#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long INF = 1e16;
const long long MOD = 1e9 + 7;
std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,
                                        std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}
void solve(long long N, long long M, std::vector<long long> A) {
  vector<long long> acc(N + 1);
  for (int(n) = (0); (n) < (N); ++(n)) {
    acc[n + 1] = acc[n] + A[n];
  }
  map<long long, long long> cnts;
  for (int(n) = (0); (n) < (N + 1); ++(n)) {
    cnts[acc[n] % M]++;
  }
  long long ans = 0;
  vector<vector<long long>> combination = comb(N, 2);
  for (auto(cnt) = (cnts).begin(); (cnt) != (cnts).end(); (cnt)++) {
    long long num = cnt->second;
    ans += combination[num][2];
  }
  cout << ans << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}
