#include <bits/stdc++.h>
using namespace std;
int A[300010], sum[300010], stk[300010], L[300010], R[300010];
vector<int> B[1000010];
int Find(int l, int r, int x) {
  int L = lower_bound(B[x].begin(), B[x].end(), l) - B[x].begin();
  int R = upper_bound(B[x].begin(), B[x].end(), r) - B[x].begin() - 1;
  return R - L + 1;
}
int main() {
  int n, m, i, j, Top;
  scanf("%d%d", &n, &m);
  B[0].push_back(0);
  for (i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    sum[i] = (sum[i - 1] + A[i]) % m;
    B[sum[i]].push_back(i);
  }
  Top = 0;
  stk[0] = 0;
  for (i = 1; i <= n; i++) {
    while (Top > 0 && A[i] > A[stk[Top]]) {
      Top--;
    }
    L[i] = stk[Top] + 1;
    stk[++Top] = i;
  }
  Top = 0;
  stk[0] = n + 1;
  for (i = n; i >= 1; i--) {
    while (Top > 0 && A[i] >= A[stk[Top]]) {
      Top--;
    }
    R[i] = stk[Top] - 1;
    stk[++Top] = i;
  }
  long long Ans = 0;
  for (i = 1; i <= n; i++) {
    if (i - L[i] + 1 <= R[i] - i + 1) {
      for (j = L[i] - 1; j < i; j++) {
        Ans += Find(i, R[i], (sum[j] + A[i]) % m);
      }
    } else {
      for (j = i; j <= R[i]; j++) {
        Ans += Find(L[i] - 1, i - 1, ((sum[j] - A[i]) % m + m) % m);
      }
    }
  }
  printf("%lld\n", Ans - n);
  return 0;
}
