#include <bits/stdc++.h>
using namespace std;
int const MAXK = 1.1e6;
int const N = 300300;
int n, k, a[N], asum[N];
struct {
  int vers[MAXK];
  int value[MAXK];
  int curver;
  int at(int i) const { return vers[i] == curver ? value[i] : 0; }
  int &at(int i) {
    if (vers[i] != curver) vers[i] = curver, value[i] = 0;
    return value[i];
  }
} cnt;
int norm(int a) { return a >= k ? a - k : a; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    asum[i + 1] = (a[i] + asum[i]) % k;
  }
  long long ans = 0;
  for (int half = 1; half < n; half *= 2) {
    for (int l = 0; l + half < n; l += half + half) {
      int m = l + half;
      int r = min(m + half, n);
      int maxv = 0;
      int to = m;
      ++cnt.curver;
      for (int from = m - 1; from >= l; --from) {
        maxv = max(maxv, a[from]);
        while (to < r && a[to] <= maxv) {
          ++to;
          ++cnt.at(norm(asum[to] - asum[m] + k));
        }
        ans += cnt.at((asum[from] + maxv + k - asum[m]) % k);
      }
      maxv = 0;
      int from = m;
      ++cnt.curver;
      for (int to = m + 1; to <= r; ++to) {
        maxv = max(maxv, a[to - 1]);
        while (from > l && a[from - 1] < maxv) {
          --from;
          ++cnt.at(norm(asum[m] + k - asum[from]));
        }
        ans += cnt.at((asum[m] + maxv + k - asum[to]) % k);
      }
    }
  }
  cout << ans << '\n';
}
