#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const int N = 3e5 + 7;
long long n, k;
long long a[N];
long long res;
vector<long long> v;
long long cnt[1000 * 1000 + 7];
void get(long long md, long long w) {
  long long mx = 0, pl = md, ps = 0, sm = 0;
  for (long long i = md; i < v.size(); i++) {
    mx = max(mx, v[i]);
    sm += v[i];
    while (pl > 0 && v[pl - 1] + w <= mx) {
      pl--;
      ps = (ps + v[pl]);
      ps %= k;
      cnt[ps]++;
    }
    res += cnt[((((mx - sm) % k) + k) % k)];
  }
  for (long long i = pl; i < md; i++) {
    cnt[ps]--;
    ps = ((((ps - v[i]) % k) + k) % k);
  }
}
void solve(long long s, long long e) {
  if (e - s <= 1) return;
  if (e - s > 2) {
    solve(s, ((s + e) / 2));
    solve(((s + e) / 2), e);
  }
  v.clear();
  for (long long i = s; i < e; i++) v.push_back(a[i]);
  get(v.size() / 2, 0);
  reverse(v.begin(), v.end());
  get(v.size() / 2 + (v.size() % 2), 1);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  solve(1, n + 1);
  cout << res;
}
