#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5, MAXK = 15;
int n, k, a[MAXN + 5], b[MAXN + 5];
int Cnt[1000005];
long long Ans, Sum[MAXN + 5];
int Maxdex[MAXN + 5][MAXK + 5];
void Init() {
  for (int i = 1; i <= n; i++) Maxdex[i][0] = i;
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      Maxdex[i][j] = a[Maxdex[i][j - 1]] > a[Maxdex[i + (1 << j - 1)][j - 1]]
                         ? Maxdex[i][j - 1]
                         : Maxdex[i + (1 << j - 1)][j - 1];
}
int Query(int l, int r) {
  int k = log2(r - l + 1);
  return a[Maxdex[l][k]] > a[Maxdex[r - (1 << k) + 1][k]]
             ? Maxdex[l][k]
             : Maxdex[r - (1 << k) + 1][k];
}
void Solve(int l, int r) {
  if (l > r) return;
  if (l == r) {
    Ans++;
    Cnt[b[l]]--;
    return;
  }
  int Mid = Query(l, r);
  if (Mid - l < r - Mid) {
    for (int i = l; i <= Mid - 1; i++) Cnt[b[i]]--;
    for (int i = l - 1; i <= Mid - 1; i++) Ans += Cnt[(Sum[i] + a[Mid]) % k];
    Cnt[b[Mid]]--;
    Solve(Mid + 1, r);
    for (int i = l; i <= Mid - 1; i++) Cnt[b[i]]++;
    Solve(l, Mid - 1);
  } else {
    for (int i = Mid; i <= r; i++) Cnt[b[i]]--;
    Cnt[b[l - 1]]++;
    for (int i = Mid; i <= r; i++) Ans += Cnt[(Sum[i] - a[Mid]) % k];
    Cnt[b[l - 1]]--;
    Solve(l, Mid - 1);
    for (int i = Mid + 1; i <= r; i++) Cnt[b[i]]++;
    Solve(Mid + 1, r);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    Sum[i] = Sum[i - 1] + a[i];
    b[i] = Sum[i] % k;
    Cnt[b[i]]++;
  }
  Init();
  Solve(1, n);
  printf("%lld\n", Ans - n);
  return 0;
}
