func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n, k, ps[N], mx[N], cnt[N], a[N];   long long ans;   int getNeed(int p, int m) {     int x = (((p - m) % k) + k) % k;     return cnt[((k - x) + k) % k];   }   void solve(int l, int r) {     if (r - l <= 1) return;     int mid = (l + r) / 2;     ps[mid - 1] = a[mid - 1] % k, mx[mid - 1] = a[mid - 1];     for (int i = mid - 2; i >= l; i--)       ps[i] = (ps[i + 1] + a[i]) % k, mx[i] = max(mx[i + 1], a[i]);     ps[mid] = a[mid] % k, mx[mid] = a[mid];     for (int i = mid + 1; i < r; i++)       ps[i] = (ps[i - 1] + a[i]) % k, mx[i] = max(mx[i - 1], a[i]);     for (int i = mid - 1; i >= l; i--) cnt[ps[i]]++;     int rn = l;     for (int i = r - 1; i >= mid; i--) {       if (mx[mid - 1] >= mx[i]) break;       while (mx[rn] >= mx[i]) cnt[ps[rn]]--, rn++;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid - 1; i >= l; i--) cnt[ps[i]] = 0;     rn = r - 1;     for (int i = mid; i < r; i++) cnt[ps[i]]++;     for (int i = l; i < mid; i++) {       if (mx[i] < mx[mid]) break;       while (mx[rn] > mx[i]) cnt[ps[rn]]--, rn--;       ans += getNeed(ps[i], mx[i]);     }     for (int i = mid; i < r; i++) cnt[ps[i]] = 0;     solve(l, mid), solve(mid, r);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     solve(0, n);     cout << ans;     return 0;   }   