#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 5;
const long long maxk = 1e6 + 5;
long long n, k, ans;
long long a[maxn], s[maxn];
long long f[maxk];
void divide_and_conquer(long long l, long long r) {
  if (l == r) return;
  long long mid = (l + r) / 2;
  divide_and_conquer(l, mid);
  divide_and_conquer(mid + 1, r);
  long long i = mid;
  long long j = mid + 1;
  long long maxx = a[i];
  while (i >= l) {
    maxx = max(maxx, a[i]);
    while (j <= r && a[j] < maxx) {
      f[(s[j] - s[mid]) % k]++;
      j++;
    }
    ans += f[(k - (((s[mid] - s[i - 1]) - maxx) % k)) % k];
    i--;
  }
  i = mid;
  j = mid + 1;
  maxx = a[i];
  while (i >= l) {
    maxx = max(maxx, a[i]);
    while (j <= r && a[j] < maxx) {
      f[(s[j] - s[mid]) % k]--;
      j++;
    }
    i--;
  }
  i = mid;
  j = mid + 1;
  maxx = a[j];
  while (j <= r) {
    maxx = max(maxx, a[j]);
    while (i >= l && a[i] <= maxx) {
      f[(s[mid] - s[i - 1]) % k]++;
      i--;
    }
    ans += f[(k - (((s[j] - s[mid]) - maxx) % k)) % k];
    j++;
  }
  i = mid;
  j = mid + 1;
  maxx = a[j];
  while (j <= r) {
    maxx = max(maxx, a[j]);
    while (i >= l && a[i] <= maxx) {
      f[(s[mid] - s[i - 1]) % k]--;
      i--;
    }
    j++;
  }
}
signed main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    s[i] = s[i - 1] + a[i];
  }
  divide_and_conquer(1, n);
  printf("%lld", ans);
}
