#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
long long COM(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
  int n;
  cin >> n;
  long long m;
  cin >> m;
  vector<long long> a(n);
  vector<long long> sum(n + 1, 0LL);
  long long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    s %= m;
    sum[i + 1] = s;
  }
  map<long long, long long> q;
  for (int i = 0; i <= n; i++) {
    if (q.find(sum[i]) != q.end()) {
      q[sum[i]]++;
    } else {
      q[sum[i]] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << sum[i] << endl;
  }
  long long ans = 0;
  for (auto i = q.begin(); i != q.end(); i++) {
    ans += i->second * (i->second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
