#include <bits/stdc++.h>
using namespace std;
void chkmx(int &x, int y) {
  if (x < y) x = y;
}
int Mod;
int val[300005];
long long res;
int sum[1000005];
int Que[300005];
void solve(int L, int R) {
  if (L == R) return;
  int mid = L + R >> 1;
  int lmx = 0, rmx = 0;
  int lsum = 0, rsum = 0;
  int l = mid, r = mid + 1;
  int top = 0;
  while (r <= R) {
    chkmx(rmx, val[r]);
    rsum = (rsum + val[r++]) % Mod;
    while (l >= L && max(lmx, val[l]) <= rmx) {
      chkmx(lmx, val[l]);
      lsum = (lsum + val[l--]) % Mod;
      sum[lsum]++;
      Que[++top] = lsum;
    }
    res += sum[((rmx - rsum) % Mod + Mod) % Mod];
  }
  for (int i = (1), _t = (top); i <= _t; ++i) sum[Que[i]]--;
  lmx = 0, rmx = 0;
  lsum = 0, rsum = 0;
  l = mid, r = mid + 1;
  top = 0;
  while (l >= L) {
    chkmx(lmx, val[l]);
    lsum = (lsum + val[l--]) % Mod;
    while (r <= R && max(rmx, val[r]) < lmx) {
      chkmx(rmx, val[r]);
      rsum = (rsum + val[r++]) % Mod;
      sum[rsum]++;
      Que[++top] = rsum;
    }
    res += sum[((lmx - lsum) % Mod + Mod) % Mod];
  }
  for (int i = (1), _t = (top); i <= _t; ++i) sum[Que[i]]--;
  solve(L, mid);
  solve(mid + 1, R);
}
int main() {
  int n;
  scanf("%d%d", &n, &Mod);
  for (int i = (1), _t = (n); i <= _t; ++i) scanf("%d", &val[i]);
  solve(1, n);
  printf("%lld\n", res);
  return 0;
}
