-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreating Strings II.cpp
More file actions
executable file
·62 lines (53 loc) · 914 Bytes
/
Copy pathCreating Strings II.cpp
File metadata and controls
executable file
·62 lines (53 loc) · 914 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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9L + 7;
LL xGCD(LL a, LL b, LL &x, LL &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
LL x1, y1, gcd = xGCD(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return gcd;
}
LL modfact(LL n) {
LL result = 1;
while (n > 1) {
result = result * n % MOD;
n -= 1;
}
return result;
}
LL modmult(LL a, LL b) {
return a * b % MOD;
}
LL inverse(LL a) {
LL x, y;
xGCD(a, MOD, x, y);
return (x + MOD) % MOD;
}
LL bc(LL n, LL k) {
return modmult(modmult(modfact(n), inverse(modfact(k))), inverse(modfact(n - k)));
}
LL t[300];
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
for (auto c : s) {
t[int(c)]++;
}
LL res = 1;
int n = s.size();
for (int i = 0; i < 300; i++) {
if (t[i] != 0) {
res = (res * bc(n, t[i])) % MOD;
n -= t[i];
}
}
cout << res << "\n";
return 0;
}