#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int MAXN = 3e5 + 10, MAXM = 1e6 + 1;
int n, k, pmx[MAXN], a[MAXN], cnt[MAXM];
vector<int> qs[MAXN];
long long ps[MAXN];
long long ans;
void solve(int s, int e) {
  if (e - s == 1) return;
  int mid = (s + e) / 2;
  solve(s, mid);
  solve(mid, e);
  for (int i = s; i <= e; i++) qs[i].clear();
  int las = -1e9;
  long long lass = 0;
  for (int i = mid - 1; i >= s; i--) {
    ps[i] = (lass + a[i]);
    lass = ps[i];
    pmx[i] = max(las, a[i]);
    las = pmx[i];
  }
  las = -1e9;
  lass = 0;
  for (int i = mid; i < e; i++) {
    ps[i] = (lass + a[i]);
    lass = ps[i];
    pmx[i] = max(las, a[i]);
    las = pmx[i];
  }
  for (int i = s; i < mid; i++) {
    int id = upper_bound(pmx + mid, pmx + e, pmx[i]) - pmx;
    id--;
    if (id >= mid) qs[id].push_back((k - ((ps[i] - pmx[i]) % k)) % k);
  }
  for (int i = mid; i < e; i++) {
    int l = s - 1, r = mid;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (pmx[mid] >= pmx[i])
        l = mid;
      else
        r = mid;
    }
    l++;
    if (l < mid) {
      qs[l].push_back((k - ((ps[i] - pmx[i]) % k)) % k);
    }
  }
  for (int i = mid; i < e; i++) {
    cnt[ps[i] % k]++;
    for (auto j : qs[i]) ans += cnt[j];
  }
  for (int i = mid; i < e; i++) cnt[ps[i] % k] = 0;
  for (int i = mid - 1; i >= s; i--) {
    cnt[ps[i] % k]++;
    for (auto j : qs[i]) ans += cnt[j];
  }
  for (int i = s; i < mid; i++) cnt[ps[i] % k] = 0;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  solve(0, n);
  printf("%lld\n", ans);
}
