#include <bits/stdc++.h>   using namespace std;   const int N = 300100;   const int K = 1001000;   vector<int> v[K];   int a[N], s[N];   int l[N], r[N];   int q[N], id[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     s[0] = a[0] % k;     v[0].push_back(-1);     v[s[0]].push_back(0);     for (int i = 1; i < n; i++) {       s[i] = (s[i - 1] + a[i]) % k;       v[s[i]].push_back(i);     }     int c = 0;     for (int i = 0; i < n; i++) {       while (c && a[q[c - 1]] < a[i]) c--;       l[i] = 0;       if (c) {         l[i] = q[c - 1] + 1;       }       q[c++] = i;     }     c = 0;     for (int i = n - 1; i >= 0; i--) {       while (c && a[q[c - 1]] <= a[i]) c--;       r[i] = n - 1;       if (c) {         r[i] = q[c - 1] - 1;       }       q[c++] = i;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i - l[i] >= r[i] - i) {         for (int j = i; j <= r[i]; j++) {           int x = (s[j] - a[i]) % k;           if (x < 0) {             x += k;           }           int ll = l[i] - 1, rr = i - 1;           if (j == i) rr = i - 2;           ans += upper_bound(v[x].begin(), v[x].end(), rr) -                  lower_bound(v[x].begin(), v[x].end(), ll);         }       } else {         for (int j = l[i]; j <= i; j++) {           int x = (a[i] + s[j - 1]) % k;           if (x < 0) {             x += k;           }           int ll = i, rr = r[i];           if (j == i) ll = i + 1;           ans += upper_bound(v[x].begin(), v[x].end(), rr) -                  lower_bound(v[x].begin(), v[x].end(), ll);         }       }     }     printf( %lld n , ans);   }   