#include <bits/stdc++.h>
using namespace std;
const int N = 300 * 1000 + 5, K = 1000 * 1000 + 5, LG = 20;
long long ans = 0;
int n, k;
int a[N], ps[N], cnt[K];
int dp[N][LG];
int get(int l, int r) {
  int x = 31 - __builtin_clz(r - l);
  int y = dp[l][x], z = dp[r - (1 << x)][x];
  if (a[y] > a[z]) {
    return y;
  }
  return z;
}
void solve(int l, int r) {
  if (r - l == 1) {
    cnt[ps[l]]++;
    return;
  }
  int x = get(l + 1, r), val = a[x] % k;
  if (r - x < x - l) {
    solve(x, r);
    for (int i = x; i < r; i++) {
      cnt[ps[i]] = 0;
    }
    solve(l, x);
    for (int i = x; i < r; i++) {
      ans += cnt[(ps[i] - val + k) % k];
    }
    for (int i = x; i < r; i++) {
      cnt[ps[i]]++;
    }
  } else {
    solve(l, x);
    for (int i = l; i < x; i++) {
      cnt[ps[i]] = 0;
    }
    solve(x, r);
    for (int i = l; i < x; i++) {
      ans += cnt[(ps[i] + val) % k];
    }
    for (int i = l; i < x; i++) {
      cnt[ps[i]]++;
    }
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i][0] = i;
    ps[i] = (ps[i - 1] + a[i]) % k;
  }
  for (int j = 1; j < LG; j++) {
    for (int i = 1; i <= n; i++) {
      dp[i][j] = dp[i][j - 1];
      if (i + (1 << (j - 1)) <= n &&
          a[dp[i + (1 << (j - 1))][j - 1]] > a[dp[i][j]]) {
        dp[i][j] = dp[i + (1 << (j - 1))][j - 1];
      }
    }
  }
  solve(0, n + 1);
  cout << ans - n;
  return 0;
}
