#include <bits/stdc++.h>
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
void get_combination_matrix(vvi& C, const int Size) {
  C = vvi(Size + 1, vi(Size + 1, 0));
  for (int i = int(0); i < int(Size + 1); ++i) {
    C[i][0] = 1;
    C[i][i] = 1;
  }
  for (int i = int(1); i < int(Size + 1); ++i) {
    for (int j = int(1); j < int(i); ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vl A(N);
  for (int i = int(0); i < int(N); ++i) cin >> A[i];
  vl S(N + 1);
  S[1] = A[0] % M;
  for (int i = int(1); i < int(N); ++i) {
    S[i + 1] = (S[i] + A[i]) % M;
  }
  map<int, int> mp;
  for (int i = int(0); i < int(N + 1); ++i) mp[S[i]]++;
  vvi C;
  get_combination_matrix(C, N + 1);
  ll ans = 0;
  for (auto p : mp) {
    ans += C[p.second][2];
  }
  cout << ans << endl;
  return 0;
}
