#include <bits/stdc++.h>
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
using namespace std;
map<long long int, long long int> memo;
long long int comb2Ck(long long int k) {
  if (k % 2 == 0) {
    return k / 2 * (k - 1);
  } else {
    return (k - 1) / 2 * k;
  }
}
void solve() {
  long long int N, M;
  cin >> N >> M;
  long long int sum = 0;
  memo[0]++;
  while (N--) {
    long long int a;
    cin >> a;
    sum += a;
    memo[sum % M]++;
  }
  long long int ans = 0;
  for (auto pair : memo) {
    cout << pair.first << " " << pair.second << endl;
    long long int cnt = pair.second;
    ans += comb2Ck(cnt);
  }
  cout << ans << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
