forked from Jonathan-Uy/CSES-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreating Strings II.cpp
More file actions
44 lines (37 loc) · 792 Bytes
/
Creating Strings II.cpp
File metadata and controls
44 lines (37 loc) · 792 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e6+5;
const ll MOD = 1e9+7;
int N, freq[26];
char S[maxN];
ll fact[maxN], inv[maxN];
ll inverse(ll x){
ll res = 1;
ll expo = MOD-2;
while(expo > 0){
if(expo&1)
res = (res * x) % MOD;
x = (x * x) % MOD;
expo >>= 1;
}
return res;
}
void init(){
fact[0] = inv[0] = 1;
for(int i = 1; i < maxN; i++){
fact[i] = i * fact[i-1] % MOD;
inv[i] = inverse(fact[i]);
}
}
int main(){
scanf("%s", S);
N = (int) strlen(S);
init();
for(int i = 0; i < N; i++)
freq[(int) (S[i]-'a')]++;
ll ans = fact[N];
for(int i = 0; i < 26; i++)
ans = ans * inv[freq[i]] % MOD;
printf("%lld\n", ans);
}