#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  for (int i = 0; i < (N); i++) cin >> a[i];
  vector<ll> m(N + 1);
  for (int i = 0; i < (N); i++) m[i + 1] = (m[i] + a[i]) % M;
  vector<vector<int>> s(M, vector<int>(N + 1));
  for (int i = 0; i < (M); i++) {
    for (int j = 0; j < (N); j++) {
      s[i][j + 1] = s[i][j];
      if (m[j + 1] == i) s[i][j + 1]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) ans += s[m[i - 1]][N] - s[m[i - 1]][i - 1];
  cout << ans << endl;
  return 0;
}
