#include <bits/stdc++.h>
long long ans;
int n, k, a[300024], s[300024], l[300024], r[300024];
std::vector<int> G[1000024];
inline int ask(int k, int l, int r) {
  int x = std::upper_bound(G[k].begin(), G[k].end(), r) - G[k].begin() - 1;
  int y = std::lower_bound(G[k].begin(), G[k].end(), l) - G[k].begin() - 1;
  return x - y;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (1), __ = (n); i <= __; ++i) {
    scanf("%d", a + i);
    s[i] = (s[i - 1] + a[i]) % k;
  }
  for (int i = (0), __ = (n); i <= __; ++i) G[s[i]].push_back(i);
  for (int i = (1), __ = (n); i <= __; ++i)
    for (l[i] = i - 1; l[i] && a[l[i]] < a[i]; l[i] = l[l[i]])
      ;
  for (int i = (n), __ = (1); i >= __; --i)
    for (r[i] = i + 1; r[i] <= n && a[r[i]] <= a[i]; r[i] = r[r[i]])
      ;
  for (int i = (1), __ = (n); i <= __; ++i)
    if (i - l[i] < r[i] - i) {
      for (int j = (l[i] + 1), __ = (i); j <= __; ++j)
        ans += ask((a[i] + s[j - 1]) % k, i, r[i] - 1);
    } else {
      for (int j = (i), __ = (r[i] - 1); j <= __; ++j)
        ans += ask(((s[j] - a[i]) % k + k) % k, l[i], i - 1);
    }
  std::cout << ans - n;
  return 0;
}
