#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void ioi(string name) {
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
int n, w, a[300005], b[300005], l[300005], r[300005];
vector<int> v, t[1000005];
long long e;
int f(int l, int r, int k) {
  return upper_bound(t[k].begin(), t[k].end(), r) -
         upper_bound(t[k].begin(), t[k].end(), l - 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  cerr.precision(10);
  ;
  cin >> n >> w;
  t[0].push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = (b[i - 1] + a[i]) % w;
    t[b[i]].push_back(i);
    while ((int)v.size() && a[v.back()] <= a[i]) v.pop_back();
    l[i] = ((int)v.size() ? v.back() : 0) + 1;
    v.push_back(i);
  }
  v.clear();
  for (int i = n; i >= 1; i--) {
    while ((int)v.size() && a[v.back()] < a[i]) v.pop_back();
    r[i] = ((int)v.size() ? v.back() : n + 1) - 1;
    v.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (r[i] - i > i - l[i]) {
      for (int j = l[i]; j <= i; j++) {
        e += f(i, r[i], (b[j - 1] + a[i]) % w);
      }
    } else {
      for (int j = i; j <= r[i]; j++) {
        e += f(l[i] - 1, i - 1, ((b[j] - a[i]) % w + w) % w);
      }
    }
  }
  cout << e - n;
  return 0;
}
