#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  map<long long, long long> ma;
  vector<long long> a(n);
  vector<long long> ans(n + 1);
  long long kotae = 0;
  long long tmp = 0;
  long long tmp2 = 1;
  for (int i = 0; i < (n); i++) {
    long long b;
    cin >> b;
    a[i] = tmp + b;
    tmp = a[i];
    if (a[i] % m == 0) {
      kotae++;
    }
    ma[a[i] % m]++;
    ans[i + 1] = tmp2 * (i + 1);
    tmp2 = ans[i + 1];
  }
  for (int i = 0; i < (m); i++) {
    if (ma[i] >= 2) {
      kotae += ans[ma[i]] / 2;
    }
  }
  cout << kotae << endl;
}
