#include <bits/stdc++.h>
using namespace std;
int a[300000];
int lcnt[1000000] = {0}, rcnt[1000000] = {0};
long long ans = 0;
int n, k;
void print(int *cnt) {
  fprintf(stderr, "%s", cnt == lcnt ? "lcnt: " : "rcnt: ");
  for (int i = 0; i < k; i++)
    fprintf(stderr, "%d%c", cnt[i], i == k - 1 ? '\n' : ' ');
}
void solve(int L, int R) {
  if (L >= R - 1) return;
  int M = (L + R) >> 1;
  solve(L, M);
  solve(M + 1, R);
  int liter, riter, rsum = 0, lsum = 0, rmax = a[M] % k, lmax = a[M] % k;
  for (riter = M, ans--; riter < R && a[riter] <= a[M]; riter++) {
    rsum += a[riter];
    rsum %= k;
    if (rsum == rmax) ans++;
    rcnt[rsum]++;
  }
  lcnt[0] = 1;
  for (liter = M - 1; liter >= L && a[liter] <= a[M]; liter--) {
    lsum += a[liter];
    lsum %= k;
    ans += (lsum > lmax) ? rcnt[lmax - lsum + k] : rcnt[lmax - lsum];
    lcnt[lsum]++;
  }
  while (liter >= L || riter < R) {
    lmax = (liter < L) ? 0x3FFFFFFF : a[liter];
    rmax = (riter >= R) ? 0x3FFFFFFF : a[riter];
    if (lmax < rmax) {
      lmax %= k;
      for (int _max = a[liter]; liter >= L && a[liter] <= _max; liter--) {
        lsum += a[liter];
        lsum %= k;
        ans += (lsum > lmax) ? rcnt[lmax - lsum + k] : rcnt[lmax - lsum];
        lcnt[lsum]++;
      }
    } else {
      rmax %= k;
      for (int _max = a[riter]; riter < R && a[riter] <= _max; riter++) {
        rsum += a[riter];
        rsum %= k;
        ans += (rsum > rmax) ? lcnt[rmax - rsum + k] : lcnt[rmax - rsum];
        rcnt[rsum]++;
      }
    }
  }
  for (riter = M, rsum = 0; riter < R; riter++) {
    rsum += a[riter];
    rsum %= k;
    rcnt[rsum] = 0;
  }
  for (liter = M, lsum = -a[liter]; liter >= L; liter--) {
    lsum += a[liter];
    lsum %= k;
    lcnt[lsum] = 0;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  solve(0, n);
  cout << ans << endl;
  return 0;
}
