#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 1e6 + 7;
const int INF = 1e9 + 7;
int n, k;
int a[maxn];
vector<int> fac[maxn];
int sum[maxn];
int L[maxn], R[maxn];
long long ans;
void ini() {
  stack<int> st;
  a[n + 1] = INF;
  for (int i = 1; i < n + 1; i++) L[i] = 1;
  for (int i = 1; i < n + 2; i++) {
    int num = 0;
    while (!st.empty() && a[st.top()] <= a[i]) {
      int p = st.top();
      st.pop();
      R[p] = num;
      L[i] += L[p];
      num = L[p] + R[p];
    }
    st.push(i);
  }
}
int query(int x, int l, int r) {
  int a = lower_bound(fac[x].begin(), fac[x].end(), l) - fac[x].begin();
  int b = upper_bound(fac[x].begin(), fac[x].end(), r) - fac[x].begin();
  return b - a;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n + 1; i++) sum[i] = (sum[i - 1] + a[i]) % k;
  fac[0].push_back(0);
  for (int i = 1; i < n + 1; i++) fac[sum[i]].push_back(i);
  for (int i = 1; i < n + 1; i++)
    for (L[i] = i - 1; L[i] && a[L[i]] < a[i]; L[i] = L[L[i]])
      ;
  for (int i = n; i > 0; i--)
    for (R[i] = i + 1; R[i] <= n && a[R[i]] <= a[i]; R[i] = R[R[i]])
      ;
  for (int i = 1; i < n + 1; i++) {
    if (i - L[i] < R[i] - i) {
      for (int j = L[i]; j < i; j++)
        ans += query((sum[j] + a[i]) % k, i, R[i] - 1);
    } else {
      for (int j = i; j < R[i]; j++)
        ans += query((sum[j] - a[i] % k + k) % k, L[i], i - 1);
    }
  }
  printf("%I64d\n", ans - n);
  return 0;
}
