#include <bits/stdc++.h>
using namespace std;
const int N = 1200000, inf = 1000000001;
int d[N], g[N], h[N], l[N], r[N], L[N], R[N];
int i, m, n, o, t;
long long s;
inline int fastscanf() {
  int t = 0;
  char c = getchar();
  while (!((c > 47) && (c < 58))) c = getchar();
  while ((c > 47) && (c < 58)) t = t * 10 + c - 48, c = getchar();
  return t;
}
inline void dfs(int l, int r, int x) {
  if ((r - x > x - l) && (R[x])) {
    for (int i = x; i >= l; i--) s = s - d[(h[i - 1] + g[x]) % m];
    dfs(x + 1, r, R[x]);
    for (int i = x; i >= l; i--) s = s + d[(h[i - 1] + g[x]) % m];
    if (L[x])
      dfs(l, x - 1, L[x]);
    else
      d[h[x - 1]]++;
  }
  if ((x - l >= r - x) && (L[x])) {
    for (int i = x; i <= r; i++) s = s - d[(h[i] - g[x] + m) % m];
    dfs(l, x - 1, L[x]);
    for (int i = x; i <= r; i++) s = s + d[(h[i] - g[x] + m) % m];
    if (R[x])
      dfs(x + 1, r, R[x]);
    else
      d[h[x]]++;
  }
  if ((!L[x]) && (!R[x]))
    d[h[x - 1]]++, d[h[x]]++;
  else
    s--;
  return;
}
int main() {
  n = fastscanf(), m = fastscanf();
  g[0] = inf, g[n + 1] = inf;
  for (i = 1; i <= n; i++) g[i] = fastscanf();
  for (l[1] = 0, i = 2; i <= n; i++)
    for (l[i] = i - 1; (l[i] != 0) && (g[i] > g[l[i]]); l[i] = l[l[i]])
      ;
  for (r[n] = n + 1, i = n - 1; i > 0; i--)
    for (r[i] = i + 1; (r[i] != n + 1) && (g[i] >= g[r[i]]); r[i] = r[r[i]])
      ;
  for (i = 1; i <= n; i++) {
    t = min(g[l[i]], g[r[i]]);
    if ((l[i] != 0) && (t == g[l[i]])) R[l[i]] = i;
    if ((r[i] != n + 1) && (t == g[r[i]])) L[r[i]] = i;
    if (t == inf) o = i;
  }
  for (i = 1; i <= n; i++) g[i] = g[i] % m, h[i] = (h[i - 1] + g[i]) % m;
  dfs(1, n, o);
  printf("%I64d", s);
  return 0;
}
