#include <bits/stdc++.h>
using namespace std;
long long Ans;
int N, K, A[300005], S[300005], L[300005], R[300005];
vector<int> G[1000005];
int Ask(int k, int l, int r) {
  int x = upper_bound(G[k].begin(), G[k].end(), r) - G[k].begin() - 1,
      y = 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; i <= N; i++) scanf("%d", &A[i]), S[i] = (S[i - 1] + A[i]) % K;
  for (int i = 0; i <= N; i++) G[S[i]].push_back(i);
  for (int i = 1; i <= N; i++)
    for (L[i] = i - 1; L[i] && A[L[i]] < A[i]; L[i] = L[L[i]])
      ;
  for (int i = N; i >= 1; i--)
    for (R[i] = i + 1; R[i] <= N && A[R[i]] <= A[i]; R[i] = R[R[i]])
      ;
  for (int i = 1; i <= N; i++)
    if (i - L[i] < R[i] - i) {
      for (int j = L[i] + 1; j <= i; j++)
        Ans += Ask((A[i] + S[j - 1]) % K, i, R[i] - 1);
    } else {
      for (int j = i; j <= R[i] - 1; j++)
        Ans += Ask((S[j] - A[i] % K + K) % K, L[i], i - 1);
    }
  printf("%I64d\n", Ans - N);
}
