#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
vector<int> F[maxn];
int pow2[maxn], st[maxn][20], stplace[maxn][20];
int N, K, sum[maxn], a[maxn];
int gettimes(int L, int R, int K) {
  vector<int>::iterator c1 = lower_bound(F[K].begin(), F[K].end(), L);
  vector<int>::iterator c2 = lower_bound(F[K].begin(), F[K].end(), R + 1);
  return c2 - c1;
}
int getmax(int l, int r) {
  int lc = pow2[r - l + 1];
  if (st[l][lc] > st[r - (1 << lc) + 1][lc])
    return stplace[l][lc];
  else
    return stplace[r - (1 << lc) + 1][lc];
}
long long getans(int l, int r) {
  if (l >= r) return 0;
  int mid = getmax(l, r), sc;
  long long ans = getans(l, mid - 1) + getans(mid + 1, r);
  if (mid - l <= r - mid) {
    for (int i = l; i <= mid; i++) {
      sc = (sum[mid - 1] - sum[i - 1] + K) % K;
      sc = (K - sc + sum[mid]) % K;
      ans += gettimes(mid, r, sc);
    }
  } else {
    for (int i = mid; i <= r; i++) {
      sc = (sum[i] - sum[mid] + K) % K;
      sc = (sum[mid - 1] - (K - sc) + K) % K;
      ans += gettimes(l - 1, mid - 1, sc);
    }
  }
  return ans - 1;
}
int main() {
  pow2[1] = 0;
  for (int i = 2; i < maxn; i++) pow2[i] = pow2[i / 2] + 1;
  scanf("%d %d", &N, &K);
  sum[0] = 0;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &a[i]);
    sum[i] = (sum[i - 1] + a[i]) % K;
  }
  for (int i = 0; i <= N; i++) F[sum[i]].push_back(i);
  for (int i = N; i >= 1; i--) {
    st[i][0] = a[i];
    stplace[i][0] = i;
    for (int j = 1; j <= 19; j++)
      if (i + (1 << j) - 1 <= N)
        if (st[i][j - 1] > st[i + (1 << (j - 1))][j - 1])
          st[i][j] = st[i][j - 1], stplace[i][j] = stplace[i][j - 1];
        else
          st[i][j] = st[i + (1 << (j - 1))][j - 1],
          stplace[i][j] = stplace[i + (1 << (j - 1))][j - 1];
  }
  printf("%I64d\n", getans(1, N));
  return 0;
}
