#include <bits/stdc++.h>
using namespace std;
long long n, k, a[1000005], res;
bool Free[1000005];
vector<long long> canUsed;
map<long long, int> M;
long long Q[1000005], front = 1, rear;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] %= k;
    if (!Free[a[i]]) {
      Q[++rear] = a[i];
      Free[a[i]] = 1;
      ++res;
    }
  }
  for (long long i = 1; i <= n; ++i) Free[a[i]] = 0;
  while (front <= rear) {
    if (!Free[Q[front]]) {
      canUsed.push_back(Q[front]);
      Free[Q[front]] = 1;
      for (long long i = 0; i < canUsed.size(); ++i) {
        if (!Free[(Q[front] + canUsed[i]) % k]) {
          Q[++rear] = (Q[front] + canUsed[i]) % k;
          Free[Q[rear]] = 1;
          canUsed.push_back(Q[rear]);
          ++res;
        }
      }
    }
    ++front;
  }
  for (int i = 0; i < canUsed.size(); ++i) M[canUsed[i]]++;
  cout << M.size() << '\n';
  for (map<long long, int>::iterator it = M.begin(); it != M.end(); ++it)
    cout << it->first << ' ';
  return 0;
}
