#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 20;
const long long maxm = 1e6 + 20;
long long mx[maxn], t[maxm], a[maxn], k, sum[maxn];
long long res;
inline void ok(long long &a) {
  a %= k;
  if (a >= k)
    a -= k;
  else if (a < 0)
    a += k;
}
void solve(long long s, long long e) {
  if (e - s < 2) return;
  long long m = (s + e) / 2;
  solve(s, m);
  solve(m, e);
  vector<pair<long long, long long> > v1, v2;
  long long mx = 0, sum = 0;
  for (long long i = m - 1; i >= s; i--) {
    ok(sum += a[i] % k);
    mx = max(mx, a[i]);
    v1.push_back({sum, mx});
  }
  mx = 0, sum = 0;
  for (long long i = m; i < e; i++) {
    ok(sum += a[i] % k);
    mx = max(mx, a[i]);
    v2.push_back({sum, mx});
  }
  long long pt = 0;
  for (auto tmp : v1) {
    while (pt < (long long)v2.size() && v2[pt].second <= tmp.second) {
      t[v2[pt].first]++;
      pt++;
    }
    long long x = (-tmp.first + tmp.second) % k;
    ok(x);
    res += t[x];
  }
  for (auto tmp : v2) t[tmp.first] = 0;
  pt = 0;
  swap(v1, v2);
  for (auto tmp : v1) {
    while (pt < (long long)v2.size() && v2[pt].second < tmp.second) {
      t[v2[pt].first]++;
      pt++;
    }
    long long x = (-tmp.first + tmp.second) % k;
    ok(x);
    res += t[x];
  }
  for (auto tmp : v2) t[tmp.first] = 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  solve(0, n);
  cout << res << endl;
}
