#include <bits/stdc++.h>
using namespace std;
const int INF = std::numeric_limits<int>::max() / 3;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int n, k;
int a[1000100], s[1000100];
int pr[1000100], ne[1000100];
vector<int> b[1000100];
pair<int, int> e[1000100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  s[0] = 0;
  for (int i = 1; i <= n; ++i) {
    s[i] = (s[i - 1] + a[i]) % k;
  }
  for (int i = 0; i <= k; ++i) {
    b[s[i]].clear();
  }
  for (int i = 0; i <= n; ++i) {
    b[s[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    e[i - 1] = pair<int, int>(a[i], i);
  }
  sort(e, e + n);
  for (int i = 0; i <= n + 1; ++i) {
    pr[i] = i - 1;
    ne[i] = i + 1;
  }
  long long ans = 0;
  int m, A, from, to, i, z;
  for (int id = 0; id < n; ++id) {
    m = e[id].second;
    A = a[m] % k;
    from = pr[m] + 1;
    to = ne[m] - 1;
    if (m - from < to - m) {
      for (i = from; i <= m; ++i) {
        z = s[i - 1] + A;
        z = (z >= k) ? z - k : z;
        ans += lower_bound(b[z].begin(), b[z].end(), to + 1) -
               lower_bound(b[z].begin(), b[z].end(), m);
      }
    } else {
      for (i = m; i <= to; ++i) {
        z = s[i] - A;
        z = (z < 0) ? z + k : z;
        ans += lower_bound(b[z].begin(), b[z].end(), m) -
               lower_bound(b[z].begin(), b[z].end(), from - 1);
      }
    }
    pr[ne[m]] = pr[m];
    ne[pr[m]] = ne[m];
  }
  cout << ans - n << endl;
  return 0;
}
