#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int NN = 300000 + 17;
const int MM = 2000000 + 17;
const int INF = 2e9;
void open() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
}
int n, k;
int a[NN], s[NN];
int maxl[NN], maxr[NN], tax[MM];
long long ans;
int get_mod(int x) { return (x % k + k) % k; }
void work(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  work(l, mid);
  work(mid + 1, r);
  maxr[mid] = maxl[mid + 1] = 0;
  for (int i = mid + 1; i <= r; i++) {
    maxr[i] = max(maxr[i - 1], a[i]);
  }
  for (int i = mid; i >= l; i--) {
    maxl[i] = max(maxl[i + 1], a[i]);
  }
  int pos = mid;
  for (int i = mid + 1; i <= r; i++) {
    while (pos >= l && maxl[pos] < maxr[i]) {
      tax[s[pos - 1]]++;
      pos--;
    }
    ans += 1LL * tax[get_mod(s[i] - maxr[i])];
  }
  for (int i = l; i <= mid; i++) tax[s[i - 1]] = 0;
  pos = mid + 1;
  for (int i = mid; i >= l; i--) {
    while (pos <= r && maxr[pos] <= maxl[i]) {
      tax[s[pos]]++;
      pos++;
    }
    ans += 1LL * tax[get_mod(s[i - 1] + maxl[i])];
  }
  for (int i = mid + 1; i <= r; i++) tax[s[i]] = 0;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    s[i] = (s[i - 1] + a[i]) % k;
  }
  work(1, n);
  printf("%lld\n", ans);
  return 0;
}
