func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int fp(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) (res *= a) %= (1000000000 + 7);       b /= 2;       (a *= a) %= (1000000000 + 7);     }     return res;   }   int n, k, cr, l, last;   long long int pref[1501][2], pw[1501][2], h, h1;   bool c[26];   string s, temp;   char c1;   queue<int> q;   set<pair<int, int>> ans;   void solve() {     s =    ;     cin >> temp;     s += temp;     for (long long int i = 0; i < 26; i++) {       cin >> c1;       c[i] = 1 - (c1 -  0 );     }     cin >> k;     n = s.length() - 1;     long long int exp = 1, exp1 = 1;     cr = 0;     q.push(0);     pref[0][0] = pref[0][1] = last = l = cr = 0;     for (int i = 1; i <= n;          i++, (exp *= 31) %= (1000000000 + 7), (exp1 *= 37) %= (1000000000 + 7)) {       pref[i][0] = (pref[i - 1][0] + (s[i] -  a  + 1) * exp) % (1000000000 + 7);       pref[i][1] = (pref[i - 1][1] + (s[i] -  a  + 1) * exp1) % (1000000000 + 7);     }     pw[n][0] = fp(31, (1000000000 + 7) - 2 - n);     pw[n][1] = fp(37, (1000000000 + 7) - 2 - n);     for (int i = n - 1; i >= 0; i--) {       pw[i][0] = (pw[i + 1][0] * 31) % (1000000000 + 7);       pw[i][1] = (pw[i + 1][1] * 37) % (1000000000 + 7);     }     for (int i = 1; i <= n; i++) {       if (c[s[i] -  a ]) {         cr++;         q.push(i);       }       if (cr == k + 1) {         cr--;         l = q.front();         q.pop();         for (int j = i - 1; j >= last; j--) {           for (int x = j; x > l; x--) {             h = (((pref[j][0] - pref[x - 1][0] + (1000000000 + 7)) %                   (1000000000 + 7)) *                      pw[x][0] +                  (1000000000 + 7)) %                 (1000000000 + 7);             h1 = (((pref[j][1] - pref[x - 1][1] + (1000000000 + 7)) %                    (1000000000 + 7)) *                       pw[x][1] +                   (1000000000 + 7)) %                  (1000000000 + 7);             ans.insert({h, h1});           }         }         last = i;       }     }     l = q.front();     q.pop();     for (int j = n; j >= last; j--) {       for (int x = j; x > l; x--) {         h = (((pref[j][0] - pref[x - 1][0] + (1000000000 + 7)) %               (1000000000 + 7)) *                  pw[x][0] +              (1000000000 + 7)) %             (1000000000 + 7);         h1 = (((pref[j][1] - pref[x - 1][1] + (1000000000 + 7)) %                (1000000000 + 7)) *                   pw[x][1] +               (1000000000 + 7)) %              (1000000000 + 7);         ans.insert({h, h1});       }     }     cout << int(ans.size());   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int T = 1;     while (T--) {       solve();     }     return 0;   }   