#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 998244353;
long long sum[N], a[N];
vector<int> num[N];
int q[N];
int pre[N], suf[N];
int solve(int l, int r, int x) {
  return upper_bound(num[x].begin(), num[x].end(), r) -
         lower_bound(num[x].begin(), num[x].end(), l);
}
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int i;
  num[0].push_back(0);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    num[sum[i] % k].push_back(i);
  }
  int hh = 0, tt = 0;
  q[0] = 0;
  for (i = 1; i <= n; i++) {
    while (hh <= tt && a[q[tt]] <= a[i]) {
      tt--;
    }
    pre[i] = q[tt] + 1;
    q[++tt] = i;
  }
  hh = 0, tt = 0;
  q[0] = n + 1;
  a[n + 1] = 1e9 + 1;
  for (i = n; i >= 1; i--) {
    while (hh <= tt && a[q[tt]] < a[i]) {
      tt--;
    }
    suf[i] = q[tt] - 1;
    q[++tt] = i;
  }
  long long ans = -n;
  for (i = 1; i <= n; i++) {
    if (suf[i] - i > i - pre[i]) {
      for (int j = pre[i] - 1; j < i; j++) {
        ans = ans + solve(i, suf[i], (sum[j] + a[i]) % k);
      }
    } else {
      for (int j = i; j <= suf[i]; j++) {
        int tmp = solve(pre[i] - 1, i - 1, (sum[j] - a[i]) % k);
        ans += tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
