#include <bits/stdc++.h>
using namespace std;
const int ONE = 1000005;
const int MOD = 1e9 + 7;
int n, k;
long long val[ONE];
int pre[ONE], suc[ONE];
long long sum[ONE], sum_B[ONE];
long long Ans;
vector<int> A[ONE], B[ONE];
int get() {
  int res;
  char c;
  while ((c = getchar()) < 48 || c > 57)
    ;
  res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57) res = res * 10 + c - 48;
  return res;
}
void Deal_first() {
  int stk[ONE], top = 0;
  for (int i = 1; i <= n; i++) {
    while (top && val[i] > val[stk[top]]) suc[stk[top--]] = i - 1;
    pre[i] = stk[top] + 1;
    stk[++top] = i;
  }
  while (top) suc[stk[top--]] = n;
  for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + val[i]) % k;
  for (int i = n; i >= 1; i--) sum_B[i] = (sum_B[i + 1] + val[i]) % k;
  for (int i = 1; i <= n; i++) {
    A[sum[i]].push_back(i);
    B[sum_B[i]].push_back(i);
  }
}
int Get(int l, int r) {
  int res = sum[r] - sum[l - 1];
  if (res < 0) res += k;
  return res;
}
int Find(int R, int val) {
  if (A[val].size() == 0) return 0;
  int l = 0, r = A[val].size() - 1;
  while (l < r - 1) {
    int mid = l + r >> 1;
    if (A[val][mid] > R)
      r = mid;
    else
      l = mid;
  }
  if (A[val][l] > R) return l;
  if (A[val][r] > R) return r;
  return A[val].size();
}
int Query_left(int L, int R, int val) {
  if (L > R) return 0;
  int now = sum[L - 1];
  int need = (now + val) % k;
  return Find(R, need) - Find(L - 1, need);
}
void Deal_left(int l, int mid, int r) {
  int T = val[mid] % k;
  for (int i = l; i <= mid - 1; i++) {
    int now = Get(i, mid - 1);
    int need = (T - now + k) % k;
    Ans += Query_left(mid, r, need);
  }
  Ans += Query_left(mid, r, T) - 1;
}
int Get_B(int l, int r) {
  int res = sum_B[l] - sum_B[r + 1];
  if (res < 0) res += k;
  return res;
}
int Find_B(int R, int val) {
  if (B[val].size() == 0) return 0;
  int l = 0, r = B[val].size() - 1;
  while (l < r - 1) {
    int mid = l + r >> 1;
    if (B[val][mid] > R)
      r = mid;
    else
      l = mid;
  }
  if (B[val][l] > R) return l;
  if (B[val][r] > R) return r;
  return B[val].size();
}
int Query_right(int L, int R, int val) {
  if (L > R) return 0;
  int now = sum_B[R + 1];
  int need = (now + val) % k;
  return Find_B(R, need) - Find_B(L - 1, need);
}
void Deal_right(int l, int mid, int r) {
  int T = val[mid] % k;
  for (int i = mid + 1; i <= r; i++) {
    int now = Get_B(mid + 1, i);
    int need = (T - now + k) % k;
    Ans += Query_right(l, mid, need);
  }
  Ans += Query_right(l, mid, T) - 1;
}
int main() {
  n = get();
  k = get();
  for (int i = 1; i <= n; i++) val[i] = get();
  Deal_first();
  for (int i = 1; i <= n; i++) {
    if (i - pre[i] + 1 <= suc[i] - i + 1)
      Deal_left(pre[i], i, suc[i]);
    else
      Deal_right(pre[i], i, suc[i]);
  }
  printf("%I64d\n", Ans);
}
