func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   vector<int> G[1000010];   int a[MAXN], s[MAXN], L[MAXN], R[MAXN];   int n, k;   long long ans;   int query(int k, int l, int r) {     return upper_bound(G[k].begin(), G[k].end(), r) -            lower_bound(G[k].begin(), G[k].end(), l);   }   int main() {     scanf( %d%d , &n, &k);     G[0].push_back(0);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = (s[i - 1] + a[i]) % k;       G[s[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       L[i] = i - 1;       while (L[i] && a[L[i]] < a[i]) L[i] = L[L[i]];     }     for (int i = n; i >= 1; i--) {       R[i] = i + 1;       while (R[i] <= n && a[R[i]] <= a[i]) R[i] = R[R[i]];     }     for (int i = 1; i <= n; i++) a[i] %= k;     for (int i = 1; i <= n; i++) {       if (i - L[i] < R[i] - i) {         for (int j = L[i] + 1; j <= i; j++)           ans += query((s[j - 1] + a[i]) % k, i, R[i] - 1);       } else {         for (int j = i; j < R[i]; j++)           ans += query((s[j] - a[i] + k) % k, L[i], i - 1);       }     }     printf( %lld n , ans - n);     return 0;   }   