func_code_string: #include <bits/stdc++.h>   using namespace std;   int d, m, n, x[25], a[30005];   vector<long long> ok;   long long L, R;   map<long long, vector<long long> > ans;   map<long long, vector<long long> > zip;   vector<long long> calc(long long lim) {     if (zip.find(lim) != zip.end()) return zip[lim];     vector<long long> ret(m, 0);     if (lim == 0) {       ret[0] = 1;       return ret;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> R = calc(nxt_lim);       for (int i = 0; i < m; i++) {         int a = (i + x[beg]);         if (a >= m) a -= m;         ret[a] += R[i];       }     }     return zip[lim] = ret;   }   void rec(long long lim, vector<long long> mask, bool F) {     if (mask.size() == 1) {       if (ans.find(lim) == ans.end()) {         ans[lim] = vector<long long>(m, 0);       }       for (int i = 0; i < m; i++) {         if (((mask[0] >> i) & 1LL)) {           if (F)             ans[lim][i]++;           else             ans[lim][i]--;         }       }       return;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> vec;       int zan = mask.size();       int bb = (d - beg);       int xx = 1 + (zan - bb + d - 1) / d;       vec.resize(xx, 0LL);       long long B = (1LL << m) - 1;       int cur = beg;       int id = 0;       for (int i = 0; i < mask.size(); i++) {         int add = x[cur];         long long nw = 0;         nw = (mask[i] >> add) | (mask[i] << (m - add));         B &= nw;         if (cur == d - 1 || i == mask.size() - 1) {           vec[id++] = B;           B = (1LL << m) - 1;         }         cur++;         if (cur == d) cur = 0;       }       assert(id == xx);       rec(nxt_lim, vec, F);     }   }   int main() {     cin >> d >> m;     for (int i = 0; i < d; i++) {       cin >> x[i];     }     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       ok.push_back((2LL << a[i]) - 1LL);     }     cin >> L >> R;     L--;     R--;     rec(R - n + 1, ok, true);     if (L - 1 >= 0) rec(L - 1, ok, false);     long long ret = 0;     for (map<long long, vector<long long> >::iterator it = ans.begin();          it != ans.end(); it++) {       vector<long long> tbl = calc(it->first);       for (int i = 0; i < m; i++) {         ret += tbl[i] * it->second[i];       }     }     cout << ret << endl;   }   