#include <bits/stdc++.h>
using namespace std;
long long ans;
int c[1000002], n, k, a[300002];
inline void in(int &x) {
  char c;
  while (!isdigit(c = getchar()))
    ;
  x = (c ^ 48);
  while (isdigit(c = getchar())) x = 10 * x + (c ^ 48);
}
inline void init() {
  in(n);
  in(k);
  for (int i = 1; i <= n; ++i) in(a[i]);
  memset(c, 0, sizeof(c));
  ans = 0;
}
inline void inc(int &x, int y) {
  x += y;
  if (x >= k) x -= k;
}
inline void clear_it(int l, int mid, int r) {
  int S = 0;
  for (int i = mid + 1; i <= r; ++i) {
    inc(S, a[i] % k);
    c[S]--;
  }
}
inline void del_with(int l, int mid, int r, bool side) {
  int M_i = a[mid], Si = 0, Sj = 0, i = mid, j = mid + 1;
  while (i >= l) {
    for (; j <= r && M_i - a[j] >= side; ++j) {
      inc(Sj, a[j] % k);
      c[Sj]++;
    }
    for (; i >= l && a[i] <= M_i; --i) {
      inc(Si, a[i] % k);
      int t = M_i % k - Si;
      if (t < 0) t += k;
      ans += c[t];
    }
    M_i = a[i];
  }
  clear_it(l, mid, j - 1);
}
inline void reserve(int l, int mid, int r) {
  for (int i = l; i <= mid; ++i) swap(a[i], a[r - i + l]);
}
inline void solve(int l, int r) {
  int mid = (r + l) >> 1;
  if (l == r) return;
  solve(l, mid);
  solve(mid + 1, r);
  del_with(l, mid, r, 0);
  reserve(l, mid, r);
  del_with(l, l + r - mid - 1, r, 1);
  reserve(l, mid, r);
}
int main() {
  init();
  solve(1, n);
  cout << ans;
  return 0;
}
