#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int arr[300009];
int sum[300009];
vector<int> st1[1000009];
int st2[4 * 300009];
long long ans = 0;
void build2(int s, int e, int idx) {
  if (s == e) {
    st2[idx] = s;
    return;
  }
  int m = (s + e) / 2;
  build2(s, m, 2 * idx + 1);
  build2(m + 1, e, 2 * idx + 2);
  if (arr[st2[2 * idx + 1]] >= arr[st2[2 * idx + 2]]) {
    st2[idx] = st2[2 * idx + 1];
  } else {
    st2[idx] = st2[2 * idx + 2];
  }
}
int query2(int s, int e, int idx, int l, int r) {
  if (s > e || s > r || l > e) {
    return 0;
  }
  if (l <= s && r >= e) {
    return st2[idx];
  }
  int m = (s + e) / 2;
  int x = query2(s, m, 2 * idx + 1, l, r);
  int y = query2(m + 1, e, 2 * idx + 2, l, r);
  if ((arr[x] >= arr[y])) {
    return x;
  } else {
    return y;
  }
}
long long query1(int l, int r, int val) {
  if (l > r || l < 0 || r < 0) {
    return 0;
  }
  return (long long)(upper_bound(st1[val].begin(), st1[val].end(), r) -
                     lower_bound(st1[val].begin(), st1[val].end(), l));
}
void solve(int l, int r) {
  if (l > r) {
    return;
  }
  if (l == r) {
    return;
  }
  if ((r - l) == 1) {
    if ((min(arr[r], arr[l])) % k == 0) {
      ans++;
    }
    return;
  }
  int m = query2(1, n, 0, l, r);
  solve(l, m - 1);
  solve(m + 1, r);
  if ((m - l + 1) <= (r - m + 1)) {
    for (int i = l; i < m; i++) {
      ans = ans + query1(m, r, (sum[i - 1] + arr[m] % k) % k);
    }
    ans = ans + query1(m + 1, r, (sum[m - 1] + arr[m] % k) % k);
  } else {
    for (int i = r; i > m; i--) {
      ans = ans + query1(max(l - 1, 0), m - 1, (sum[i] - arr[m] % k + k) % k);
    }
    ans = ans + query1(max(l - 1, 0), m - 2, (sum[m] - arr[m] % k + k) % k);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum[i] = (sum[i - 1] + arr[i]) % k;
  }
  for (int i = 0; i <= n; i++) {
    st1[sum[i]].push_back(i);
  }
  build2(1, n, 0);
  int l = 1, r = n;
  solve(l, r);
  printf("%lld\n", ans);
}
