#include <bits/stdc++.h>
using namespace std;
const int N = 1000500;
const int INF = 1000000000, mod = 1000000007;
const long long LLINF = 1000000000000000000ll;
int nextInt() {
  int x = 0, p = 1;
  char c;
  do {
    c = getchar();
  } while (c <= 32);
  if (c == '-') {
    p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c - '0');
    c = getchar();
  }
  return x * p;
}
vector<int> g[N];
int query(int l, int r, int c) {
  return upper_bound(g[c].begin(), g[c].end(), r) -
         lower_bound(g[c].begin(), g[c].end(), l);
}
pair<int, int> f[N][20];
int lg[N];
int x[N];
int pref[N];
int n, k;
int getmax(int l, int r) {
  int k = lg[r - l + 1];
  return max(f[l][k], f[r - (1 << k) + 1][k]).second;
}
long long result;
void go(int l, int r) {
  if (l > r) return;
  int m = getmax(l, r);
  go(l, m - 1);
  go(m + 1, r);
  if (m - l < r - m) {
    for (int a = l; a <= m; ++a) {
      int c = (x[m] + pref[a - 1]) % k;
      result += query(m, r, c);
    }
  } else {
    for (int b = m; b <= r; ++b) {
      int c = ((pref[b] - x[m]) % k + k) % k;
      result += query(l - 1, m - 1, c);
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    pref[i] = (pref[i - 1] + x[i]) % k;
  }
  for (int i = 0; i <= n; ++i) {
    g[pref[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    f[i][0] = make_pair(x[i], i);
  }
  lg[1] = 0;
  for (int i = 2; i <= n; ++i) {
    lg[i] = lg[i / 2] + 1;
  }
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      int k = i + (1 << j) / 2;
      f[i][j] = max(f[i][j - 1], f[k][j - 1]);
    }
  }
  go(1, n);
  cout << result - n << endl;
  return 0;
}
