#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 77, L = 19;
int n, k, a[N], Mx[N][L], LG[N], Ps[N], T[N << 2];
long long A;
vector<pair<int, int> > V[N];
inline int GetMax(int le, int ri) {
  int t = LG[ri - le + 1];
  int x = Mx[le][t];
  if (a[x] < a[Mx[ri - (1 << t) + 1][t]]) x = Mx[ri - (1 << t) + 1][t];
  return x;
}
void Solve(int le = 1, int ri = n) {
  if (ri < le) return;
  int Mx = GetMax(le, ri);
  int szle = Mx - le;
  int szri = ri - Mx;
  Solve(le, Mx - 1);
  Solve(Mx + 1, ri);
  int now;
  if (szri > szle) {
    for (int i = le - 1; i < Mx; ++i) {
      now = (Ps[i] + a[Mx]) % k;
      V[ri].push_back(make_pair(now, 1));
      V[Mx - 1].push_back(make_pair(now, -1));
    }
  } else {
    for (int i = Mx; i <= ri; ++i) {
      now = (Ps[i] - a[Mx] % k + k) % k;
      V[Mx - 1].push_back(make_pair(now, 1));
      if (le - 2 >= 0) V[le - 2].push_back(make_pair(now, -1));
    }
  }
}
int main() {
  for (int i = 2; i < N; ++i) LG[i] = LG[i >> 1] + 1;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i), Mx[i][0] = i, Ps[i] = (Ps[i - 1] + a[i]) % k;
  A = -n;
  for (int j = 1; j < L; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      Mx[i][j] = Mx[i][j - 1];
      if (a[Mx[i + (1 << (j - 1))][j - 1]] > a[Mx[i][j]])
        Mx[i][j] = Mx[i + (1 << (j - 1))][j - 1];
    }
  Solve();
  for (int i = 0; i <= n; ++i) {
    ++T[Ps[i]];
    for (auto x : V[i]) A += x.second * T[x.first];
  }
  printf("%lld\n", A);
  return 0;
}
