#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
int n, k, ans;
int a[300111], cnt[1000111];
long long calc(int l, int r) {
  if (l >= r) return 0;
  int m = l + r >> 1;
  long long ans = calc(l, m - 1) + calc(m + 1, r);
  int lit = m, rit = m + 1, ls = 0, rs = 0, lmx = 0, rmx = 0;
  ls = (ls + a[lit]) % k;
  lmx = max(lmx, a[lit]);
  for (int i = m + 1; i <= r; i++) {
    rmx = max(rmx, a[i]);
    while (lit >= l && lmx < rmx) {
      ans += cnt[(-ls + lmx % k + k) % k];
      lit--;
      if (lit < l) break;
      ls = (ls + a[lit]) % k;
      lmx = max(lmx, a[lit]);
    }
    rs = (rs + a[i]) % k;
    cnt[rs]++;
  }
  while (lit >= l) {
    ans += cnt[(-ls + lmx % k + k) % k];
    lit--;
    if (lit < l) break;
    ls = (ls + a[lit]) % k;
    lmx = max(lmx, a[lit]);
  }
  rs = 0;
  for (int i = m + 1; i <= r; i++) {
    rs = (rs + a[i]) % k;
    cnt[rs]--;
  }
  ls = rs = lmx = rmx = 0;
  rs = (rs + a[rit]) % k;
  rmx = max(rmx, a[rit]);
  for (int i = m; i >= l; i--) {
    lmx = max(lmx, a[i]);
    while (rit <= r && rmx <= lmx) {
      ans += cnt[(-rs + rmx % k + k) % k];
      rit++;
      if (rit > r) break;
      rs = (rs + a[rit]) % k;
      rmx = max(rmx, a[rit]);
    }
    ls = (ls + a[i]) % k;
    cnt[ls]++;
    if (i < m && (ls - lmx % k + k) % k == 0) ans++;
  }
  while (rit <= r) {
    ans += cnt[(-rs + rmx % k + k) % k];
    rit++;
    if (rit > r) break;
    rs = (rs + a[rit]) % k;
    rmx = max(rmx, a[rit]);
  }
  ls = 0;
  for (int i = m; i >= l; i--) {
    ls = (ls + a[i]) % k;
    cnt[ls]--;
  }
  return ans;
}
int main() {
  n = getnum(), k = getnum();
  for (int i = 1; i <= n; i++) a[i] = getnum();
  putnum(calc(1, n)), putsp(), putendl();
  return 0;
}
