#include <bits/stdc++.h>
using namespace std;
template <class Num>
inline void read(Num &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
}
template <class Num>
inline void write(Num x) {
  if (x < 0) putchar('-'), x = -x;
  static char s[20];
  int sl = 0;
  while (x) s[sl++] = x % 10 + '0', x /= 10;
  if (!sl) {
    putchar('0');
    return;
  }
  while (sl) putchar(s[--sl]);
}
template <typename T>
bool chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int MAXN = 1000000 + 100;
int N, K;
int A[MAXN], sum[MAXN], L[MAXN], R[MAXN];
vector<int> fac[MAXN];
long long ans;
void prework() {
  stack<int> S;
  A[N + 1] = oo;
  for (int i = 1; i <= N; ++i) L[i] = 1;
  for (int i = 1; i <= N + 1; ++i) {
    int num = 0;
    while (!S.empty() && A[S.top()] <= A[i]) {
      int p = S.top();
      S.pop();
      R[p] = num;
      L[i] += L[p];
      num = L[p] + R[p];
    }
    S.push(i);
  }
}
int Query(int x, int l, int r) {
  return upper_bound(fac[x].begin(), fac[x].end(), r) -
         lower_bound(fac[x].begin(), fac[x].end(), l);
}
void init() {
  read(N), read(K);
  sum[0] = 0;
  for (int i = 1; i <= N; ++i) read(A[i]);
  for (int i = 1; i <= N; ++i) sum[i] = (sum[i - 1] + A[i]) % K;
  fac[0].push_back(0);
  for (int i = 1; i <= N; ++i) fac[sum[i]].push_back(i);
  prework();
}
void solve() {
  for (int i = 1; i <= N; ++i) L[i] = i - L[i], R[i] = i + R[i] + 1;
  for (int i = 1; i <= N; ++i)
    if (i - L[i] < R[i] - i) {
      for (int j = L[i]; j < i; ++j)
        ans += Query((sum[j] + A[i]) % K, i, R[i] - 1);
    } else {
      for (int j = i; j < R[i]; ++j)
        ans += Query((sum[j] - A[i] % K + K) % K, L[i], i - 1);
    }
  printf("%I64d\n", ans - N);
}
int main() {
  init();
  solve();
  return 0;
}
