#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
  if (f) x = -x;
}
int n, md, a[300005], sum[300005];
vector<int> ve[1000005];
int st[300005], tp;
long long ans;
int cunt(int l, int r, int k) {
  if (l > r) return 0;
  return upper_bound(ve[k].begin(), ve[k].end(), r) -
         lower_bound(ve[k].begin(), ve[k].end(), l);
}
int l[300005], r[300005];
void solve(int x) {
  a[x] %= md;
  if (x - l[x] < r[x] - x) {
    for (register int i = l[x]; i <= x; ++i)
      ans += cunt(max(i + 1, x), r[x], (sum[i - 1] + a[x]) % md);
  } else {
    for (register int i = x; i <= r[x]; ++i)
      ans += cunt(l[x] - 1, min(i - 1, x) - 1, (sum[i] - a[x] + md) % md);
  }
}
signed main() {
  in(n), in(md);
  ve[0].push_back(0);
  for (register int i = 1; i <= n; ++i) {
    in(a[i]);
    sum[i] = (sum[i - 1] + a[i]) % md;
    ve[sum[i]].push_back(i);
  }
  a[n + 1] = 1000000010;
  for (register int i = 1; i <= n + 1; ++i) {
    while (tp && a[st[tp]] < a[i]) {
      r[st[tp]] = i - 1;
      --tp;
    }
    st[++tp] = i;
  }
  a[0] = 1000000010;
  for (register int i = n; i >= 0; --i) {
    while (tp && a[st[tp]] <= a[i]) {
      l[st[tp]] = i + 1;
      --tp;
    }
    st[++tp] = i;
  }
  for (register int i = 1; i <= n; ++i) {
    solve(i);
  }
  printf("%lld", ans);
  return 0;
}
