#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int p[1000006], q[1000006], lmax, lsum;
int rmax, rsum, l, r;
int n, k, i, j, a[N];
long long ans;
void move_left() {
  l--;
  lmax = ((lmax) > (a[l]) ? (lmax) : (a[l]));
  lsum = (lsum + a[l]) % k;
  p[lsum]++;
  int e = (lmax - lsum + k) % k;
  ans += q[e];
}
void move_right() {
  r++;
  rmax = ((rmax) > (a[r]) ? (rmax) : (a[r]));
  rsum = (rsum + a[r]) % k;
  q[rsum]++;
  int e = (rmax - rsum + k) % k;
  ans += p[e];
}
void go(int x, int y) {
  if (x == y) return;
  int d = (x + y) >> 1;
  go(x, d);
  go(d + 1, y);
  lmax = lsum = rmax = rsum = 0;
  l = d + 1, r = d;
  while (x < l || r < y) {
    if (x == l)
      move_right();
    else if (y == r)
      move_left();
    else if (((a[l - 1]) > (lmax) ? (a[l - 1]) : (lmax)) <=
             ((a[r + 1]) > (rmax) ? (a[r + 1]) : (rmax)))
      move_left();
    else
      move_right();
  }
  int e = 0;
  for (int i = d; i >= l; i--) {
    e = (e + a[i]) % k;
    p[e] = 0;
  }
  e = 0;
  for (int i = d + 1; i <= r; i++) {
    e = (e + a[i]) % k;
    q[e] = 0;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  go(1, n);
  cout << ans << endl;
  return 0;
}
