func_code_string: #include <bits/stdc++.h>   using namespace std;   long long base = 31, M = 1000000007, base1 = 29, M1 = 1000000009;   long long fpow(long long x, long long y) {     if (y == 0) return 1;     if (y == 1) return x;     long long p = fpow(x, y / 2) % M;     p *= p;     p %= M;     if (y & 1) p *= x;     return p % M;   }   long long po1[5005], pr[5005], po[5005], pr1[5005], suf[5005], suf1[5005];   int ans[5005][5005], dp[5005][5005];   pair<long long, long long> gethash(int i, int j) {     long long has = pr[j];     if (i != 0) has -= (pr[i - 1] * po[j - i + 1]) % M;     has += M;     has %= M;     long long has1 = pr1[j];     if (i != 0) has1 -= (pr1[i - 1] * po1[j - i + 1]) % M1;     has1 += M1;     has1 %= M1;     return {has, has1};   }   pair<long long, long long> gethash1(int i, int j) {     long long has = suf[j];     if (i != 0) has -= (suf[i - 1] * po[j - i + 1]) % M;     has += M;     has %= M;     long long has1 = suf1[j];     if (i != 0) has1 -= (suf1[i - 1] * po1[j - i + 1]) % M1;     has1 += M1;     has1 %= M1;     return {has, has1};   }   int main() {     po[0] = 1;     po1[0] = 1;     for (int i = 1; i <= 5001; i++) {       po[i] = po[i - 1] * base;       po1[i] = po1[i - 1] * base1;       po[i] %= M;       po1[i] %= M1;     }     string s, t;     char c[100005];     scanf( %s , &c);     s = c;     int n = s.size();     t = s;     reverse(t.begin(), t.end());     int q;     scanf( %d , &q);     pr[0] = s[0] -  a  + 1;     pr1[0] = s[0] -  a  + 1;     suf[0] = t[0] -  a  + 1;     suf1[0] = t[0] -  a  + 1;     for (int i = 1; i < s.size(); i++) {       long long x = s[i] -  a  + 1;       long long y = t[i] -  a  + 1;       pr[i] = (pr[i - 1] * base + x) % M;       pr1[i] = (pr1[i - 1] * base1 + x) % M1;       suf[i] = (suf[i - 1] * base + y) % M;       suf1[i] = (suf1[i - 1] * base1 + y) % M1;     }     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         pair<long long, long long> o = gethash(i, j);         pair<long long, long long> os = gethash1(n - 1 - j, n - 1 - i);         if (o.first == os.first && o.second == os.second) ans[i][j]++;         if (j != i) ans[i][j] += ans[i][j - 1];       }     }     for (int i = n - 1; i >= 0; i--) {       for (int j = i; j >= 0; j--) {         dp[j][i] = dp[j + 1][i] + ans[j][i];       }     }     int l, r;     while (q--) {       scanf( %d%d , &l, &r);       l--;       r--;       printf( %d n , dp[l][r]);     }     return 0;   }   