func_code_string: #include <bits/stdc++.h>   using namespace std;   const int Maxn = 3e6 + 10, Maxk = 1e6 + 10;   int a[Maxn], l[Maxn], r[Maxn], s[Maxn], n, k;   vector<int> v[Maxk];   long long ans;   int ask(int k, int l, int r) {     int x = upper_bound(v[k].begin(), v[k].end(), r) - v[k].begin() - 1,         y = lower_bound(v[k].begin(), v[k].end(), l) - v[k].begin() - 1;     return x - y;   }   int main() {     ios::sync_with_stdio(0);     int i, j;     cin >> n >> k;     for (i = 1; i <= n; i++) cin >> a[i], s[i] = (s[i - 1] + a[i]) % k;     for (i = 0; i <= n; i++) v[s[i]].push_back(i);     for (i = 1; i <= n; i++)       for (l[i] = i - 1; l[i] >= 1 && a[l[i]] < a[i]; l[i] = l[l[i]])         ;     for (i = n; i >= 1; i--)       for (r[i] = i + 1; r[i] <= n && a[r[i]] <= a[i]; r[i] = r[r[i]])         ;     for (i = 1; i <= n; i++)       if (i - l[i] < r[i] - i) {         for (j = l[i] + 1; j <= i; j++)           ans += ask((a[i] + s[j - 1]) % k, i, r[i] - 1);       } else {         for (j = i; j <= r[i] - 1; j++)           ans += ask(((s[j] - a[i]) % k + k) % k, l[i], i - 1);       }     cout << ans - n << endl;     return 0;   }   