#include <bits/stdc++.h>
using namespace std;
int const K = 2e6;
int a[K], S[K], V[K], X[K], C;
int& at(int i) {
  if (V[i] != C) V[i] = C, X[i] = 0;
  return X[i];
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    S[i + 1] = (a[i] + S[i]) % k;
  }
  long long R = 0;
  for (int H = 1; H < n; H *= 2) {
    for (int l = 0; l + H < n; l += H + H) {
      int m = l + H, r = min(m + H, n), Z = 0, T = m;
      ++C;
      for (int F = m - 1; F >= l; --F) {
        Z = max(Z, a[F]);
        while (T < r && a[T] <= Z) {
          int x = S[++T] - S[m] + k;
          ++at(x >= k ? x - k : x);
        }
        R += at((S[F] + Z + k - S[m]) % k);
      }
      Z = 0, ++C;
      int F = m;
      for (int T = m + 1; T <= r; ++T) {
        Z = max(Z, a[T - 1]);
        while (F > l && a[F - 1] < Z) {
          int x = S[m] + k - S[--F];
          ++at(x >= k ? x - k : x);
        }
        R += at((S[m] + Z + k - S[T]) % k);
      }
    }
  }
  cout << R;
}
