func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 100003;   int l[maxn], r[maxn], L, R, K, n, cnt[maxn][30], sum[30], A[30], B[30];   char c[maxn], s[maxn];   int List[30][maxn], a[maxn], len[maxn], tot = 0;   inline int get() {     int f = 0, v = 0;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) break;     if (ch ==  - )       f = 1;     else       v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     if (f == 1)       return -v;     else       return v;   }   int check(int st, int ed) {     bool f = 0, g = 0;     for (int i = 0; i < 26; i++) {       int tp = cnt[ed][i] - cnt[st - 1][i];       if (tp > B[i]) g = 1;       if (tp < A[i]) f = 1;     }     if (f && g) return 2;     if (f) return -1;     if (g) return 1;     return 0;   }   void add(int st, int ed, int v) {     for (int i = st; i <= ed; i++) {       if (L <= a[i] && a[i] <= R) tot--;       a[i] += v;       if (L <= a[i] && a[i] <= R) tot++;     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     K = get();     L = get(), R = get();     for (int i = 1; i <= K; i++) scanf(  %c , &c[i]), l[i] = get(), r[i] = get();     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];       cnt[i][s[i] -  a ]++;     }     if (L == K && R == K) {       long long ans = 0;       for (int i = 0; i < 26; i++) A[i] = 0, B[i] = n + 1;       for (int i = 1; i <= K; i++) {         A[c[i] -  a ] = max(A[c[i] -  a ], l[i]);         B[c[i] -  a ] = min(B[c[i] -  a ], r[i]);         if (A[c[i] -  a ] > B[c[i] -  a ]) return puts( 0 ), 0;       }       for (int i = 1; i <= n; i++) {         bool flag = 1;         L = i, R = n;         int Left, Right;         while (L <= R) {           int mid = (L + R) / 2, t = check(i, mid);           if (t == 2) {             flag = 0;             break;           }           if (t == 1)             R = mid - 1;           else             L = mid + 1;         }         Right = R;         L = i, R = n;         while (L <= R) {           int mid = (L + R) / 2, t = check(i, mid);           if (t == 2) {             flag = 0;             break;           }           if (t == -1)             L = mid + 1;           else             R = mid - 1;         }         Left = L;         if (flag && Right >= Left) ans += Right - Left + 1;       }       cout << ans << endl;       return 0;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (L == 0) tot++;       int tp = s[i] -  a ;       List[tp][++len[tp]] = i;       for (int j = 1; j <= K; j++) {         if (l[j] == 0) add(i, i, 1);         if (c[j] != s[i]) continue;         if (len[tp] >= l[j] && l[j] != 0)           add(List[tp][len[tp] - l[j]] + 1, List[tp][len[tp] - l[j] + 1], 1);         if (len[tp] > r[j])           add(List[tp][len[tp] - r[j] - 1] + 1, List[tp][len[tp] - r[j]], -1);       }       ans += tot;     }     cout << ans << endl;     return 0;   }   