#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chk_mi(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <class T>
bool chk_mx(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <class T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <class T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <const int maxn, const int maxm>
struct Link_list {
  int head[maxn], To[maxm], nxt[maxm], tot;
  void init() { memset(head, tot = 0, sizeof head); }
  void add(int x, int y) {
    nxt[++tot] = head[x];
    head[x] = tot;
    To[tot] = y;
  }
};
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
void Rd(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = (res << 3) + (res << 1) + (c & 15);
  while (c = getchar(), 47 < c);
}
int A[300005], L[300005], R[300005], Sum[300005];
vector<int> E[1000005];
int find(int x, int l, int r) {
  if (l > r) return 0;
  if (E[x].empty()) return 0;
  int lt = lower_bound(E[x].begin(), E[x].end(), l) - E[x].begin() - 1;
  int rt = upper_bound(E[x].begin(), E[x].end(), r) - E[x].begin() - 1;
  return rt - lt;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int now = 0;
  E[0].push_back(0);
  for (int i = (1), i_END = (n); i <= i_END; i++) {
    scanf("%d", &A[i]);
    now = (now + A[i]) % k;
    Sum[i] = now;
    E[now].push_back(i);
  }
  for (int i = (1), i_END = (n); i <= i_END; i++) L[i] = i, R[i] = i;
  for (int i = (2), i_END = (n); i <= i_END; i++) {
    int now = i;
    while (A[now - 1] <= A[i] && now > 1) now = L[now - 1];
    L[i] = now;
  }
  for (int i = (n - 1), i_END = (1); i >= i_END; i--) {
    int now = i;
    while (A[now + 1] < A[i] && now < n) {
      now = R[now + 1];
    }
    R[i] = now;
  }
  long long ans = 0;
  for (int i = (1), i_END = (n); i <= i_END; i++) {
    if (i - L[i] < R[i] - i) {
      for (int j = (L[i]), j_END = (i); j <= j_END; j++) {
        int a = Sum[j - 1];
        int b = (a + A[i]) % k;
        ans += find(b, i, R[i]);
      }
    } else {
      for (int j = (i), j_END = (R[i]); j <= j_END; j++) {
        int a = Sum[j];
        int b = ((a - A[i]) % k + k) % k;
        ans += find(b, L[i] - 1, i - 1);
      }
    }
  }
  printf("%lld\n", ans - n);
  return 0;
}
