func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   int v[N], md[N];   vector<int> freq[N];   int lm[N], rm[N];   int cs[N];   int val(int x, int l, int r) {     if (l > r || l < 0) return 0;     return upper_bound(freq[x].begin(), freq[x].end(), r) -            lower_bound(freq[x].begin(), freq[x].end(), l);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     freq[0].push_back(0);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i]);       md[i] = v[i] % k;       cs[i] += v[i] % k;       cs[i] += cs[i - 1];       cs[i] %= k;       freq[cs[i]].push_back(i);     }     stack<pair<int, int> > s;     for (int i = n; i > 0; i--) {       while (s.size() && s.top().first < v[i]) {         s.pop();       }       if (s.size()) {         rm[i] = s.top().second - 1;       } else         rm[i] = n;       s.push(make_pair(v[i], i));     }     while (!s.empty()) {       s.pop();     }     for (int i = 1; i <= n; i++) {       while (s.size() && s.top().first <= v[i]) {         s.pop();       }       if (s.size()) {         lm[i] = s.top().second + 1;       } else         lm[i] = 1;       s.push(make_pair(v[i], i));     }     long long ans = 0;     int l, r, al, ar;     int x, d;     for (int i = 1; i <= n; i++) {       if (lm[i] == rm[i]) continue;       if (abs(lm[i] - i) + 1 < abs(i - rm[i]) + 1) {         l = lm[i] - 1, r = i - 2;         al = i + 1, ar = rm[i];         d = md[i];       } else {         d = -md[i];         l = i + 1, r = rm[i];         al = lm[i] - 1, ar = i - 2;       }       for (int j = l; j <= r; j++) {         x = cs[j] + d + k;         x %= k;         ans += val(x, al, ar);       }       ans += val(cs[i - 1], lm[i] - 1, i - 2);       ans += val(cs[i], i + 1, rm[i]);     }     cout << ans << endl;     return 0;   }   