#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int a[1000125], sa[1000125], pre[1000125], nxt[1000125], rsa[1000125];
vector<int> pos[2][1000125];
int fd(int id, int val, int l, int r) {
  int a = upper_bound(pos[id][val].begin(), pos[id][val].end(), r) -
          pos[id][val].begin();
  int b = lower_bound(pos[id][val].begin(), pos[id][val].end(), l) -
          pos[id][val].begin();
  return a - b;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", a + i);
    sa[i] = a[i] % k;
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) (sa[i] += sa[i - 1]) %= k;
  for (int(i) = 1; (i) <= (int)(n); (i)++) pos[0][sa[i]].push_back(i);
  for (int i = n; i; i--) {
    rsa[i] = (rsa[i + 1] + a[i]) % k;
    pos[1][rsa[i]].push_back(i);
  }
  for (int(i) = 0; (i) < (int)(k); (i)++)
    reverse(pos[1][i].begin(), pos[1][i].end());
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int j = i - 1;
    while (j > 0 && a[j] <= a[i]) j = pre[j];
    pre[i] = j;
  }
  for (int i = n; i; i--) {
    int j = i + 1;
    while (j <= n && a[j] < a[i]) j = nxt[j];
    nxt[i] = j;
  }
  long long ans = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int l = pre[i] + 1, r = nxt[i] - 1;
    if (i - l < r - i) {
      for (int j = l; j <= i; j++) {
        int x = (sa[i] + sa[j - 1] - sa[i - 1]) % k;
        x = (x + k) % k;
        int t = fd(0, x, j == i ? i + 1 : i, r);
        ans += t;
      }
    } else {
      for (int j = i; j <= r; j++) {
        int x = (rsa[i] + rsa[j + 1] - rsa[i + 1]) % k + k;
        x %= k;
        int t = fd(1, x, l, j == i ? i - 1 : i);
        ans += t;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
