#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 3e5 + 10;
const int K = 1e6 + 10;
long long fcl[K], fcr[K];
int a[N];
long long g[N];
int n, k;
void maximize(int &u, int v) { u = max(u, v); }
long long f(int l, int r) {
  if (r < l + 1) return 0;
  int m = (l + r) / 2 + 1;
  long long ans = 0;
  int maxnum = 0;
  int ul = m - 1, ur = m;
  fcr[g[m]]++;
  maxnum = a[m];
  fcl[g[m - 1]]++;
  while ((l - 1 < ul) && (ur < r)) {
    if (a[ul] < a[ur + 1]) {
      ul--;
      fcl[g[ul]]++;
      maximize(maxnum, a[ul + 1]);
      ans += fcr[(g[ul] + maxnum) % k];
    } else {
      ur++;
      fcr[g[ur]]++;
      maximize(maxnum, a[ur]);
      ans += fcl[((g[ur] - maxnum) % k + k) % k];
    }
  }
  while (l - 1 < ul) {
    ul--;
    fcl[g[ul]]++;
    maximize(maxnum, a[ul + 1]);
    ans += fcr[(g[ul] + maxnum) % k];
  }
  while (ur < r) {
    ur++;
    fcr[g[ur]]++;
    maximize(maxnum, a[ur]);
    ans += fcl[((g[ur] - maxnum) % k + k) % k];
  }
  for (int i = l - 1; i <= r; i++) fcl[g[i]] = fcr[g[i]] = 0;
  ans += f(l, m - 1);
  ans += f(m + 1, r);
  return ans;
}
int main() {
  scanf("%d %d", &n, &k);
  a[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    g[i] = (g[i - 1] + a[i]) % k;
  }
  cout << f(1, n) << endl;
}
