#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int maxn((1 << 21) + 1);
char ibuf[maxn], *iS, *iT, c;
int f;
inline char Getc() {
  return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
                     (iS == iT ? EOF : *iS++))
                  : *iS++;
}
template <class Int>
inline void In(Int &x) {
  for (f = 1, c = Getc(); c < '0' || c > '9'; c = Getc()) f = c == '-' ? -1 : 1;
  for (x = 0; c >= '0' && c <= '9'; c = Getc())
    x = (x << 1) + (x << 3) + (c ^ 48);
  x *= f;
}
}  // namespace IO
using IO ::In;
const int maxn(3e5 + 5);
int n, k, a[maxn], st[20][maxn], lg[maxn], s[maxn], tot[1000000];
long long ans;
vector<pair<int, int> > qry[maxn];
inline int Max(int x, int y) { return a[x] > a[y] ? x : y; }
inline int RMQ(int l, int r) {
  int len = lg[r - l + 1];
  return Max(st[len][l], st[len][r - (1 << len) + 1]);
}
void Query(int l, int r, int v) {
  if (l > r) return;
  qry[l - 1].push_back(make_pair(-1, v)), qry[r].push_back(make_pair(1, v));
}
void Solve(int l, int r) {
  if (l >= r) return;
  int mid = RMQ(l, r), v = k - a[mid] % k;
  if (mid - l < r - mid) {
    Query(mid + 1, r, (s[mid - 1] + a[mid]) % k);
    for (int i = mid - 1; i >= l; --i) Query(mid, r, (s[i - 1] + a[mid]) % k);
  } else {
    Query(l - 1, mid - 2, (s[mid] + v) % k);
    for (int i = mid + 1; i <= r; ++i) Query(l - 1, mid - 1, (s[i] + v) % k);
  }
  Solve(l, mid - 1), Solve(mid + 1, r);
}
int main() {
  In(n), In(k);
  for (int i = 1; i <= n; ++i)
    In(a[i]), st[0][i] = i, s[i] = (s[i - 1] + a[i]) % k;
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; j <= lg[n]; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      st[j][i] = Max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
  Solve(1, n);
  for (int i = 0, j, l; i <= n; ++i)
    for (++tot[s[i]], j = 0, l = qry[i].size(); j < l; ++j)
      ans += 1LL * qry[i][j].first * tot[qry[i][j].second];
  printf("%lld\n", ans);
  return 0;
}
