#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  long long i, a[100001], s[100001] = {0};
  map<long long, long long> mp;
  for (i = 1; i <= N; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
    mp[s[i] % M]++;
  }
  mp[0]++;
  long long ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    cout << it->first << " " << it->second << endl;
    long long t = it->second;
    ans += t * (t - 1) / 2;
  }
  cout << ans << endl;
}
