#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005;
vector<int> v[MAX];
int a[MAX], sum[MAX], st[MAX], le[MAX], ri[MAX];
int get_cnt(int l, int r, int x) {
  if (l >= r) return 0;
  return lower_bound(v[x].begin(), v[x].end(), r) -
         lower_bound(v[x].begin(), v[x].end(), l);
}
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  v[0].push_back(0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum[i + 1] = (sum[i] + a[i]) % k;
    v[sum[i + 1]].push_back(i + 1);
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    while (t > 0 && a[st[t - 1]] < a[i]) t--;
    le[i] = -1;
    if (t) le[i] = st[t - 1];
    st[t++] = i;
  }
  t = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (t > 0 && a[st[t - 1]] <= a[i]) t--;
    ri[i] = n;
    if (t) ri[i] = st[t - 1];
    st[t++] = i;
  }
  for (int i = 0; i < n; i++) a[i] %= k;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i - le[i] < ri[i] - i) {
      for (int j = i; j > le[i]; j--)
        if (j == i)
          ans += get_cnt(i + 2, ri[i] + 1, (sum[j] + a[i]) % k);
        else
          ans += get_cnt(i + 1, ri[i] + 1, (sum[j] + a[i]) % k);
    } else {
      for (int j = i + 1; j <= ri[i]; j++)
        if (j == i + 1)
          ans += get_cnt(le[i] + 1, i, (sum[j] - a[i] + k) % k);
        else
          ans += get_cnt(le[i] + 1, i + 1, (sum[j] - a[i] + k) % k);
    }
  }
  cout << ans << endl;
  return 0;
}
