#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> numbers;
  numbers.insert(0);
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    temp %= k;
    if (numbers.find(temp) != numbers.end()) continue;
    vector<int> temp1;
    for (auto u : numbers) {
      temp1.push_back(u);
    }
    for (auto u : temp1) {
      u = (u + temp) % k;
      while (numbers.find(u) == numbers.end()) {
        numbers.insert(u);
        u = (u + temp) % k;
      }
    }
  }
  cout << numbers.size() << '\n';
  for (auto u : numbers) cout << u << ' ';
  return 0;
}
