-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreating_Strings_II.cpp
More file actions
65 lines (55 loc) · 950 Bytes
/
Copy pathCreating_Strings_II.cpp
File metadata and controls
65 lines (55 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll M = 1e9 + 7;
const ll s = 1e6 ;
ll pow(ll a, ll n){
ll ans =1;
while(n!=0)
{
if(n %2 ==0)
{
n= n/2;
a =(a*a)%M;
}
else{
ans = (ans * a)%M;
n--;
}
}
return ans;
}
ll inv(ll a){
return pow(a,M-2);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<ll>fact(s+1);
fact[0]=1;
for(ll i=1; i<=s; i++)
{
fact[i] = (i*fact[i-1])%M;
}
vector<ll>ivfact(s+1);
ivfact[s]=inv(fact[s]);
for(ll i=s-1; i>=0; i--)
{
ivfact[i]=((i+1) * ivfact[i+1])%M;
}
string s;
cin >>s;
map<char, ll>mp;
ll l= s.length();
for(ll i=0; i<s.length(); i++){
mp[s[i]]++;
}
ll ans=1;
for(auto v : mp)
{
ans=(ans*ivfact[v.second])%M;
}
cout<<(ans*fact[l])%M;
}