#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
const int N = 1e6 + 10;
int n, k, L[N], R[N];
int a[N], s[N];
vector<int> g[N];
int qry(int first, int l, int r) {
  if (first < 0) first += k;
  return upper_bound(g[first].begin(), g[first].end(), r) -
         lower_bound(g[first].begin(), g[first].end(), l);
}
int main() {
  scanf("%d%d", &n, &k);
  g[0].push_back(0);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    s[i] = (s[i - 1] + a[i]) % k;
    g[s[i]].push_back(i);
    L[i] = i - 1;
    while (L[i] && a[L[i]] < a[i]) L[i] = L[L[i]];
  }
  for (int i = n; i >= 1; --i) {
    R[i] = i + 1;
    while (R[i] <= n && a[R[i]] <= a[i]) R[i] = R[R[i]];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i - L[i] < R[i] - i) {
      for (int j = L[i] + 1; j <= i; ++j) {
        ans += qry((s[j - 1] + a[i]) % k, i, R[i] - 1);
      }
    } else {
      for (int j = i; j <= R[i] - 1; ++j) {
        ans += qry((s[j] - a[i]) % k, L[i], i - 1);
      }
    }
  }
  printf("%lld\n", ans - n);
}
