#include <bits/stdc++.h>
using namespace std;
const int N = 300500;
const int K = 1000500;
int n, k;
int sz = 0;
int a[N];
int cnt[K];
int pref[N];
int suff[N];
int toDel[N];
long long res = 0LL;
void dfs(int l, int r) {
  if (l == r) {
    return;
  }
  int mid = (l + r) >> 1;
  dfs(l, mid);
  dfs(mid + 1, r);
  int ptr = mid;
  suff[mid + 1] = 0;
  pref[mid] = 0;
  for (int i = mid; i >= l; --i) {
    suff[i] = max(a[i], suff[i + 1]);
  }
  for (int i = mid + 1; i <= r; i++) {
    pref[i] = max(a[i], pref[i - 1]);
  }
  int lSum, rSum;
  lSum = rSum = 0;
  sz = 0;
  for (int i = mid; i >= l; --i) {
    (lSum += a[i]) %= k;
    while (ptr + 1 <= r && pref[ptr + 1] < suff[i]) {
      ++ptr;
      (rSum += a[ptr]) %= k;
      toDel[++sz] = rSum;
      cnt[rSum]++;
    }
    int needSum = suff[i] - lSum;
    while (needSum < 0) needSum += k;
    needSum = needSum % k;
    res += (1LL * cnt[needSum]);
  }
  for (int i = 1; i <= sz; i++) cnt[toDel[i]] = 0;
  sz = 0;
  ptr = mid + 1;
  lSum = rSum = 0;
  for (int i = mid + 1; i <= r; i++) {
    (rSum += a[i]) %= k;
    while (ptr - 1 >= l && suff[ptr - 1] <= pref[i]) {
      --ptr;
      (lSum += a[ptr]) %= k;
      toDel[++sz] = lSum;
      cnt[lSum]++;
    }
    int needSum = pref[i] - rSum;
    while (needSum < 0) needSum += k;
    needSum = needSum % k;
    res += (1LL * cnt[needSum]);
  }
  for (int i = 1; i <= sz; i++) cnt[toDel[i]] = 0;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dfs(1, n);
  cout << res << "\n";
  return 0;
}
