Border
Contest: Codeforces Round 499 (Div. 1)
Difficulty rating: 1800
Tags: number theory

Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.

There are $$$n$$$ banknote denominations on Mars: the value of $$$i$$$-th banknote is $$$a_i$$$. Natasha has an infinite number of banknotes of each denomination.

Martians have $$$k$$$ fingers on their hands, so they use a number system with base $$$k$$$. In addition, the Martians consider the digit $$$d$$$ (in the number system with base $$$k$$$) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base $$$k$$$ is $$$d$$$, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.

Determine for which values $$$d$$$ Natasha can make the Martians happy.

Natasha can use only her banknotes. Martians don't give her change.

Input format:
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of banknotes on Mars.

All numbers are given in decimal notation.

Output format:
On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy.

In the second line, output all these values in increasing order.

Print all numbers in decimal notation.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
Consider the first test case. It uses the octal number system.

If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.

If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. In the octal system, it is $$$40_8$$$. The last digit is $$$0_8$$$.

If you take two banknotes with the value of $$$20$$$, the total value will be $$$40$$$, this is $$$50_8$$$ in the octal system. The last digit is $$$0_8$$$.

No other digits other than $$$0_8$$$ and $$$4_8$$$ can be obtained. Digits $$$0_8$$$ and $$$4_8$$$ could also be obtained in other ways.

The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.

Example input:
2 8
12 20

Example output:
2
0 4

Example input:
3 10
10 20 30

Example output:
1
0

Editorial:
Note that the condition "the last digit in the record of Natasha's tax amount in the number system with the base $$$k$$$ will be $$$d$$$" is equivalent to the condition "the remainder of dividing the tax on $$$k$$$ will be $$$d$$$".
Let $$$g=GCD(a_1,a_2,\ldots,a_n)$$$. It is stated that the original problem is equivalent to the problem where $$$n=1$$$ and the only banknote is $$$g$$$.
Evidence. We prove this with the help of the Bézout's identity. It follows that an equation of the form $$$a_1$$$$$$x_1+a_2$$$$$$x_2+\dots+a_n$$$$$$x_n=c$$$, where at least one of the parameters $$$a_1,a_2,\dots,a_n$$$ is not zero, has a solution in integers if and only if $$$c \hspace{2pt} \vdots \hspace{2pt} GCD(a_1,a_2,…,a_n)$$$. Then in this task Natasha can pay $$$x_i$$$ banknotes of the $$$i$$$-th nominal value for each $$$i$$$, where $$$1\le i\le n$$$, and the amount of tax ($$$a_1$$$$$$x_1+a_2$$$$$$x_2+\dots+a_n$$$$$$x_n$$$) can be any number $$$c$$$, multiple $$$g$$$. (Here some $$$x_i<0$$$, But Natasha can add for each par a sufficiently large number, multiple $$$k$$$, that $$$x_i$$$ became greater than zero, the balance from dividing the amount of tax on $$$k$$$ from this will not change.) Therefore, you can replace all pars with one par $$$g$$$ and the answer from this will not change.
Now we can sort out all the numbers of the form $$$gx\bmod k$$$, where $$$0\le x<k$$$ (further the remainder of the sum, divided by $$$k$$$ will cycle repeatedly) and output them in ascending order.
Complexity: $$$O(n+\log m+k\log k)$$$, where $$$m$$$ is the greatest $$$a_i$$$.
Bonus. Try to improve the complexity to $$$O(n+k)$$$.