#include <bits/stdc++.h>
using namespace std;
int rd();
const int N = 300007;
int n, k, a[N], cnt[1000007];
int pref[N], suff[N];
long long ans;
void rec(int l, int r) {
  if (l == r) return;
  int m = (l + r) / 2;
  rec(l, m);
  rec(m + 1, r);
  suff[m] = a[m];
  for (int i = m - 1; i >= l; --i) {
    suff[i] = max(a[i], suff[i + 1]);
  }
  pref[m + 1] = a[m + 1];
  for (int i = m + 2; i <= r; ++i) {
    pref[i] = max(a[i], pref[i - 1]);
  }
  int rptr = m + 1;
  long long sum = 0;
  int rsum = 0;
  for (int i = m; i >= l; --i) {
    sum += a[i];
    int maxi = suff[i];
    int cur = (int)((sum - maxi) % k);
    while (rptr <= r && pref[rptr] <= maxi) {
      rsum = (rsum + a[rptr++]) % k;
      ++cnt[rsum];
    }
    int need = k - cur;
    if (need == k) need = 0;
    ans += cnt[need];
  }
  for (int i = m + 1, rsum = 0; i < rptr; ++i) {
    rsum = (rsum + a[i]) % k;
    --cnt[rsum];
  }
  int lptr = m;
  sum = 0;
  int lsum = 0;
  for (int i = m + 1; i <= r; ++i) {
    sum += a[i];
    int maxi = pref[i];
    int cur = (int)((sum - maxi) % k);
    while (lptr >= l && suff[lptr] < maxi) {
      lsum = (lsum + a[lptr--]) % k;
      ++cnt[lsum];
    }
    int need = k - cur;
    if (need == k) need = 0;
    ans += cnt[need];
  }
  for (int i = m, lsum = 0; i > lptr; --i) {
    lsum = (lsum + a[i]) % k;
    --cnt[lsum];
  }
}
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &a[i]);
  }
  rec(0, n - 1);
  printf("%lld\n", ans);
}
int rd() { return (((long long)rand() << 16) ^ rand()) % 1000000000; }
void testGen() {
  FILE *f = fopen("input.txt", "w");
  fclose(f);
}
int main() {
  cerr << fixed;
  cerr.precision(9);
  solve();
  return 0;
}
