#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  for (int n = 0; n < N; n++) cin >> A[n];
  unordered_map<long long, long long> um;
  um[A[0] % M]++;
  for (int n = 1; n < N; n++) {
    A[n] += A[n - 1];
    um[A[n] % M]++;
  }
  long long count = 0;
  for (auto i = um.begin(); i != um.end(); i++) {
    long long a = i->first, b = i->second;
    cout << a << " " << b << endl;
    count += (b) * (b - 1) / 2;
  }
  count += um[0];
  cout << count << endl;
}
