#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
  scanf("%d", &head);
  RI(tail...);
}
template <typename T>
void _dump(const char* s, T&& head) {
  cerr << s << "=" << head << endl;
}
template <typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail) {
  int c = 0;
  while (*s != ',' || c != 0) {
    if (*s == '(' || *s == '[' || *s == '{') c++;
    if (*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << "=" << head << ", ";
  _dump(s + 1, tail...);
}
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename T>
ostream& operator<<(ostream& s, const set<T>& c) {
  return _out(s, begin(c), end(c));
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const map<A, B>& c) {
  return _out(s, begin(c), end(c));
}
vector<int> app[1000010];
int ask(int l, int r, int v) {
  auto it = lower_bound(begin(app[v]), end(app[v]), l);
  auto jt = upper_bound(begin(app[v]), end(app[v]), r);
  return jt - it;
}
int n, m, a[300010], sa[300010], ord[300010], l[300010], r[300010];
bool vis[300010];
bool cmp(int x, int y) { return a[x] < a[y]; }
long long calc(int l1, int r1, int l2, int r2, int mx) {
  long long ans = 0;
  mx %= m;
  if (r1 - l1 <= r2 - l2) {
    for (int i = (l1 - 1); i <= int(r1 - 1); i++) {
      int x = sa[i] + mx;
      if (x >= m) x -= m;
      int now = ask(l2, r2, x);
      ans += now;
    }
  } else {
    for (int i = (l2); i <= int(r2); i++) {
      int x = sa[i] - mx;
      if (x < 0) x += m;
      int now = ask(l1 - 1, r1 - 1, x);
      ans += now;
    }
  }
  return ans;
}
int main() {
  RI(n, m);
  for (int i = (1); i <= int(n); i++) RI(a[i]);
  for (int i = (1); i <= int(n); i++) l[i] = r[i] = i;
  for (int i = (1); i <= int(n); i++) ord[i] = i;
  for (int i = (1); i <= int(n); i++) sa[i] = (sa[i - 1] + a[i]) % m;
  for (int i = (0); i <= int(n); i++) app[sa[i]].push_back(i);
  sort(ord + 1, ord + n + 1, cmp);
  long long ans = 0;
  for (int ii = (1); ii <= int(n); ii++) {
    int i = ord[ii];
    vis[i] = 1;
    if (i > 1 && vis[i - 1]) {
      ans += calc(l[i - 1], i - 1, i, i, a[i]);
      l[i] = l[i - 1];
      r[l[i - 1]] = i;
    }
    if (i < n && vis[i + 1]) {
      ans += calc(l[i], i, i + 1, r[i + 1], a[i]);
      r[l[i]] = r[i + 1];
      l[r[i + 1]] = l[i];
    }
  }
  cout << ans << endl;
  return 0;
}
