#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  register T sum = 0;
  char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T &a) {
  a = read<T>();
  return a;
}
struct Node {
  int syl;
  int val;
  Node(int a = 0, int b = 0) {
    syl = a;
    val = b;
  }
};
vector<Node> v[300010];
int n, k, top, more, sum[300010], pre[300010], sub[300010], sta[300010],
    num[300010], cnt[1000010];
long long ans;
int main() {
  n = read<int>(), k = read<int>();
  for (int i = 1; i <= n; i++) {
    num[i] = read<int>();
    sum[i] = (sum[i - 1] + num[i]) % k;
  }
  num[0] = num[n + 1] = 0x7fffffff;
  sta[top = 1] = 0;
  for (int i = 1; i <= n; i++) {
    while (num[sta[top]] <= num[i]) top -= 1;
    pre[i] = sta[top] + 1;
    sta[++top] = i;
  }
  sta[top = 1] = n + 1;
  for (int i = n; i >= 1; i--) {
    while (num[sta[top]] < num[i]) top -= 1;
    sub[i] = sta[top] - 1;
    sta[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (pre[i] == sub[i]) continue;
    more += 1;
    if (i - pre[i] + 1 <= sub[i] - i + 1) {
      for (int j = pre[i] - 1; j < i; j++) {
        v[i - 1].push_back(Node(-1, (1ll * sum[j] + num[i] % k) % k));
        v[sub[i]].push_back(Node(1, (1ll * sum[j] + num[i] % k) % k));
      }
    } else {
      for (int j = i; j <= sub[i]; j++) {
        if (pre[i] >= 2)
          v[pre[i] - 2].push_back(
              Node(-1, (1ll * sum[j] - num[i] % k + k) % k));
        v[i - 1].push_back(Node(1, (1ll * sum[j] - num[i] % k + k) % k));
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    cnt[sum[i]] += 1;
    for (vector<Node>::iterator j = v[i].begin(); j != v[i].end(); j++)
      ans += j->syl * cnt[j->val];
  }
  printf("%lld\n", ans - more);
  return 0;
}
