#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  map<long, long> rests;
  long s = 0;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    s = (s + a) % m;
    rests[s]++;
  }
  long ans = 0;
  for (const auto [key, value] : rests) {
    cout << key << " " << value << endl;
    if (key == 0)
      ans += value * (value + 1) / 2;
    else
      ans += value * (value - 1) / 2;
  }
  cout << ans << endl;
}
