fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30.  
  31. vector<long long> fact;
  32. vector<long long> ifact;
  33.  
  34. void compute(){
  35. fact.resize(N+1);
  36. ifact.resize(N+1);
  37. ifact[0] = fact[0] = fact[1] = 1;
  38. for(int i=2; i<=N; i++){
  39. fact[i] = (i * fact[i-1])%M;
  40. }
  41. ifact[N] = power(fact[N], M-2, M);
  42. for(int i=N-1; i>=1; i--){
  43. ifact[i] = ((i+1) * ifact[i+1])%M;
  44. }
  45. }
  46.  
  47. long long fac(int i){
  48. return fact[i];
  49. }
  50. long long ifac(int i){
  51. return ifact[i];
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. int consistency(string s) {
  59. compute();
  60.  
  61. long long ans = 1;
  62. stringstream str(s);
  63. string temp;
  64.  
  65. while(str >> temp){
  66.  
  67. int sz = temp.size();
  68. vector<int> f(26);
  69.  
  70. for(auto& ch : temp){
  71. f[ch-'a']++;
  72. }
  73.  
  74. long long val = fac(sz);
  75. for(auto& ct : f){
  76. if(ct == 0) continue;
  77. val = (val * ifac(ct))%M;
  78. }
  79. ans = (ans * val)%M;
  80. }
  81. return ans%M;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. int practice(string s){
  99.  
  100.  
  101. return 0;
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108. void solve() {
  109.  
  110. string s;
  111. getline(cin, s);
  112.  
  113.  
  114. cout << consistency(s) << endl;
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. int32_t main() {
  124. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  125.  
  126. int t = 1;
  127. // cin >> t;
  128. while (t--) {
  129. solve();
  130. }
  131.  
  132. return 0;
  133. }
Success #stdin #stdout 0.01s 7856KB
stdin
too hot
stdout
18