#include <bits/stdc++.h>
using namespace std;
int n, k;
int A[300005];
int B[300005];
int M[300005][28];
void rmq() {
  for (int i = 0; i <= n; i++) M[i][0] = i;
  for (int j = 1; j <= 25; j++)
    for (int i = 0; i + (1 << (j - 1)) <= n; i++)
      if (A[M[i][j - 1]] > A[M[i + (1 << (j - 1))][j - 1]])
        M[i][j] = M[i][j - 1];
      else
        M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
int id_mayor(int a, int b) {
  int lg = 31 - __builtin_clz(b - a + 1);
  if (A[M[a][lg]] > A[M[b - (1 << lg) + 1][lg]]) return M[a][lg];
  return M[b - (1 << lg) + 1][lg];
}
int Dp[1000005];
long long sol;
void query(int in, int fin, bool limp) {
  if (in == fin) {
    if (!limp) Dp[B[in]]++;
    return;
  }
  int mit = id_mayor(in + 1, fin);
  long long tmp = 0;
  if (mit - in < fin - mit) {
    if (in != mit) query(in, mit - 1, true);
    if (fin != mit) query(mit, fin, false);
    for (int i = in; i < mit; i++) {
      sol += Dp[(B[i] + A[mit]) % k];
      tmp += Dp[(B[i] + A[mit]) % k];
    }
    for (int i = in; i < mit; i++) Dp[B[i]]++;
  } else {
    if (fin != mit) query(mit, fin, true);
    if (in != mit) query(in, mit - 1, false);
    for (int i = mit; i <= fin; i++) {
      sol += Dp[(B[i] - (A[mit] % k) + k) % k];
      tmp += Dp[(B[i] - (A[mit] % k) + k) % k];
    }
    for (int i = mit; i <= fin; i++) Dp[B[i]]++;
  }
  if (limp) {
    for (int i = in; i <= fin; i++) Dp[B[i]]--;
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    B[i] = (B[i - 1] + A[i]) % k;
  }
  rmq();
  query(0, n, false);
  cout << sol - n << endl;
  return 0;
}
