#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank>
inline void smin(blank &a, blank b) {
  a = min(a, b);
}
template <class blank>
inline void smax(blank &a, blank b) {
  a = max(a, b);
}
const long long maxn = 3e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 10;
const long long SQ = 317;
long long a[maxn], pref[maxn], n, k, q[maxn], t, l[maxn], r[maxn], res;
vector<long long> pos[maxn * 10];
inline long long countInterval(long long l, long long r, long long val) {
  if (l > r) return 0;
  return lower_bound(pos[val].begin(), pos[val].end(), r) -
         lower_bound(pos[val].begin(), pos[val].end(), l);
}
int32_t main() {
  n = in(), k = in();
  read(a, n);
  memset(l, -1, sizeof l);
  fill(r, r + n, n);
  pos[0].push_back(0);
  for (long long i = 0; i < n; i++)
    pref[i] = ((i ? pref[i - 1] : 0) + a[i]) % k, pos[pref[i]].push_back(i + 1);
  for (long long i = 0; i < n; i++) {
    while (t && a[q[t - 1]] < a[i]) t--;
    if (t) l[i] = q[t - 1];
    q[t++] = i;
  }
  t = 0;
  for (long long i = n - 1; i >= 0; i--) {
    while (t && a[q[t - 1]] <= a[i]) t--;
    if (t) r[i] = q[t - 1];
    q[t++] = i;
  }
  for (long long i = 0; i < n; i++) a[i] %= k;
  for (long long id = 0; id < n; id++) {
    if (r[id] - id > id - l[id]) {
      for (long long left = l[id] + 1; left <= id; left++)
        res += countInterval(max(left + 2, id + 1), r[id] + 1,
                             (a[id] + (left ? pref[left - 1] : 0)) % k);
    } else {
      for (long long right = r[id] - 1; right >= id; right--)
        res += countInterval(l[id] + 1, min(right, id + 1),
                             (pref[right] - a[id] + k) % k);
    }
  }
  cout << res << "\n";
}
