#include <bits/stdc++.h>
using namespace std;
const int INF = 1000001000;
const long long INFL = 2000000000000001000;
int solve();
int main() {
  srand(2317);
  cout.precision(10);
  cout.setf(ios::fixed);
  int tn = 1;
  for (int i = 0; i < tn; ++i) solve();
}
const int maxn = 400001;
const int maxmod = 1000002;
int a[maxn];
int k;
int cnt[maxmod];
int pmax[maxn];
int psum[maxn];
long long get(int l, int r, int c, bool eq) {
  long long res = 0;
  pmax[c] = 0;
  psum[c] = 0;
  for (int i = int(c); i < int(r); ++i) {
    pmax[i + 1] = max(pmax[i], a[i]);
    psum[i + 1] = (psum[i] + a[i]) % k;
  }
  int ptr = c + 1;
  int csum = 0;
  int cmax = 0;
  for (int i = c - 1; i >= l; --i) {
    csum = (csum + a[i]) % k;
    cmax = max(cmax, a[i]);
    while (ptr <= r && (pmax[ptr] < cmax || (pmax[ptr] == cmax && eq))) {
      cnt[psum[ptr]]++;
      ++ptr;
    }
    int need = (cmax - csum) % k;
    if (need < 0) need += k;
    res += cnt[need];
  }
  for (int i = int(c); i < int(r + 1); ++i) cnt[psum[i]] = 0;
  return res;
}
long long calc(int l, int r) {
  if (l + 1 >= r) {
    return 0;
  }
  int c = (l + r) / 2;
  long long res = calc(l, c) + calc(c, r);
  res += get(l, r, c, true);
  reverse(a + l, a + r);
  res += get(l, r, l + r - c, false);
  reverse(a + l, a + r);
  return res;
}
int solve() {
  int n;
  cin >> n >> k;
  for (int i = 0; i < int(n); ++i) cin >> a[i];
  cout << calc(0, n) << '\n';
  return 0;
}
