#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int const nmax = 300010;
int n, k;
vector<int> a;
int d[nmax];
int cnt[1000000];
vector<int> st[1000010];
class SegmentTree {
 private:
  int n;
  vector<int> st, A;
  int left(int p) { return p << 1; };
  int right(int p) { return (p << 1) + 1; }
  void build(int p, int L, int R) {
    if (L == R)
      st[p] = L;
    else {
      build(left(p), L, (L + R) / 2);
      build(right(p), (L + R) / 2 + 1, R);
      int p1 = st[left(p)], p2 = st[right(p)];
      st[p] = (A[p1] <= A[p2]) ? p1 : p2;
    }
  }
  int rmq(int p, int L, int R, int i, int j) {
    if (i > R || j < L) return -1;
    if (L >= i && R <= j) return st[p];
    int p1 = rmq(left(p), L, (L + R) / 2, i, j);
    int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
    return (A[p1] <= A[p2]) ? p1 : p2;
  }

 public:
  void init(const vector<int> &_A) {
    A = _A;
    n = (int)A.size();
    st.assign(4 * n, 0);
    build(1, 0, n - 1);
  }
  int rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }
} smt;
long long run(int l, int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  int mid = smt.rmq(l, r);
  long long res = 0;
  if (mid - l < r - mid) {
    for (int i = l; i < mid + 1; i++) {
      int h = (k + d[i] + (-a[mid] % k)) % k;
      int u = lower_bound(st[h].begin(), st[h].end(), r + 2) - st[h].begin();
      int v = lower_bound(st[h].begin(), st[h].end(), mid + 1) - st[h].begin();
      int end = st[h].end() - st[h].begin();
      if (v != end && st[h][v] <= r + 1) res += u - v;
    }
  } else {
    for (int i = mid + 1; i < r + 2; i++) {
      int h = (k + d[i] - (-a[mid] % k)) % k;
      int u = lower_bound(st[h].begin(), st[h].end(), mid + 1) - st[h].begin();
      int v = lower_bound(st[h].begin(), st[h].end(), l) - st[h].begin();
      int end = st[h].end() - st[h].begin();
      if (v != end && st[h][v] <= mid) res += u - v;
    }
  }
  return res + run(l, mid - 1) + run(mid + 1, r);
}
void solve() {
  memset(d, 0, sizeof(d));
  scanf("%d%d", &n, &k);
  st[0].push_back(0);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    a.push_back(-p);
    d[i + 1] = (d[i] + p) % k;
    st[d[i + 1]].push_back(i + 1);
  }
  smt.init(a);
  printf("%I64d", run(0, n - 1) - n);
}
int main() {
  solve();
  return 0;
}
