#include <bits/stdc++.h>
using namespace std;
const long long hmod1 = 999999937;
const long long hmod2 = 1000000000 + 9;
const long long INF = 1 << 30;
const long long INFLL = 1LL << 62;
const long double EPS = 1e-12;
const long long mod = 1000000000 + 7;
const long long dx4[4] = {1, 0, -1, 0};
const long long dy4[4] = {0, 1, 0, -1};
const long long dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const long long dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const long double pi = 3.141592653589793;
void dump_func() { cout << endl; };
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0)
    cout << " ";
  else
    cout << ", ";
  dump_func(std::move(tail)...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  for (long long i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
  os << "[";
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << "(" << itr->first << ", " << itr->second << ")";
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "]";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
  os << "[";
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "]";
  return os;
}
long long n, m;
long long a[100000 + 5];
long long sum[100000 + 5];
map<long long, long long> mp;
long long ans = 0;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = (1); i < (n); i++) {
    cin >> a[i];
    sum[i] = a[i];
    sum[i] += sum[i - 1];
  }
  for (long long i = 0; i < (n + 1); i++) {
    sum[i] %= m;
    mp[sum[i]]++;
  }
  for (auto x : mp) {
    cout << x.first << endl;
    ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}
