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-----

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-----

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.


-----Examples-----
Input
2 8
12 20

Output
2
0 4 
Input
3 10
10 20 30

Output
1
0 


-----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.

Difficulty: MEDIUM_HARD
Tags: Number theory

Starter code:

Solutions:
from functools import reduce
from math import gcd
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
G = gcd(k, reduce(lambda x, y: gcd(x, y), A))
print(k // G)
print(*list(range(0, k, G)))


from math import gcd
from functools import reduce
(n, k) = [int(aa) for aa in input().split()]
a = [int(aa) for aa in input().split()]
g = reduce(gcd, a) % k
answ = [0] * k
pos = g
count = 0
while answ[pos] == 0:
	answ[pos] = 1
	pos = (pos + g) % k
	count += 1
print(count)
for i in range(len(answ)):
	if answ[i] == 1:
		print(i, end=' ')


import sys
import math
from collections import defaultdict
(n, k) = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
l = [0 for _ in range(n)]
for i in range(n):
	l[i] = a[i] % k
ans = set()
ans.add(0)
vis = defaultdict(int)
x = 0
for i in range(n):
	x = math.gcd(x, l[i])
st = 0
x = math.gcd(x, k)
while st * x < k and x != 0:
	ans.add(st * x)
	st += 1
print(len(ans))
res = list(ans)
res.sort()
print(*res)


import math
from functools import reduce

def read():
	return int(input())

def readmap():
	return map(int, input().split())

def readlist():
	return list(map(int, input().split()))

def gcd_list(numbers):
	return reduce(math.gcd, numbers)
(n, k) = readmap()
A = readlist()
B = [a % k for a in A if a % k > 0]
if B:
	B.append(k)
	g = gcd_list(B)
else:
	print(1)
	print(0)
	quit()
ans = [a for a in range(k) if a % g == 0]
print(len(ans))
print(' '.join(list(map(str, ans))))


from math import gcd
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
g = 0
for i in a:
	g = gcd(g, i)
ans = set()
ans.add(g % k)
for i in range(k):
	ans.add(i * g % k)
print(len(ans))
print(*sorted(list(ans)))


from math import gcd
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if n == 1:
	ans = a[0]
else:
	ans = gcd(a[0], a[1])
for i in range(2, n):
	ans = gcd(ans, a[i])
ans %= k
cur = ans
c = set()
while cur % k not in c:
	c.add(cur % k)
	cur += ans
print(len(c))
c = list(c)
c.sort()
for v in c:
	print(v, end=' ')


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
g = 0
for i in a:
	g = gcd(g, i)
res = set()
for i in range(0, k * g, g):
	res.add(i % k)
print(str(len(res)) + ' \n' + ' '.join(map(str, sorted(res))))


import math

def binpow(a, n):
	if n == 0:
		return 1
	if n % 2 == 1:
		return binpow(a, n - 1) * a
	else:
		b = binpow(a, n // 2)
		return b * b
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
gcd = a[0]
for i in range(1, n):
	gcd = math.gcd(gcd, a[i])
s = set()
d = gcd % k
isk = gcd
while d not in s:
	s.add(d)
	gcd += isk
	d = gcd % k
print(len(s))
print(*sorted(s))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a, b):
	while a != 0:
		(a, b) = (b % a, a)
	return b
divisor = a[0]
for i in range(1, n):
	divisor = gcd(divisor, a[i])
r = gcd(divisor, k)
print(k // r)
print(*[i * r for i in range(k // r)])


import sys
import os

def gcd(a, b):
	if a > b:
		return gcd(b, a)
	if a == 0:
		return b
	return gcd(b % a, a)

def build(n, d):
	print(n // d)
	r = []
	for i in range(n // d):
		r.append(i * d)
	print(' '.join(map(str, r)))

def solve(k, a):
	d = k
	for note in a:
		d = gcd(note, d)
		if d == 1:
			return build(k, d)
	return build(k, d)

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	solve(k, a)
main()


import math
i = lambda : map(int, input().split())
(n, k) = i()
g = k
for a in i():
	g = math.gcd(g, a)
print(k // g)
print(*range(0, k, g))


from math import gcd
from functools import reduce
(n, k) = map(int, input().split())
st = reduce(gcd, {int(e) % k for e in input().split()})
st = gcd(st, k)
print(k // st)
print(' '.join(map(str, range(0, k, st))))


import math
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
ddc = 0
f = 1
ans = set()
for x in a:
	if f:
		ddc = x % k
	o = 0
	o = x % k
	if not f:
		ddc = math.gcd(ddc, o)
	if o == 1:
		print(k)
		print(*list(range(k)))
		return
	f = 0
yy = ddc
while yy:
	ans.add(yy)
	yy += ddc
	yy %= k
ans.add(0)
print(len(ans))
print(*sorted(ans))


from math import gcd
(n, k) = map(int, input().split())
it = list(map(int, input().split()))
it = [i % k for i in it]
it = [i for i in it if i != 0]
try:
	gc = it[0]
	for i in range(1, len(it)):
		gc = gcd(it[i], gc)
	gc = gcd(k, gc)
	print(k // gc)
	for i in range(k // gc):
		print(i * gc, end=' ')
except:
	print(1)
	print(0)


from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf
from collections import Counter
import sys
sys.setrecursionlimit(1000000)
from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil, inf, factorial, log2
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 9)
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
g = 0
for i in l:
	g = gcd(i, g)
seti = set()
for i in range(k + 1):
	ka = g * i % k
	seti.add(ka)
print(len(seti))
for i in sorted(seti):
	print(i, end=' ')


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, k) = invr()
note = inara()
g = k
for taka in note:
	g = math.gcd(g, taka)
khushi = []
for i in range(0, k, g):
	khushi.append(i)
print(len(khushi))
print(*khushi)


def gcd(a, b):
	if b == 0:
		return a
	if b > a:
		return gcd(b, a)
	return gcd(b, a % b)
(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
out = k
for i in l:
	out = gcd(i, out)
print(k // out)
print(' '.join(list(map(str, range(0, k, out)))))


from math import gcd
(n, k) = map(int, input().split())
g = 0
l = list(map(int, input().split()))
for e in l:
	g = gcd(g, gcd(e, k))
print(k // g)
for i in range(0, k, g):
	print(i, end=' ')


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
(n, k) = map(int, input().split())
gcdd = 0
for el in input().split():
	el = int(el) % k
	if gcdd == 0:
		gcdd = gcd(el, k)
	else:
		gcdd = gcd(gcdd, el)
ans = []
for i in range(k):
	if i % gcdd == 0:
		ans.append(i)
print(len(ans))
print(*ans)


from math import gcd
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
g = 0
for ai in A:
	g = gcd(g, ai)
s = set()
x = 0
while True:
	d = g * x % k
	if d not in s:
		s.add(d)
	else:
		break
	x += 1
print(len(s))
print(*sorted(s))


from math import gcd
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a_ = [el % k for el in a]
g = gcd(k, a_[0])
for i in range(1, n):
	g = gcd(g, a_[i])
print(k // g)
print(' '.join(map(str, [g * i for i in range(k // g)])))


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
(n, k) = map(int, input().split(' '))
aa = list(map(int, input().split(' ')))
m = k
for a in aa:
	m = gcd(m, a)
print(k // m)
for i in range(0, k, m):
	print(i, end=' ')
print()


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
GCD = 0
for x in a:
	GCD = math.gcd(GCD, x)
ans = {GCD % k}
for i in range(k):
	ans.add(i * GCD % k)
print(len(ans))
print(*sorted(list(ans)))


def gcd(a, b):
	if b == 0:
		return a
	if a % b == 0:
		return b
	else:
		return gcd(b, a % b)
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
	a[i] = a[i] % k
a.append(k)
b = 0
for i in range(n + 1):
	b = gcd(b, a[i])
c = []
for i in range(0, k, b):
	c.append(i)
print(len(c))
print(*c)


from functools import reduce
from math import ceil, floor

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def extended_gcd(a, b):
	(s, old_s) = (0, 1)
	(r, old_r) = (b, a)
	while r:
		q = old_r // r
		(old_r, r) = (r, old_r - q * r)
		(old_s, s) = (s, old_s - q * s)
	return (old_r, old_s, (old_r - old_s * a) // b if b else 0)
gcdm = lambda args: reduce(gcd, args, 0)
lcm = lambda a, b: a * b // gcd(a, b)
lcmm = lambda *args: reduce(lcm, args, 1)

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	g = gcdm(a + [k])
	print(k // g)
	print(' '.join([str(x * g) for x in range(k // g)]))
main()


from math import gcd
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
g = 0
for ai in A:
	g = gcd(g, ai)
s = set()
x = 0
while x < k:
	d = g * x % k
	s.add(d)
	x += 1
print(len(s))
print(*sorted(s))


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(n, k) = map(int, input().split())
a = list(set([int(i) % k for i in input().split()]))
res = k
for i in a:
	res = gcd(res, i)
print(k // res)
print(*list(range(0, k, res)))


from math import gcd

def MinimumGCD(arr, n):
	g = 0
	for i in range(n):
		g = gcd(g, arr[i])
	return g
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(n):
	arr[i] = arr[i] % k
t = k + 1
for i in range(n):
	t = min(t, gcd(k, arr[i]))
t1 = MinimumGCD(arr, n)
t1 = gcd(t1 % k, k)
f = min(t, t1)
c = [0] * k
p = f % k
while c[p] == 0:
	c[p] = 1
	p = (p + f) % k
print(c.count(1))
for i in range(k):
	if c[i]:
		print(i, end=' ')


from functools import reduce
from math import gcd
(_, k) = map(int, input().split())
g = reduce(gcd, [k] + list(map(int, input().split())))
print(k // g)
print(' '.join((str(l) for l in range(0, k, g))))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = set()
g = a[0]
for i in a:
	g = math.gcd(g, i)
for i in range(k):
	s.add(g * i % k)
l = list(s)
l.sort()
print(len(s))
print(*l)


(n, k) = map(int, input().split(' '))
a = set(map(lambda x: int(x) % k, input().split(' ')))

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
a = list(a)
a.append(k)
res = a[0]
for i in a[1:]:
	res = gcd(res, i)
ans = k // res
print(ans)
out = []
for i in range(ans):
	out.append(str(i * res))
print(' '.join(out))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def lcm(a, b):
	return a * b // gcd(a, b)
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def N():
	return int(inp())

def solve():
	(n, k) = sep()
	ar = [int(i) % k for i in inp().strip().split(' ') if int(i) % k]
	if not ar:
		print(1)
		print(0)
		return
	g = reduce(gcd, ar)
	g = gcd(k, g)
	t = (k - 1) // g + 1
	print(t)
	ans = [0]
	for i in range(1, k):
		if i % g == 0:
			ans.append(i)
	print(*ans)
solve()


def gcd(x, y):
	if x == 0:
		return y
	elif y == 0:
		return x
	if x > y:
		return gcd(x % y, y)
	elif x < y:
		return gcd(x, y % x)
	else:
		return x
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
flag1 = 0
ans1 = k
i = 0
while i < n:
	ans1 = gcd(arr[i] % k, ans1)
	i += 1
arr1 = [0]
ans = ans1
if ans == k:
	print(1)
	print(0)
else:
	while ans1 < k:
		arr1.append(ans1)
		ans1 += ans
	print(len(arr1))
	print(*arr1)


import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
c = []
b = list(map(int, input().split()))
g = b[0]
for j in range(1, n):
	g = math.gcd(g, b[j])
l = 0
ans = []
j = 0
while j < k:
	ans.append(l % k)
	l += g
	j += 1
ans = sorted(list(set(ans)))
print(len(ans))
print(*ans)


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
gcdd = k
for i in range(n):
	gcdd = gcd(gcdd, l[i])
if gcdd == 0:
	print(1)
	print(0)
else:
	print(k // gcdd)
	ans = []
	for i in range(1, k // gcdd + 1):
		ans.append(i * gcdd % k)
print(' '.join(map(str, sorted(ans))))


from math import gcd
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
gd = 0
for i in range(n):
	gd = gcd(gd, arr[i])
count = gd
s = set()
for i in range(k):
	s.add(count % k)
	count += gd
s = list(s)
s.sort()
print(len(s))
print(*s)


(n, k) = map(int, input().split())
B = list(map(int, input().split()))

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
allgcd = k
for i in range(n):
	allgcd = gcd(allgcd, B[i])
x = k // allgcd
print(x)
ANS = [None] * x
for i in range(x):
	ANS[i] = allgcd * i
for i in range(x - 1):
	print(ANS[i], end=' ')
print(ANS[x - 1])


def nod(a, b):
	while a != 0 and b != 0:
		if a > b:
			(a, b) = (b, a % b)
		else:
			(b, a) = (a, b % a)
	return a + b
(n, k) = map(int, input().split())
a = [int(j) for j in input().split()]
c = a[0]
for i in range(1, n):
	c = nod(c, a[i])
	if c == 1:
		break
e = nod(c, k)
if c == 1 or e == 1:
	print(k)
	for i in range(k):
		print(i, end=' ')
if e > 1:
	c = k // e
	print(c)
	for i in range(c):
		print(i * e, end=' ')


from math import gcd
(n, k) = map(int, input().split())
a = set([int(x) % k for x in input().split()])
ans = k
for elem in a:
	ans = gcd(ans, elem)
print(k // ans)
print(*list(range(0, k, ans)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import math
g = a[0]
for i in range(1, n):
	g = math.gcd(g, a[i])
if g == 0:
	print(1, 0, sep='\n')
else:
	l = g * k // math.gcd(g, k)
	f = []
	gt = g
	for i in range(k):
		f.append(g % k)
		g += gt
print(len(set(f)))
print(*sorted(list(set(f))))


import sys
from math import gcd
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for i in range(1, n):
	g = gcd(g, a[i])
s = set()
val = 0
for i in range(k):
	s.add(val % k)
	val += g
s = list(s)
s.sort()
print(len(s))
print(*s)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m) = map(int, input().split())
k = m

def convert(no):
	return no % k
l = list(map(int, input().split()))
l = [convert(l[i]) for i in range(n)]
g = 0
for i in range(n):
	g = math.gcd(g, l[i])
if g == 0:
	print(1)
	print(0)
	sys.exit(0)
g = math.gcd(g, k)
t = 0
l = []
while t < k:
	l.append(t % k)
	t += g
l = set(l)
print(len(l))
print(*sorted(list(l)))


from functools import reduce

def gcd(x, y):
	if x == 0:
		return y
	elif y == 0:
		return x
	if x > y:
		return gcd(x % y, y)
	elif x < y:
		return gcd(x, y % x)
	else:
		return x

def main():
	[n, k] = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	gcd1 = reduce(gcd, a + [k])
	print(int(k / gcd1))
	print(' '.join([str(gcd1 * x) for x in range(int(k / gcd1))]))
main()


(n, k) = list(map(int, input().split()))
g = lambda x: int(x) % k
a = list(map(g, input().split()))

def nod(a, b):
	while b > 0:
		a %= b
		(a, b) = (b, a)
	return a
c = k
for x in a:
	if x != 0:
		c = nod(c, x)
print(k // c)
print(' '.join(map(str, list(range(0, k, c)))))


import math
(n, k) = map(int, input().split())
g = k
for a in map(int, input().split()):
	g = math.gcd(g, a)
print(k // g)
print(' '.join(map(str, range(0, k, g))))


(x, y) = map(int, input().split())
from math import gcd
s = list(map(int, input().split()))
st = set()
gc = 0
for n in s:
	gc = gcd(gc, n)
p = 0
for n in range(y):
	st.add(p % y)
	p += gc
print(len(st))
v = []
for n in st:
	v.append(n)
v.sort()
print(*v)


import sys
from math import gcd
(N, k) = [int(x) for x in input().split()]
sk = [int(x) for x in input().split()]
dbd = 0
for i in sk:
	dbd = gcd(dbd, i)
ats = set()
for i in range(k):
	ats.add(i * dbd % k)
print(len(ats))
ats2 = sorted(ats)
for i in ats2:
	print(i, end=' ')


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
(n, k) = map(int, input().split())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
gcd = a[0]
for i in range(1, n):
	gcd = hcfnaive(gcd, a[i])
l = 0
ans = []
for i in range(k):
	ans.append(l % k)
	l += gcd
ans = list(set(ans))
ans.sort()
print(len(ans))
print(*ans)


from math import gcd
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
g = 0
for Ai in A:
	g = gcd(g, Ai)
s = set()
x = 0
while x not in s:
	s.add(x)
	x = (x + g) % K
print(len(s))
print(*sorted(s))


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
g = a[0] % k
for i in range(1, n):
	g = gcd(g, a[i] % k)
ans = [g]
x = (g + g) % k
while x != g:
	ans.append(x)
	x += g
	x %= k
print(len(ans))
ans.sort()
for i in ans:
	print(i, end=' ')
print()


import os, io, math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
r = k
for i in range(n):
	r = math.gcd(r, a[i])
ans = []
for i in range(0, k, r):
	ans.append(i)
print(len(ans))
print(' '.join(map(str, ans)))


import os, sys
from io import BytesIO, IOBase
from math import gcd
from functools import reduce

def main():
	(n, k) = map(int, input().split())
	if n == 1:
		gc = gcd(int(input()), k)
	else:
		gc = gcd(k, reduce(lambda aa, bb: gcd(int(aa) % k, int(bb) % k), input().split()))
	if not gc:
		print(0)
		print(0)
	else:
		print(k // gc)
		print(*range(0, k, gc))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import gcd
from functools import reduce

def main():
	(n, k) = map(int, input().split())
	g = reduce(gcd, map(int, input().split()), k)
	print(k // g, ' '.join(map(str, range(0, k, g))), sep='\n')
main()


import math
from functools import reduce
(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = c[0]
for j in range(a):
	d = math.gcd(d, c[j])
	if d == 1:
		break
e = math.gcd(d, b)
print(b // e)
print(' '.join((str(k) for k in range(b) if k % e == 0)))


from math import gcd
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))[:n]
a = set([b % k for b in a])
a = set([gcd(k, b) for b in a if b > 0])
if len(a) == 0:
	print(1)
	print(0)
	exit()
mg = min(a)
for d in a:
	mg = gcd(mg, d)
	if mg == 1:
		break
res = [mg * j for j in range(k // mg)]
print(len(res))
print(*res)


def mi():
	return map(int, input().split())

def gcd(a, b):
	if b < a:
		(a, b) = (b, a)
	if a == 0:
		return b
	return gcd(a, b % a)
(n, k) = mi()
a = list(mi())
g = 0
for i in a:
	g = gcd(g, i)
t = g % k
ans = [t]
c = 1
t += g
while True:
	if ans[0] == t % k:
		break
	ans.append(t % k)
	c += 1
	t += g
print(c)
ans.sort()
for i in ans:
	print(i, end=' ')


from functools import reduce

def gcd(a, b):
	if a == 0:
		return b
	else:
		return gcd(b % a, a)
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
G = gcd(k, reduce(lambda x, y: gcd(x, y), A))
print(k // G)
for i in range(0, k, G):
	print(i, end=' ')


def gcd(a, b):
	return a if 0 == b else gcd(b, a % b)
(n, k) = map(int, input().split(' '))
den = list(map(int, input().split(' ')))
g = 0
for i in den:
	g = gcd(g, i)
d = []
dic = {}
i = 0
while i < k:
	val = i * g % k
	if not val in dic:
		d.append(val)
		dic[val] = 1
		i = i + 1
	else:
		i = i + 1
		continue
print(len(d))
d.sort()
for val in d:
	print(val, end=' ')


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		(n, k) = map(int, input().strip().split())
		a = list(map(int, input().strip().split()))

		def gcd(a, b):
			if a < b:
				(a, b) = (b, a)
			return a if b == 0 else gcd(b, a % b)
		g = a[0]
		for ai in a:
			g = gcd(g, ai)
		s = set()
		x = g
		while True:
			r = x % k
			if r in s:
				break
			s.add(r)
			x += g
		s = list(s)
		s.sort()
		print(len(s))
		print(' '.join(map(str, s)))
solver()()


(n, k) = map(int, input().split())
v = list(map(int, input().split()))

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
g = v[0]
for i in range(1, n):
	g = gcd(g, v[i])
lst = set()
for i in range(k):
	lst.add(g * i % k)
lst = sorted(list(lst))
print(len(lst))
print(' '.join(map(str, lst)))