#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, K;
int arr[N];
vector<int> mp[N];
int tmin[N][20];
int prefix[N];
int logn = 19;
void preprocess() {
  for (int j = 0; j < logn; j++) {
    if (j == 0) {
      for (int i = 1; i <= n; i++) tmin[i][j] = i;
      continue;
    }
    for (int i = 1; i <= n; i++) {
      int tv = i + (1 << (j - 1));
      if (tv > n) break;
      tmin[i][j] =
          (arr[tmin[i][j - 1]] >= arr[tmin[tv][j - 1]] ? tmin[i][j - 1]
                                                       : tmin[tv][j - 1]);
    }
  }
  mp[prefix[0]].push_back(0);
  for (int i = 1; i <= n; i++) {
    prefix[i] = (prefix[i - 1] + arr[i]) % K;
    assert(0 <= prefix[i] && prefix[i] < K);
    mp[prefix[i]].push_back(i);
  }
}
int query(int l, int r) {
  int p = 0;
  int len = r - l + 1;
  p = log2(len);
  int b = l + len - 1;
  return arr[tmin[l][p]] >= arr[tmin[b - (1 << p) + 1][p]]
             ? tmin[l][p]
             : tmin[b - (1 << p) + 1][p];
}
long long ans = 0;
long long findans(int val, int l, int r) {
  int x = lower_bound(mp[val].begin(), mp[val].end(), l) - mp[val].begin();
  int y = upper_bound(mp[val].begin(), mp[val].end(), r) - mp[val].begin();
  return y - x;
}
void solve(int l, int r) {
  if (l > r) return;
  int mind = query(l, r);
  assert(l <= mind && mind <= r);
  int val = arr[mind] % K;
  int l1 = mind - l + 1;
  int l2 = r - mind + 1;
  if (l1 < l2) {
    for (int i = l - 1; i <= mind - 1; i++) {
      int need = (prefix[i] + val) % K;
      ans += findans(need, mind, r);
    }
  } else {
    for (int i = mind; i <= r; i++) {
      int need = (prefix[i] - val + K) % K;
      ans += findans(need, l - 1, mind - 1);
    }
  }
  solve(l, mind - 1);
  solve(mind + 1, r);
}
signed main() {
  ignore = scanf("%d %d", &n, &K);
  logn = log2(n) + 1;
  for (int i = 1; i <= n; i++) ignore = scanf("%d", &arr[i]);
  preprocess();
  solve(1, n);
  printf("%I64d\n", ans - n);
}
