#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000005];
int n, k, a[300005], sum[300005], st[300005], top;
int L[300005], R[300005];
long long ans;
inline int read(void) {
  int x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int solve(int x, int l, int r) {
  int p1 = lower_bound(g[x].begin(), g[x].end(), l) - g[x].begin();
  int p2 = upper_bound(g[x].begin(), g[x].end(), r) - g[x].begin() - 1;
  return p2 - p1 + 1;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + a[i]) % k;
  g[0].push_back(0);
  for (int i = 1; i <= n; i++) g[sum[i]].push_back(i);
  for (int i = 1; i <= n; i++) {
    while (top > 0 && a[st[top]] <= a[i]) {
      R[st[top]] = i - 1;
      top--;
    }
    st[++top] = i;
  }
  while (top > 0) R[st[top--]] = n;
  for (int i = n; i >= 1; i--) {
    while (top > 0 && a[st[top]] < a[i]) {
      L[st[top]] = i + 1;
      top--;
    }
    st[++top] = i;
  }
  while (top > 0) L[st[top--]] = 1;
  for (int i = 1; i <= n; i++) {
    if (i == 7) {
      int b = 5;
    }
    if (R[i] - L[i] + 1 == 1) continue;
    if (R[i] - i < i - L[i]) {
      for (int j = i; j <= R[i]; j++)
        ans +=
            solve(((sum[j] - a[i]) % k + k) % k, L[i] - 1, min(i - 1, j - 2));
    } else {
      for (int j = L[i] - 1; j <= i - 1; j++)
        ans += solve((sum[j] + a[i]) % k, max(i, j + 2), R[i]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
