#include <bits/stdc++.h>
using namespace std;
const int N = 303030, M = 1010101;
int n, k;
int a[N], pr[N], ne[N];
long long s[N];
vector<int> b[M];
pair<int, int> e[N];
inline int qry(int l, int r, int x) {
  int res = upper_bound(b[x].begin(), b[x].end(), r) -
            upper_bound(b[x].begin(), b[x].end(), l - 1);
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n >> k;
  b[0].push_back(0);
  for (int i = (1); i < (n + 1); i++)
    cin >> a[i], s[i] = s[i - 1] + a[i], b[s[i] % k].push_back(i),
                 e[i] = make_pair(a[i], i);
  sort(e + 1, e + 1 + n);
  for (int i = (1); i < (n + 1); i++) pr[i] = i - 1, ne[i] = i + 1;
  long long ans = 0;
  for (int _ = (1); _ < (n + 1); _++) {
    int i = e[_].second;
    int l = pr[i] + 1, r = ne[i] - 1;
    int l1 = l - 1, r1 = i - 1;
    int l2 = i, r2 = r;
    if (r1 - l1 < r2 - l2) {
      for (int j = (l1); j < (r1 + 1); j++) {
        ans += qry(l2, r2, (s[j] + a[i]) % k);
      }
    } else {
      for (int j = (l2); j < (r2 + 1); j++) {
        ans += qry(l1, r1, (s[j] - a[i]) % k);
      }
    }
    pr[ne[i]] = pr[i];
    ne[pr[i]] = ne[i];
  }
  cout << ans - n << "\n";
  return 0;
}
