代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
#define x first
#define y second
#define sz(a) a.size()
#define lowbit(x) (x & -x)
#define debug(x) cout << #x << ':' << x << endl
#define VI vector<int>
#define all(a) a.begin(), a.end()
#define rep(i, c, n) for (int i = c; i <= n; ++i)
#define per(i, c, n) for (int i = c; i >= n; --i)
#define w(x) while(x --)
#define db double
#define pb(x) push_back(x)
const int INF = 0x3f3f3f3f;
const ll INFll = 9223372036854775807;
const double PI = 3.1415926;
#define getchar() (tt == ss && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
char In[1 << 20], *ss=In, *tt=In;
namespace Fastio
{
struct Reader
{
template <typename T> Reader& operator >> (T &x)
{
x = 0;
short f = 1;
char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= f;
return *this;
}
Reader& operator >> (double &x)
{
x = 0;
double t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (long double &x)
{
x = 0;
long double t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (__float128 &x)
{
x = 0;
__float128 t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (char &c)
{
c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
return *this;
}
Reader& operator >> (char *str)
{
int len = 0;
char c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
while (c != ' ' && c != '\n' && c != '\r') str[len++] = c, c = getchar();
str[len] = '\0';
return *this;
}
Reader& operator >> (string &str)
{
str.clear();
char c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
while (c != ' ' && c != '\n' && c != '\r') str.push_back(c), c = getchar();
return *this;
}
Reader() {}
} cin;
const char endl = '\n';
struct Writer
{
const int Setprecision = 6;
typedef int mxdouble;
template <typename T> Writer& operator << (T x)
{
if (x == 0) { putchar('0'); return *this; }
if (x < 0) putchar('-'), x = -x;
static short sta[40];
short top = 0;
while (x > 0) sta[++top] = x % 10, x /= 10;
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (double x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (double)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (long double x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (long double)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (__float128 x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (__float128)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (char c) { putchar(c); return *this; }
Writer& operator << (char *str)
{
int cur = 0;
while (str[cur]) putchar(str[cur++]);
return *this;
}
Writer& operator << (const char *str)
{
int cur = 0;
while (str[cur]) putchar(str[cur++]);
return *this;
}
Writer& operator << (string str)
{
int st = 0, ed = str.size();
while (st < ed) putchar(str[st++]);
return *this;
}
Writer() {}
} cout;
}
using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
#define max(a,b) a > b ? a : b
#define min(a,b) a<b?a:b
#define abs(x) x<0?-x:x
template<typename T>inline T power(T a, T b) {T res = 1;while (b) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
const int mod = 1e9 + 7;
int n;
string s;
int cnt[30];
long long fact(int x) {
long long res = 1;
rep(i, 1, x)
res = res * i % mod;
return res;
}
long long factR(int x) {
long long res = 1;
rep(i, x / 2 + 1, x)
res = res * i % mod;
return res;
}
int main() {
cin >> n >> s;
rep(i, 0, n - 1) {
cnt[s[i] - 'a'] ++;
}
long long addcnt = 0;
rep(i, 0, 25) {
if (cnt[i] & 1)
addcnt ++;
}
long long ans = fact(n);
if (addcnt > 1) {
cout << ans % mod << endl;
return 0;
}
long long sum = fact(n / 2);
rep(i, 0, 25) {
sum = sum * factR(cnt[i]) % mod;
}
cout << (ans - sum + mod) % mod;
return 0;
}