#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > o[300010];
long long ans;
int n, m;
int a[300010];
long long s[300010];
int sum[1000010];
int top;
int q[300010];
int l[300010], r[300010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  top = 0;
  for (int i = 1; i <= n; i++) {
    while (top && a[q[top]] <= a[i]) top--;
    l[i] = q[top] + 1;
    q[++top] = i;
  }
  top = 0;
  q[0] = n + 1;
  for (int i = n; i; i--) {
    while (top && a[q[top]] < a[i]) top--;
    r[i] = q[top] - 1;
    q[++top] = i;
  }
  for (int i = 1; i <= n; i++)
    if (r[i] - i < i - l[i]) {
      for (int j = i; j <= r[i]; j++)
        o[l[i] - 1].push_back(make_pair((s[j] - a[i]) % m, -1)),
            o[i].push_back(make_pair((s[j] - a[i]) % m, 1));
    } else {
      for (int j = l[i] - 1; j < i; j++)
        o[i].push_back(make_pair((s[j] + a[i]) % m, -1)),
            o[r[i] + 1].push_back(make_pair((s[j] + a[i]) % m, 1));
    }
  for (int i = 0; i <= n + 1; i++) {
    for (pair<int, int> t : o[i]) ans += 1ll * sum[t.first] * t.second;
    sum[s[i] % m]++;
  }
  ans -= n;
  printf("%lld\n", ans);
}
