#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
const int maxk = 1000000 + 5;
int n, k;
int a[maxn];
long long ret;
int cnt[maxk];
int clk, dfn[maxk];
void update(int i) {
  if (dfn[i] < clk)
    cnt[i] = 1, dfn[i] = clk;
  else
    ++cnt[i];
}
int query(int i) { return dfn[i] < clk ? 0 : cnt[i]; }
void divide(int l, int r) {
  if (l == r) return;
  int mid = (l + r) / 2;
  divide(l, mid), divide(mid + 1, r);
  int pre = 0, suf = 0, maxv = 0, j = mid + 1;
  ++clk;
  for (int i = mid; i >= l; --i) {
    pre = (pre + a[i]) % k;
    maxv = max(maxv, a[i]);
    while (j <= r && a[j] <= maxv) {
      suf = (suf + a[j++]) % k;
      update(suf);
    }
    ret += query((maxv - pre + k) % k);
  }
  pre = suf = maxv = 0, j = mid;
  ++clk;
  for (int i = mid + 1; i <= r; ++i) {
    suf = (suf + a[i]) % k;
    maxv = max(maxv, a[i]);
    while (j >= l && a[j] < maxv) {
      pre = (pre + a[j--]) % k;
      update(pre);
    }
    ret += query((maxv - suf + k) % k);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  divide(1, n);
  printf("%lld\n", ret);
  return 0;
}
