#include <bits/stdc++.h>
using namespace std;
int n, mod, col;
int a[300010];
long long ans = 0;
int h[2][1000010];
void solve(int l, int r) {
  int i, j, mid;
  long long s = 0, s1 = 0, max1 = 0;
  if (l == r || l > r) return;
  mid = (l + r) / 2;
  col++;
  j = mid;
  for (i = mid; i <= r; i++) {
    if (a[i] > max1) {
      max1 = a[i];
    }
    s = (s + a[i]) % mod;
    while (j - 1 >= l && a[j - 1] <= max1) {
      j--;
      s1 = (s1 + a[j]) % mod;
      if (h[1][s1] == col)
        h[0][s1]++;
      else {
        h[1][s1] = col;
        h[0][s1] = 1;
      }
    }
    if (h[1][(mod - (s - (max1 % mod)) + mod) % mod] == col)
      ans += h[0][(mod - (s - (max1 % mod)) + mod) % mod];
    if (i > mid && (s - (max1 % mod) + mod) % mod == 0) ans++;
  }
  col++;
  j = mid - 1;
  max1 = 0;
  s = 0;
  s1 = 0;
  for (i = mid - 1; i >= l; i--) {
    if (a[i] > max1) {
      max1 = a[i];
    }
    s = (s + a[i]) % mod;
    while (j + 1 <= r && a[j + 1] < max1) {
      j++;
      s1 = (s1 + a[j]) % mod;
      if (h[1][s1] == col)
        h[0][s1]++;
      else {
        h[1][s1] = col;
        h[0][s1] = 1;
      }
    }
    if (h[1][(mod - (s - (max1 % mod)) + mod) % mod] == col)
      ans += h[0][(mod - (s - (max1 % mod)) + mod) % mod];
  }
  solve(l, mid - 1);
  solve(mid + 1, r);
}
int main() {
  int i, j;
  scanf("%d%d", &n, &mod);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve(1, n);
  cout << ans << endl;
  return 0;
}
