wa on #3 #6 #10
wa on #3 #6 #10
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,t[30],cnt;
ll ans,tot,p=1e9+7,jc[2005];
char ch;
string s;
ll qp(ll d,ll c)
{
ll res=1;
while(c)
{
if(c&1)
c--,res=res*d%p;
else
c/=2,d=d*d%p;
}
return res;
}
ll A(ll a,ll b)
{
return (jc[a]*qp(jc[b],p-2)%p);
}
int main()
{
cin>>n;
cin>>s;
s=' '+s;
n=s.size()-1;
for(int i=1;i<=n;i++)
t[s[i]-'a'+1]++;
jc[0]=1;
for(int i=1;i<=n;i++)
jc[i]=jc[i-1]*i%p;
for(int i=1;i<=26;i++)
if(t[i]%2)
cnt++;
if(cnt>1)
{
cout<<jc[n];
}
else
{
ans=jc[n];
if(cnt)
{
for(int i=1;i<=26;i++)
if(t[i]&1)
t[i]--;
n--;
}
tot=jc[n/2];
for(int i=1;i<=26;i++)
{
if(!t[i])continue;
tot=tot*A(t[i],t[i]/2)%p;
}
ans=(ans-tot+p)%p;
cout<<ans;
}
return 0;
}