func_code_string: #include <bits/stdc++.h>   using namespace std;   long long fac[100001];   long long inv_fac[100001];   int val[100001];   vector<int> cnt(53, 0);   int l[100001];   int r[100001];   long long keep[53][53];   long long dp[54][100001];   long long dp1[54][100001];   long long mod = 1e9 + 7;   inline void add(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += mod;   }   long long pw(long long x, int p) {     if (p == 0) return 1;     if (p == 1) return x % mod;     long long temp = pw(x, p / 2);     temp = (temp * temp) % mod;     if (p % 2 == 0) return temp;     temp = (x * temp) % mod;     return temp;   }   void calc() {     fac[0] = fac[1] = 1;     inv_fac[0] = inv_fac[1] = 1;     for (int i = 2; i <= 100000; i++) {       fac[i] = (i * fac[i - 1]) % mod;       inv_fac[i] = pw(fac[i], mod - 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int q;     cin >> q;     for (int i = 0; i < q; i++) cin >> l[i] >> r[i];     int n = s.size();     int mx = n / 2;     calc();     for (int i = 0; i < n; i++) {       if (s[i] >=  a  && s[i] <=  z ) {         val[i + 1] = int(s[i] -  a ) + 1;         cnt[int(s[i] -  a ) + 1]++;       } else {         val[i + 1] = 26 + int(s[i] -  A ) + 1;         cnt[26 + int(s[i] -  A ) + 1]++;       }     }     for (int i = 1; i <= 52; i++) {       int temp = cnt[i];       if (temp > n / 2 || cnt[i] == 0) {         continue;       }       temp = n / 2 - temp;       for (int w = 0; w <= mx; w++) dp[0][w] = dp1[53][w] = 0;       dp[0][0] = dp1[53][0] = 1;       for (int k = 1; k <= 52; k++) {         if (k == i || cnt[k] == 0) {           for (int w = 0; w <= mx; w++) dp[k][w] = dp[k - 1][w];           continue;         }         for (int w = 0; w <= mx; w++) {           dp[k][w] = dp[k - 1][w];           if (w >= cnt[k]) add(dp[k][w], dp[k - 1][w - cnt[k]]);         }       }       for (int k = 52; k >= 1; k--) {         if (k == i || cnt[k] == 0) {           for (int w = 0; w <= mx; w++) dp1[k][w] = dp1[k + 1][w];           continue;         }         for (int w = 0; w <= mx; w++) {           dp1[k][w] = dp1[k + 1][w];           if (w >= cnt[k]) add(dp1[k][w], dp1[k + 1][w - cnt[k]]);         }       }       for (int k = i; k <= 52; k++) {         if (k == i) {           keep[k][i] = dp[52][temp];           continue;         }         long long t1 = 0;         int rem = temp - cnt[k];         if (rem < 0) {           keep[k][i] = keep[i][k] = 0;           continue;         }         for (int w = 0; w <= rem; w++) {           long long t2 = (dp[k - 1][w] * dp1[k + 1][rem - w]) % mod;           add(t1, t2);         }         keep[i][k] = keep[k][i] = t1;       }     }     long long ans = (fac[n / 2] * fac[n / 2]) % mod;     for (int i = 1; i <= 52; i++) ans = (ans * inv_fac[cnt[i]]) % mod;     ans = (2 * ans) % mod;     for (int i = 0; i < q; i++) {       int x = val[l[i]];       int y = val[r[i]];       long long temp = ans;       temp = (temp * keep[x][y]) % mod;       cout << temp << endl;     }   }   