#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<stack>
#define de printf("\ndebug:\n")
#define End printf("\nend\n\n")
#define fi first
#define se second
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair< int,int > P;
typedef pair< ll,ll > Pll;
typedef pair< pair <int, int> ,int > PI;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template <class c>
struct rge
{
    c b, e;
};
template <class c>
rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c>
auto dud(c *x) -> decltype(std::cerr << *x, 0);
template <class c>
char dud(...);
struct debug
{
#ifndef ONLINE_JUDGE
    ~debug()
    {
        std::cerr << std::endl;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i)
    {
        std::cerr << std::boolalpha << i;
        return *this;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i)
    {
        return *this << range(begin(i), end(i));
    }
    template <class c, class b>
    debug &operator<<(std::pair<b, c> d)
    {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    template <class c>
    debug &operator<<(rge<c> d)
    {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << (char *)", " + 2 * (it == d.b) << *it;
        return *this << "]";
    }
#else
    template <class c>
    debug &operator<<(const c &)
    {
        return *this;
    }
#endif
};
#define imie(X) " [ " << #X ": " << (X) << " ] "

const int mod1=1e5+7;
const int mod2=1e9+7;
const ll mod3=1e12+7;
const int si=1050;
//const int N=1e6+7;
//ios::sync_with_stdio(false);
//priority_queue <int,vector<int>,less<int> > p;  p1>p2
//priority_queue <int,vector<int>,greater<int> > q;  q1<q2
//vector<int>().swap(a);

int n,k,a[si],gcd,now=1,cnt,sta;
set<int> s;
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%d",a);
    gcd=a[0];
    for(int i=1;i<n;i++)
    {
        scanf("%d",a+i);
        gcd=__gcd(gcd,a[i]);
    }
    debug()<<imie(gcd);
    for(int i=1;now!=0;i++)
    {
        debug()<<imie(i*gcd);
        now=i*gcd%k;
        debug()<<imie(now);
        //if(!b[now])
        //{
            s.insert(now);
        //}
    }
    printf("%d\n",s.size());
    for(auto v:s)
    {
        printf(" %d",v);
    }
    printf("\n");
    /*
    for(int i=0;i<k;i++)
    {
        if(b[i])
        {
            sta=i;
            printf("%d",i);
            break;
        }
    }
    for(int i=sta+1;i<k;i++)
    {
        if(b[i])
            printf(" %d",i);
    }
    printf("\n");*/
    return 0;
}

/*
10 5
4 6 8 6 4 10 2 10 8 6

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<stack>
#define de printf("\ndebug:\n")
#define End printf("\nend\n\n")
#define fi first
#define se second
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair< int,int > P;
typedef pair< ll,ll > Pll;
typedef pair< pair <int, int> ,int > PI;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template <class c>
struct rge
{
    c b, e;
};
template <class c>
rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c>
auto dud(c *x) -> decltype(std::cerr << *x, 0);
template <class c>
char dud(...);
struct debug
{
#ifndef ONLINE_JUDGE
    ~debug()
    {
        std::cerr << std::endl;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i)
    {
        std::cerr << std::boolalpha << i;
        return *this;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i)
    {
        return *this << range(begin(i), end(i));
    }
    template <class c, class b>
    debug &operator<<(std::pair<b, c> d)
    {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    template <class c>
    debug &operator<<(rge<c> d)
    {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << (char *)", " + 2 * (it == d.b) << *it;
        return *this << "]";
    }
#else
    template <class c>
    debug &operator<<(const c &)
    {
        return *this;
    }
#endif
};
#define imie(X) " [ " << #X ": " << (X) << " ] "

const int mod1=1e5+7;
const int mod2=1e9+7;
const ll mod3=1e12+7;
const int si=1050;
//const int N=1e6+7;
//ios::sync_with_stdio(false);
//priority_queue <int,vector<int>,less<int> > p;  p1>p2
//priority_queue <int,vector<int>,greater<int> > q;  q1<q2
//vector<int>().swap(a);

int n,k,a[si],gcd,now=1,cnt,sta;
bool b[si];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%d",a);
    gcd=a[0];
    for(int i=1;i<n;i++)
    {
        scanf("%d",a+i);
        gcd=__gcd(gcd,a[i]);
    }
    debug()<<imie(gcd);
    for(int i=1;now!=0;i++)
    {
        debug()<<imie(i*gcd);
        now=i*gcd%k;
        debug()<<imie(now);
        if(!b[now])
        {
            b[now]=1;
            cnt++;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<k;i++)
    {
        if(b[i])
        {
            sta=i;
            printf("%d",i);
            break;
        }
    }
    for(int i=sta+1;i<k;i++)
    {
        if(b[i])
            printf(" %d",i);
    }
    printf("\n");
    return 0;
}

/*
10 5
4 6 8 6 4 10 2 10 8 6

*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<stack>
#define de printf("\ndebug:\n")
#define End printf("\nend\n\n")
#define fi first
#define se second
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair< int,int > P;
typedef pair< ll,ll > Pll;
typedef pair< pair <int, int> ,int > PI;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

template <class c>
struct rge
{
    c b, e;
};
template <class c>
rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c>
auto dud(c *x) -> decltype(std::cerr << *x, 0);
template <class c>
char dud(...);
struct debug
{
#ifndef ONLINE_JUDGE
    ~debug()
    {
        std::cerr << std::endl;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i)
    {
        std::cerr << std::boolalpha << i;
        return *this;
    }
    template <class c>
    typename std::enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i)
    {
        return *this << range(begin(i), end(i));
    }
    template <class c, class b>
    debug &operator<<(std::pair<b, c> d)
    {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    template <class c>
    debug &operator<<(rge<c> d)
    {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << (char *)", " + 2 * (it == d.b) << *it;
        return *this << "]";
    }
#else
    template <class c>
    debug &operator<<(const c &)
    {
        return *this;
    }
#endif
};
#define imie(X) " [ " << #X ": " << (X) << " ] "

const int mod1=1e5+7;
const int mod2=1e9+7;
const ll mod3=1e12+7;
const int si=1050;
//const int N=1e6+7;
//ios::sync_with_stdio(false);
//priority_queue <int,vector<int>,less<int> > p;  p1>p2
//priority_queue <int,vector<int>,greater<int> > q;  q1<q2
//vector<int>().swap(a);

int n,k,a[si],gcd,now=1,cnt,sta;
bool b[mod2];
int main()
{
    scanf("%d%d",&n,&k);
    scanf("%d",a);
    gcd=a[0];
    for(int i=1;i<n;i++)
    {
        scanf("%d",a+i);
        gcd=__gcd(gcd,a[i]);
    }
    debug()<<imie(gcd);
    for(int i=1;now!=0;i++)
    {
        debug()<<imie(i*gcd);
        now=i*gcd%k;
        debug()<<imie(now);
        if(!b[now])
        {
            b[now]=1;
            cnt++;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<k;i++)
    {
        if(b[i])
        {
            sta=i;
            printf("%d",i);
            break;
        }
    }
    for(int i=sta+1;i<k;i++)
    {
        if(b[i])
            printf(" %d",i);
    }
    printf("\n");
    return 0;
}

/*
10 5
4 6 8 6 4 10 2 10 8 6

*/


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

int gcd(int a, int b){return !b ? a : gcd(b, a % b);}

void work(){
	n = read(), k = read(); int x;
	for(int i = 1; i <= n; i ++){x = read(); b[x % k] = 1;}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		if(tmp == 1){
			printf("%d\n", k);
			for(int j = 0; j < k; j ++) printf("%d ", j);
			puts("");
			return ;
		}
	}
	int flag = 0, minn = 1e9;
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		flag = 1;
		minn = min(minn, tmp);
	}
	if(flag){
		printf("%d\n", k / minn);
		for(int i = 0; i < k; i += minn) printf("%d ", i);
		puts("");
		return ;
	}
	if(b[0]){puts("1"); puts("0");}
	else puts("0");
}

int main(){
	work();
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

int gcd(int a, int b){return !b ? a : gcd(b, a % b);}

void work(){
	n = read(), k = read(); int x, tmp = k;
	for(int i = 1; i <= n; i ++){x = read(); tmp = gcd(tmp, x);}
	printf("%d\n", k / tmp);
	for(int i = 0; i < k; i += tmp) printf("%d ", i); puts("");
}

int main(){
	work();
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

void work(){
	n = read(), k = read(); int x;
	for(int i = 1; i <= n; i ++){x = read(); b[x % k] = 1;}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		if(k % i){
			printf("%d\n", k);
			for(int j = 0; j < k; j ++) printf("%d ", j);
			puts("");
			return ;
		}
	}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		if(k % i == 0){
			printf("%d\n", k / i);
			for(int j = 0; j < k; j += i) printf("%d ", j);
			puts("");
			return ;
		}
	}
	if(b[0]){puts("1"); puts("0");}
}

int main(){
	work();
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

int gcd(int a, int b){return !b ? a : gcd(b, a % b);}

void work(){
	n = read(), k = read(); int x;
	for(int i = 1; i <= n; i ++){x = read(); b[x % k] = 1;}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		if(tmp == 1){
			printf("%d\n", k);
			for(int j = 0; j < k; j ++) printf("%d ", j);
			puts("");
			return ;
		}
	}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		if(tmp != 1){
			printf("%d\n", k / tmp);
			for(int j = 0; j < k; j += tmp) printf("%d ", j);
			puts("");
			return ;
		}
	}
	if(b[0]){puts("1"); puts("0");}
	else puts("0");
}

int main(){
	work();
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

void work(){
	n = read(), k = read(); int x;
	for(int i = 1; i <= n; i ++){x = read(); b[x % k] = 1;}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		if(k % i){
			printf("%d\n", k);
			for(int j = 0; j < k; j ++) printf("%d ", j);
			puts("");
			return ;
		}
	}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		if(k % i == 0){
			printf("%d\n", k / i);
			for(int j = 0; j < k; j += i) printf("%d ", j);
			puts("");
		}
	}
	if(b[0]){puts("1"); puts("0");}
}

int main(){
	work();
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

const int MAXN = 1e5 + 15;

int n, k;
bool b[MAXN];

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

int gcd(int a, int b){return !b ? a : gcd(b, a % b);}

void work(){
	n = read(), k = read(); int x;
	for(int i = 1; i <= n; i ++){x = read(); b[x % k] = 1;}
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		if(tmp == 1){
			printf("%d\n", k);
			for(int j = 0; j < k; j ++) printf("%d ", j);
			puts("");
			return ;
		}
	}
	int flag = 0, minn = 1e9;
	for(int i = 1; i < k; i ++){
		if(!b[i]) continue;
		int tmp = gcd(k, i);
		flag = 1;
		minn = min(minn, tmp);
	}
	if(flag){
		printf("%d\n", n / minn);
		for(int i = 0; i < k; i += minn) printf("%d ", i);
		puts("");
		return ;
	}
	if(b[0]){puts("1"); puts("0");}
	else puts("0");
}

int main(){
	work();
	return 0;
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int gcd(int x,int y){
	while(x%y){
		int z=x%y;
		x%=y;
		y=z;
	}
	return y;
}
int main(){
	int n,k,i,x,y;
	cin>>n>>k;
	y=k;
	for(i=0;i<n;i++){
		scanf("%d",&x);
		x%=k;
		if(x) y=gcd(y,x);
	}
	cout<<k/y<<endl;
	for(i=0;i<k/y;i++) cout<<i*y<<" ";
}


#include <iostream>
#include <algorithm>
using namespace std;
int x[15];
int main(){
	int n,k,i,j,a,ans=0,cnt=0;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k%10]=1;
	}
	int p=min(k,10);
	for(i=0;i<p;i++) if(x[i]) ans++;
	while(cnt!=ans){
		cnt=ans;
		for(i=1;i<p;i++){
			if(x[i]){
				for(j=2;i*j%p!=i;j++){
					x[i*j%p]=1;
				}
			}
		}
		ans=0;
		for(i=0;i<p;i++) if(x[i]) ans++;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
int x[100005];
int main(){
	int n,k,i,j,a,ans=0,cnt=0;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	for(i=0;i<k;i++) if(x[i]) ans++;
	while(cnt!=ans){
		cnt=ans;
		for(i=1;i<k;i++){
			if(x[i]){
				for(j=2;i*j%k!=i;j++){
					x[i*j%k]=1;
				}
			}
		}
		ans=0;
		for(i=0;i<k;i++) if(x[i]) ans++;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
bool x[100005];
int y[100005],z[100005],k;
int ch(int y[],int z[],int ctt){
	int cnt=0;
	for(int i=1;i<ctt;i++){
		for(ll j=2;y[i]*j%k!=y[i];j++){
			if(!x[y[i]*j%k]){
				x[y[i]*j%k]=1;
				z[cnt++]=y[i]*j%k;
			}
		}
	}
	return cnt;
}
int main(){
	int n,a,ans=1,cnt=0,f=0,c=0;
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	x[0]=1;
	cnt=0;
	for(i=1;i<k;i++) if(x[i]) y[cnt++]=i;
	ans+=cnt;
	while(cnt){
		if(x[1]) {
			f=1;
			break;
		}
		if(c&1)cnt=ch(z,y,cnt);
		else cnt=ch(y,z,cnt);
		c++;
		if(x[1]) {
			f=1;
			break;
		}
		ans+=cnt;
	}
	if(f) {
		cout<<k<<endl;
		for(i=0;i<k;i++) printf("%d ",i);
		return 0;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
bool x[100005];
int y[100005],z[100005],k;
int ch(int y[],int z[],int ctt){
	int cnt=0;
	for(int i=1;i<ctt;i++){
		for(ll j=2;y[i]*j%k!=y[i];j++){
			if(!x[y[i]*j%k]){
				x[y[i]*j%k]=1;
				z[cnt++]=y[i]*j%k;
			}
		}
	}
	return cnt;
}
int main(){
	int n,a,ans=1,cnt=0,f=0,c=0;
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	x[0]=1;
	cnt=0;
	for(i=1;i<k;i++) if(x[i]) y[cnt++]=i;
	ans+=cnt;
	while(cnt){
		if(x[1]) {
			f=1;
			break;
		}
		if(c&1)cnt=ch(z,y,cnt);
		else cnt=ch(y,z,cnt);
		if(x[1]) {
			f=1;
			break;
		}
		ans+=cnt;
	}
	if(f) {
		cout<<k<<endl;
		for(i=0;i<k;i++) printf("%d ",i);
		return 0;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int gcd(int x,int y){
	while(x%y){
		int z=x%y;
		x=y;
		y=z;
	}
	return y;
}
int main(){
	int n,k,i,x,y;
	cin>>n>>k;
	y=k;
	for(i=0;i<n;i++){
		scanf("%d",&x);
		x%=k;
		if(x) y=gcd(y,x);
	}
	cout<<k/y<<endl;
	for(i=0;i<k/y;i++) cout<<i*y<<" ";
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int x[100005];
int main(){
	int n,k,a,ans=0,cnt=0,f=0;
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	x[0]=1;
	for(i=0;i<k;i++) if(x[i]) ans++;
	while(cnt!=ans){
		cnt=ans;
		for(i=1;i<k;i++){
			if(x[i]){
				for(j=2;i*j%k!=i;j++){
					x[i*j%k]=1;
				}
			}
		}
		ans=0;
		if(x[1]) {
			f=1;
			break;
		}
		for(i=0;i<k;i++) if(x[i]) ans++;
	}
	if(f) {
		cout<<k<<endl;
		for(i=0;i<k;i++) printf("%d ",i);
		return 0;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
bool x[100005];
int y[100005],z[100005],k;
int ch(int y[],int z[],int ctt){
	int cnt=0;
	for(int i=0;i<ctt;i++){
		for(ll j=2;y[i]*j%k!=y[i];j++){
			if(!x[y[i]*j%k]){
				x[y[i]*j%k]=1;
				z[cnt++]=y[i]*j%k;
			}
		}
	}
	return cnt;
}
int main(){
	int n,a,ans=1,cnt=0,f=0,c=0;
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	x[0]=1;
	cnt=0;
	for(i=1;i<k;i++) if(x[i]) y[cnt++]=i;
	ans+=cnt;
	while(cnt){
		if(x[1]) {
			f=1;
			break;
		}
		if(c&1)cnt=ch(z,y,cnt);
		else cnt=ch(y,z,cnt);
		c++;
		if(x[1]) {
			f=1;
			break;
		}
		ans+=cnt;
	}
	if(f) {
		cout<<k<<endl;
		for(i=0;i<k;i++) printf("%d ",i);
		return 0;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
bool x[100005];
int y[100005];
int main(){
	int n,k,a,ans=1,cnt=0,f=0,ctt;
	ll i,j;
	cin>>n>>k;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x[a%k]=1;
	}
	x[0]=1;
	cnt=0;
	for(i=1;i<k;i++) if(x[i]) y[cnt++]=i;
	ans+=cnt;
	while(cnt){
		ctt=cnt;
		cnt=0;
		if(x[1]) {
			f=1;
			break;
		}
		for(i=0;i<ctt;i++){
			for(j=2;y[i]*j%k!=i;j++){
				if(!x[y[i]*j%k]){
					y[cnt++]=y[i]*j%k;
					x[y[i]*j%k]=1;
				}
			}
		}
		ans+=cnt;
		if(x[1]) {
			f=1;
			break;
		}
	}
	if(f) {
		cout<<k<<endl;
		for(i=0;i<k;i++) printf("%d ",i);
		return 0;
	}
	cout<<ans<<endl;
	for(i=0;i<k;i++){
		if(x[i]) printf("%d ",i);
	}
}


#include <cstdio>
#include <vector>

#define MAXK 100000

using namespace std;

bool aRev[MAXK];

vector<int> factors;
bool dp[MAXK];

int gcd(int n1, int n2) {
  return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
  int n, k; scanf("%d %d\n", &n, &k);
  for(int i = 0; i < n; i++) {
    int ai; scanf("%d", &ai);
    aRev[gcd(ai % k, k)] = true;
  }

  for(int i = 1; i < k; i++) {
    if(!aRev[i]) continue;
    factors.push_back(i);

//    for(int j = i + i; j < k; j += i) {
//      aRev[j] = false;
//    }
  }

  dp[0] = true;
  int cnt = 1;
  for(int fact : factors) {
    bool changed = true;
    while(changed) {
      changed = false;
      for(int i = 0; i < k; i++) {
        if(!dp[i]) continue;
        if(!dp[(i + fact) % k]) {
          dp[(i + fact) % k] = true;
          cnt++;
          changed = true;
        }
      }
    }
  }

  printf("%d\n", cnt);
  for(int i = 0; i < k; i++) {
    if(dp[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 100000
#define MAXK 100000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int a[MAXN];
bool aRev[MAXK];

vector<int> factors;

bool dp[MAXK];

int gcd(int n1, int n2) {
  return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
  int n, k; scanf("%d %d\n", &n, &k);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    aRev[gcd(a[i] % k, k)] = true;
  }

  for(int i = 1; i < k; i++) {
    if(!aRev[i]) continue;
    factors.push_back(i);

    for(int j = i + i; j < k; j += i) {
      aRev[j] = false;
    }
  }

  dp[0] = true;
  for(int fact : factors) {
    for(int i = 0; i + fact < k; i++) {
      if(!dp[i]) continue;
      dp[i + fact] = true;
    }
  }

  int cnt = 0;
  for(int i = 0; i < k; i++) {
    if(dp[i]) cnt++;
  }

  printf("%d\n", cnt);
  for(int i = 0; i < k; i++) {
    if(dp[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 100000
#define MAXK 100000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int a[MAXN];
bool aRev[MAXK];

vector<int> factors;

bool dp[MAXK];

int gcd(int n1, int n2) {
  return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
  int n, k; scanf("%d %d\n", &n, &k);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    aRev[gcd(a[i], k) % k] = true;
  }

  for(int i = 1; i < k; i++) {
    if(!aRev[i]) continue;
    factors.push_back(i);

    for(int j = i + i; j < k; j += i) {
      aRev[j] = false;
    }
  }

  dp[0] = true;
  for(int fact : factors) {
    for(int i = 0; i + fact < k; i++) {
      if(!dp[i]) continue;
      dp[i + fact] = true;
    }
  }

  int cnt = 0;
  for(int i = 0; i < k; i++) {
    if(dp[i]) cnt++;
  }

  printf("%d\n", cnt);
  for(int i = 0; i < k; i++) {
    if(dp[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


#include <cstdio>

#define MAXK 100000

bool dp[MAXK];

int gcd(int n1, int n2) {
  return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
  int n, k; scanf("%d %d\n", &n, &k);

  int aGcd = k;
  for(int i = 0; i < n; i++) {
    int ai; scanf("%d", &ai);
    aGcd = gcd(aGcd, ai);
  }

  dp[0] = true;
  int cnt = 1;
  for(int i = 0; i + aGcd < k; i++) {
    if(!dp[i]) continue;
    if(!dp[i + aGcd]) {
      dp[i + aGcd] = true;
      cnt++;
    }
  }

  printf("%d\n", cnt);
  for(int i = 0; i < k; i++) {
    if(dp[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define MAXN 100000
#define MAXK 100000
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef long double ld;

int a[MAXN];
bool aRev[MAXK];

vector<int> factors;

bool dp[MAXK];

int gcd(int n1, int n2) {
  return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
  int n, k; scanf("%d %d\n", &n, &k);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    aRev[gcd(a[i] % k, k)] = true;
  }

  for(int i = 1; i < k; i++) {
    if(!aRev[i]) continue;
    factors.push_back(i);

    for(int j = i + i; j < k; j += i) {
      aRev[j] = false;
    }
  }

  dp[0] = true;
  int cnt = 1;
  for(int fact : factors) {
    bool changed = true;
    while(changed) {
      changed = false;
      for(int i = 0; i < k; i++) {
        if(!dp[i]) continue;
        if(!dp[(i + fact) % k]) {
          dp[(i + fact) % k] = true;
          cnt++;
          changed = true;
        }
      }
    }
  }

  printf("%d\n", cnt);
  for(int i = 0; i < k; i++) {
    if(dp[i]) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	int k;
	int g;
	cin>>n>>k;
	int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		g=__gcd(a,g);
	}
	cout<<k/g<<endl;
	for (int j=0;j<k;j=j+g)
	{
		cout<<j<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

int n, k, a[100010];
int gcd(int x, int y) {
    if (y == 0)
        return x;
    return gcd(y, x%y);
}
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    scanf("%d %d", &n, &k);

    for (int i = 0; i < n; i++)
        scanf("%d", a+i);

    int g = k;
    for (int i = 0; i < n; i++)
        g = gcd(g, a[i]);

    vector<int> results;
    for (int i = 0; i < k; i++) {
        if (i % g == 0)
            results.push_back(i);
    }
    printf("%d\n", results.size());
    if (results.size() > 0) {
        for (int i = 0; i < results.size() - 1; i++)
            printf("%d ", results[i]);
        printf("%d\n", results.back());
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	int k;
	int g;
	cin>>n>>k;
	g=k;
	int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		g=__gcd(a,g);
	}
	cout<<k/g<<endl;
	for (int j=0;j<k;j=j+g)
	{
		cout<<j<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int gcd(long long int a, int b)
{

    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

int main()
{
	int n;
	int k;
	int g;
	cin>>n>>k;
	long long int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		g=gcd(a,g);
	}
	cout<<k/g<<endl;
	for (int j=0;j<k;j=j+g)
	{
		cout<<j<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int GCD(int x,int y){
   if(x<y)  swap(x,y);
   while((x%=y)&&(y%=x));
   return max(x,y);
}
int a[100010];
int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n,k,ans,x;
   cin>>n>>k;
   ans=k;
   for(int i=1;i<=n;i++){
      cin>>x;
      ans=GCD(ans,x);
   }
   cout<<k/ans<<endl;
   for(int i=0;i*ans<k;i++){
      if(i!=0) cout<<' ';
      cout<<i*ans;
   }
   cout<<endl;

}


#include <bits/stdc++.h>

using namespace std;

#define INTMAX 0x7FFFFFFF
#define INTMIN -0x80000000
#define LONGMAX 0x7FFFFFFFFFFFFFFF
#define LONGMIN -0x8000000000000000

int gcd(int a, int b){
	if(a==0)
		return b;
	return gcd(b%a, a);
}

int main(){
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i] = a[i]%k;
		if(a[i]==0)
			a[i] = k;
	}
	int g = a[0];
	for(int i=1; i<n; i++){
		g = gcd(g, a[i]);
	}

	int gg = gcd(g,k);
	cout << k/gg << endl;
	for(int i=0; i<k/gg; i++){
		cout << i*gg << " ";
	}
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
int gcd(long long int a, long long int b)
{

    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

int main()
{
	int n;
	int k;
	long long int g;
	cin>>n>>k;
	g=k;
	long long int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		g=gcd(a,g);
	}
	cout<<k/g<<endl;
	for (int j=0;j<k;j=j+g)
	{
		cout<<j<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int gcd(long long int a, long long int b)
{

    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

int main()
{
	int n;
	int k;
	long long int g;
	cin>>n>>k;
	long long int a;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		g=gcd(a,g);
	}
	cout<<k/g<<endl;
	for (int j=0;j<k;j=j+g)
	{
		cout<<j<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  memset(h, 0, sizeof(h));
  for (int i = 0; i < n; i++) {
    h[a[i] % k] = true;
  }

  vector<int> idx, nidx;
  for (int i = 0; i < k; i++) {
    if (h[i]) nidx.push_back(i);
  }
  while (!nidx.empty()) {
    vector<int> tmp;
    for (int i = 0; i < nidx.size(); i++) {
      idx.push_back(nidx[i]);
      tmp.push_back(nidx[i]);
    }
    nidx.clear();
    for (int i = 0; i < tmp.size(); i++) {
      for (int j = 0; j < idx.size(); j++) {
        int ni = (tmp[i] + idx[j]) % k;
        if (!h[ni]) {
          h[ni] = true;
          nidx.push_back(ni);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (h[i]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
int h[100100];

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int g = a[0];
  for (int i = 1; i < n; i++) g = gcd(g, a[i]);
  memset(h, 0, sizeof(h));
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (!h[(g * i) % k]) ans++;
    h[(g * i) % k] = true;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100];

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int g = a[0];
  for (int i = 1; i < n; i++) g = gcd(g, a[i]);
  memset(h, 0, sizeof(h));
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (!h[(g * i) % k]) ans++;
    h[(g * i) % k] = true;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  memset(h, 0, sizeof(h));
  for (int i = 0; i < n; i++) {
    h[a[i] % k] = true;
  }

  for (int i = 0; i < k; i++) {
    if (h[i]) continue;
    int m = i - 1, p = 1;
    while (p <= m) {
      if (h[p] && h[m]) {
        h[i] = true;
        break;
      }
      p++; m--;
    }
    if (h[i]) continue;
    m = k - 1, p = i + 1;
    while (p <= m) {
      if (h[p] && h[m]) {
        h[i] = true;
        break;
      }
      p++; m--;
    }
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (h[i]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100];

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int g = a[0];
  for (int i = 1; i < n; i++) g = gcd(g, a[i]);
  memset(h, 0, sizeof(h));
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (!h[(1LL * g * i) % k]) ans++;
    h[(1LL * g * i) % k] = true;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100];

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int g = a[0];
  for (int i = 1; i < n; i++) g = gcd(g, a[i]);
  memset(h, 0, sizeof(h));
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (!h[(g % k * i) % k]) ans++;
    h[(g % k * i) % k] = true;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, k;
int a[100100];
bool h[100100], hc[100100];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  memset(h, 0, sizeof(h));
  for (int i = 0; i < n; i++) {
    h[a[i] % k] = true;
  }

  set<int> nh;
  do {
    nh.clear();
    for (int i = 0; i < k; i++) hc[i] = h[i];
    for (int i = 0; i < k; i++) {
      if (!hc[i]) continue;
      for (int j = i; j < k; j++) {
        if (!hc[j]) continue;
        if (!h[(i + j) % k]) {
          h[(i + j) % k] = true;
          nh.insert((i + j) % k);
        }
      }
    }
  } while (nh.size());

  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (h[i]) ans++;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
int a[100100];
bool h[100100];

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int g = a[0];
  for (int i = 1; i < n; i++) g = gcd(g, a[i]);
  memset(h, 0, sizeof(h));
  int ans = 0;
  for (ll i = 0, s = 0; i < k; i++, s += g) {
    if (!h[s % k]) ans++;
    h[s % k] = true;
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    if (h[i]) printf("%d ", i);
  }
  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <unordered_set>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, k;
set<int> st_g, ans;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    int i, j;
    cin >> n >> k;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        st_g.insert(gcd(t, k));
    }
    int z = *st_g.begin();
    for (set<int>::iterator it = st_g.begin(); it != st_g.end(); it++) {
        z = gcd(z, *it);
    }
    cout << k / z << endl;
    for (i = 0; i * z < k; ++i) {
        cout << i * z << ' ';
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <unordered_set>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, k;
set<int> st_g, ans;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    int i, j;
    cin >> n >> k;
    int z;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (i == 0)
            z = t;
        else
            z = gcd(z, t);
    }
    cout << k / z << endl;
    for (i = 0; i * z < k; ++i) {
        cout << i * z << ' ';
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <unordered_set>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, k;
set<int> st_g, ans;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    int i, j;
    cin >> n >> k;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        st_g.insert(gcd(t, k));
    }
    for (set<int>::iterator it = st_g.begin(); it != st_g.end(); it++) {
        for (i = 0; i * *it != k; ++i)
            ans.insert(i * *it);
    }
    cout << ans.size() << endl;
    for (set<int>::iterator it = ans.begin(); it != ans.end(); it++) {
        cout << *it << ' ';
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <unordered_set>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, k;
set<int> st_g, ans;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    int i, j;
    cin >> n >> k;
    int z;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (i == 0)
            z = t;
        else
            z = gcd(z, t);
    }
    z = gcd(z, k);
    cout << k / z << endl;
    for (i = 0; i * z < k; ++i) {
        cout << i * z << ' ';
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100009

long long i,j,k,l,n,m;

set<long long>res;

int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>l;
        if(i==1)k=l;
        else k=__gcd(k,l);
    }

    l=0;

    for(i=1;i<m;i++){
        res.insert(l%m);
        l+=k;
    }

    cout<<res.size()<<endl;
    for(auto to:res)cout<<to<<' ';
    cout<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100009

long long i,j,k,l,n,m;

set<long long>res;

int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>l;
        if(i==1)k=l;
        else k=__gcd(k,l);
    }

    for(i=1;i<m;i++){
        res.insert(i*k%m);
    }

    cout<<res.size()<<endl;
    for(auto to:res)cout<<to<<' ';
    cout<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100009

long long i,j,k,l,n,m;

set<long long>res;

int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>l;
        if(i==1)k=l;
        else k=__gcd(k,l);
    }

    for(i=1;i<m;i++){
        if(i%k==0)res.insert(i);
    }

    cout<<res.size()<<endl;
    for(auto to:res)cout<<to<<' ';
    cout<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define DIM 100009

long long i,j,k,l,n,m;

set<long long>res;

int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++){
        cin>>l;
        if(i==1)k=l;
        else k=__gcd(k,l);
    }

    l=0;

    for(i=1;i<=m;i++){
        res.insert(l%m);
        l+=k;
    }

    cout<<res.size()<<endl;
    for(auto to:res)cout<<to<<' ';
    cout<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
// #pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            const int maxn = 1e5+9;
            ll a[maxn];
            int n,m;
            int mp[maxn],l[maxn];
            int dp[maxn];
int main(){
            scanf("%d%d", &n, &m);
            int cnt = 0;
            mp[0] = 1;
            for(int i=1; i<=n; i++){
                scanf("%I64d", &a[i]);
                int val = a[i] % m;
                if(mp[val]==0){
                    mp[val] = 1;
                    l[++cnt] = val;
                }
            }
            dp[0] = 1;
            int ans = 1,flag = 1;
            for(int i=1; i<=cnt; i++){
                for(int j=l[i]; j<m; j++){
                    if(dp[j]==1)continue;
                    flag = 1;
                    if(dp[j]==0)flag = 0;
                    dp[j] |= dp[j-l[i]];
                    if(dp[j]==1&&flag==0)ans++;

                }
            }

            printf("%d\n",ans);
            for(int i=0; i<m; i++){
                if(dp[i])printf("%d ",i);
            }
            printf("\n");
            return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
#pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            ll gcd(ll a, ll b){
                if(b==0)return a;
                else return gcd(b,a%b);
            }
            const int maxn = 100009;
            int a[maxn];
            set<int>q;
int main(){
            int n,k;
            scanf("%d%d", &n, &k);
            for(int i=1; i<=n; i++){
                scanf("%d", &a[i]);
            }
            q.insert(0);
            for(int i=1; i<=n; i++){
                int tmp = a[i];
                q.insert(a[i] % k);
                while(tmp<k){
                    tmp+=a[i];
                    q.insert(a[i] % k);
                }
            }
            printf("%d\n",(int)q.size());
            for(int k : q){
                printf("%d ",k);
            }
            printf("\n");

        return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
// #pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            const int maxn = 1e5+9;
            ll a[maxn];
            int n,m;
            int mp[maxn],l[maxn];
            int dp[maxn];
int main(){
            scanf("%d%d", &n, &m);
            int cnt = 0;
            mp[0] = 1;
            for(int i=1; i<=n; i++){
                scanf("%I64d", &a[i]);
                int val = a[i] % m;
                if(mp[val]==0){
                    mp[val] = 1;
                    l[++cnt] = val;
                }
            }
            if(n==100000)cout<<"cnt"<<cnt<<endl;
            dp[0] = 1;
            int ans = 1,flag = 1;
            for(int i=1; i<=cnt; i++){
                for(int j=l[i]; j<m; j++){
                    if(dp[j]==1)continue;
                    flag = 1;
                    if(dp[j]==0)flag = 0;
                    dp[j] |= dp[j-l[i]];
                    if(dp[j]==1&&flag==0)ans++;

                }
            }

            printf("%d\n",ans);
            for(int i=0; i<m; i++){
                if(dp[i])printf("%d ",i);
            }
            printf("\n");
            return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
// #pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            const int maxn = 1e5+9;
            int a[maxn];
            int n,m;

            ll gcd(ll a,ll b){
                if(b==0)return a;
                else return gcd(b,a%b);
            }
int main(){
            scanf("%d%d", &n, &m);
            for(int i=1; i<=n; i++){
                scanf("%d", &a[i]);
            }

            int g = m;
            for(int i=1; i<=n; i++){
                g = gcd(g,a[i]);
            }
            int cnt = m/g;
            printf("%d\n",cnt);
            for(int i=1; i<=cnt; i++){
                printf("%d ",g*(i-1));
            }
            return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
#pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            ll gcd(ll a, ll b){
                if(b==0)return a;
                else return gcd(b,a%b);
            }
            const int maxn = 100009;
            int a[maxn];
            set<int>q;
int main(){
            int n,k;
            scanf("%d%d", &n, &k);
            for(int i=1; i<=n; i++){
                scanf("%d", &a[i]);
            }
            q.insert(0);
            for(int i=1; i<=n; i++){
                q.insert(a[i] % k);
            }
            printf("%d\n",(int)q.size());
            for(int k : q){
                printf("%d ",k);
            }
            printf("\n");

        return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
// #pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            const int maxn = 1e5+9;
            ll a[maxn];
            int n,m;
            int mp[maxn],l[maxn];
            int dp[maxn];
int main(){
            scanf("%d%d", &n, &m);
            int cnt = 0;
            mp[0] = 1;
            for(int i=1; i<=n; i++){
                scanf("%I64d", &a[i]);
                int val = a[i] % m;
                if(mp[val]==0){
                    mp[val] = 1;
                    l[++cnt] = val;
                }
            }
            if(n==100000)debug(cnt);
            dp[0] = 1;
            int ans = 1,flag = 1;
            for(int i=1; i<=cnt; i++){
                for(int j=l[i]; j<m; j++){
                    if(dp[j]==1)continue;
                    flag = 1;
                    if(dp[j]==0)flag = 0;
                    dp[j] |= dp[j-l[i]];
                    if(dp[j]==1&&flag==0)ans++;

                }
            }

            printf("%d\n",ans);
            for(int i=0; i<m; i++){
                if(dp[i])printf("%d ",i);
            }
            printf("\n");
            return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <stack>
// #pragma comment(linker, "/STACK:102400000,102400000")  //c++
using namespace std;

#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;

#define fi first
#define se second

#define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf  = 0x3f3f3f3f;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*----------------------show time----------------------*/
            const int maxn = 1e5+9;
            int a[maxn];
            int n,m;
            int mp[maxn],l[maxn];
            int dp[maxn];
int main(){
            scanf("%d%d", &n, &m);
            int cnt = 0;
            for(int i=1; i<=n; i++){
                scanf("%d", &a[i]);
                int val = a[i] % m;
                if(mp[val]==0){
                    mp[val] = 1;
                    l[++cnt] = val;
                }
            }
            dp[0] = 1;
            int ans = 1,flag = 1;
            for(int i=1; i<=cnt; i++){
                for(int j=l[i]; j<m; j++){
                    flag = 1;
                    if(dp[j]==0)flag = 0;
                    dp[j] |= dp[j-l[i]];
                    if(dp[j]==1&&flag==0)ans++;

                }
            }

            printf("%d\n",ans);
            for(int i=0; i<m; i++){
                if(dp[i])printf("%d ",i);
            }
            printf("\n");
            return 0;
}


#include<iostream>
using namespace std;

int n, k;
int a[100000];

void init()
{ cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) a[i]=a[i]%k;

}

int nwd(int x, int y)
{ int z;
  if (x<y) swap(x,y);
  while (y!=0)
  { z=x%y;
    x=y; y=z;
  }
  return x;
}

bool jestjedynka()
{ for (int i=0; i<n; i++) if (a[i]==1) return true;
  return false;
}

int main()
{ init();
  if (jestjedynka())
    { //cout<<"c1\n";
	  cout<<k<<"\n";
	  for (int i=0; i<k; i++) cout<<i<<" ";
      cout<<"\n";
      return 0;
	}
  if (n==1 && a[0]!=0)
    { //cout<<"c2\n";
	  cout<<k/a[0]<<"\n";
	  for (int i=0; i<k; i=i+a[0]) cout<<i<<" ";
      cout<<"\n";
      return 0;
 	}
  if (n==1 && a[0]==0)
    { //cout<<"c3\n";
	  cout<<"1\n0\n";
      return 0;
 	}
 int d=k;
 for (int i=0; i<n; i++) d=nwd(a[i], d);
 if (d==0) cout<<"1\n0\n";
 else
 {//cout<<"c5\n";
  //cout<<"n = "<<n<<"  d = "<<d<<"\n";
	  cout<<k/d<<"\n";
  for (int i=0; i<k; i=i+d) cout<<i<<" ";
      cout<<"\n";
 }

}


#include<iostream>
using namespace std;

int n, k;
int a[100000];

void init()
{ cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) a[i]=a[i]%k;

}

int nwd(int x, int y)
{ int z;
  if (x<y) swap(x,y);
  while (y!=0)
  { z=x%y;
    x=y; y=z;
  }
  return x;
}

bool jestjedynka()
{ for (int i=0; i<n; i++) if (a[i]==1) return true;
  return false;
}

int main()
{ init();
  if (jestjedynka())
    { //cout<<"c1\n";
	  cout<<k<<"\n";
	  for (int i=0; i<k; i++) cout<<i<<" ";
      cout<<"\n";
      return 0;
	}
/*  if (n==1 && a[0]!=0)
    { //cout<<"c2\n";
	  cout<<k/a[0]<<"\n";
	  for (int i=0; i<k; i=i+a[0]) cout<<i<<" ";
      cout<<"\n";
      return 0;
 	}*/
  if (n==1 && a[0]==0)
    { //cout<<"c3\n";
	  cout<<"1\n0\n";
      return 0;
 	}
 int d=k;
 for (int i=0; i<n; i++) d=nwd(a[i], d);
 if (d==0) cout<<"1\n0\n";
 else
 {//cout<<"c5\n";
  //cout<<"n = "<<n<<"  d = "<<d<<"\n";
	  cout<<k/d<<"\n";
  for (int i=0; i<k; i=i+d) cout<<i<<" ";
      cout<<"\n";
 }

}


#include<iostream>
using namespace std;

int n, k;
int a[100000];

void init()
{ cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) a[i]=a[i]%k;

}

int nwd(int x, int y)
{ int z;
  if (x<y) swap(x,y);
  while (y!=0)
  { z=x%y;
    x=y; y=z;
  }
  return x;
}

bool jestjedynka()
{ for (int i=0; i<n; i++) if (a[i]==1) return true;
  return false;
}

int main()
{ init();
  if (jestjedynka())
    { for (int i=0; i<k; i++) cout<<i<<" ";
      cout<<"\n";
      return 0;
	}
  if (n==1 && a[0]!=0)
    { for (int i=0; i<k; i=i+a[0]) cout<<i<<" ";
      cout<<"\n";
      return 0;
 	}
  if (n==1 && a[0]==0)
    { cout<<"0\n";
      return 0;
 	}
 int d=a[0];
 for (int i=1; i<n; i++) d=nwd(a[i], d);
 if (d==0) cout<<"0\n";
 else
 for (int i=0; i<k; i=i+d) cout<<i<<" ";
      cout<<"\n";
}


#include<iostream>
using namespace std;

int n, k;
int a[100000];

void init()
{ cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) a[i]=a[i]%k;

}

int nwd(int x, int y)
{ int z;
  if (x<y) swap(x,y);
  while (y!=0)
  { z=x%y;
    x=y; y=z;
  }
  return x;
}

bool jestjedynka()
{ for (int i=0; i<n; i++) if (a[i]==1) return true;
  return false;
}

int main()
{ init();
  if (jestjedynka())
    { //cout<<"c1\n";
	  cout<<k<<"\n";
	  for (int i=0; i<k; i++) cout<<i<<" ";
      cout<<"\n";
      return 0;
	}
  if (n==1 && a[0]!=0)
    { //cout<<"c2\n";
	  cout<<k/a[0]<<"\n";
	  for (int i=0; i<k; i=i+a[0]) cout<<i<<" ";
      cout<<"\n";
      return 0;
 	}
  if (n==1 && a[0]==0)
    { //cout<<"c3\n";
	  cout<<"1\n0\n";
      return 0;
 	}
 int d=a[0];
 for (int i=1; i<n; i++) d=nwd(a[i], d);
 if (d==0) cout<<"1\n0\n";
 else
 {//cout<<"c5\n";
  cout<<"n = "<<n<<"  d = "<<d<<"\n";
	  cout<<k/d<<"\n";
  for (int i=0; i<k; i=i+d) cout<<i<<" ";
      cout<<"\n";
 }

}


#include<iostream>
using namespace std;

int n, k;
int a[100000];

void init()
{ cin>>n>>k;
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) a[i]=a[i]%k;

}

int nwd(int x, int y)
{ int z;
  if (x<y) swap(x,y);
  while (y!=0)
  { z=x%y;
    x=y; y=z;
  }
  return x;
}

bool jestjedynka()
{ for (int i=0; i<n; i++) if (a[i]==1) return true;
  return false;
}

int main()
{ init();
  if (jestjedynka())
    { //cout<<"c1\n";
	  cout<<k<<"\n";
	  for (int i=0; i<k; i++) cout<<i<<" ";
      cout<<"\n";
      return 0;
	}
  if (n==1 && a[0]!=0)
    { //cout<<"c2\n";
	  cout<<k/a[0]<<"\n";
	  for (int i=0; i<k; i=i+a[0]) cout<<i<<" ";
      cout<<"\n";
      return 0;
 	}
  if (n==1 && a[0]==0)
    { //cout<<"c3\n";
	  cout<<"1\n0\n";
      return 0;
 	}
 int d=a[0];
 for (int i=1; i<n; i++) d=nwd(a[i], d);
 if (d==0) cout<<"1\n0\n";
 else
 {//cout<<"c5\n";
  //cout<<"n = "<<n<<"  d = "<<d<<"\n";
	  cout<<k/d<<"\n";
  for (int i=0; i<k; i=i+d) cout<<i<<" ";
      cout<<"\n";
 }

}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int gcd(int a,int b){
	if(a==0) return b;
	return gcd(b%a,a);
}
int main(){
	int n;
	ll k;
	cin>>n>>k;
	int x;
	cin>>x;
	int g=x;
	for(int i=1;i<n;i++){
		cin>>x;
		g=gcd(g,x);
	}
	ll tmp=g%k;
	vector<bool> pos(k,0);
	for(ll i=1;i<=k;i++){
		ll y=(tmp*i)%k;
		pos[y]=1;
	}
	int count=0;
	for(int i=0;i<k;i++){
		if(pos[i]) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k;i++){
		if(pos[i]) cout<<i<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int k;
int func(vector<int> & pos,vector<int> & a, int q){
	cout<<q<<endl;
	if(pos[q]!=-1){
		return pos[q];
	}
	else{
		for(int i=0;i<a.size();i++){
			int tmp=(q-a[i])%k;
			tmp=(tmp<0)?tmp+k:tmp;
			if(func(pos,a,tmp)==1){
				pos[q]=1;
				return 1;
			}
		}
		pos[q]=0;
		return 0;
	}
}

int main(){
	int n;
	cin>>n>>k;
	vector<int> pos(k,-1);
	unordered_map<int,int> rem;
	vector<int> a;
	int x;
	for(int i=0;i<n;i++){
		cin>>x;
		x=x%k;
		if(rem.find(x)==rem.end()){
			rem[x]=1;
			pos[x]=1;

			a.pb(x);
		}
	}
	int count=0;
	//cout<<"here"<<endl;
	for(int i=0;i<k;i++){
		if(pos[i]==1){
			for(int j=0;j<a.size();j++){
				int tmp=(i+a[j])%k;
				if(pos[tmp]!=1){
					pos[tmp]=1;
				}
			}
		}
	}
	for(int i=k-1;i>=0;i--){
		//cout<<i<<endl;
		if(pos[i]==1) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k;i++){
		if(pos[i]==1) cout<<i<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
ll k;
int main(){
	int n;
	cin>>n>>k;
	vector<int> pos(k,-1);
	unordered_map<int,int> rem;
	vector<ll> a;
	ll x;
	for(int i=0;i<n;i++){
		cin>>x;
		x=x%k;
		if(rem.find(x)==rem.end()){
			rem[x]=1;
			pos[x]=1;
			a.pb(x);
		}
	}
	int count=0;
	//cout<<"here"<<endl;
	for(ll i=0;i<k;i++){
		if(pos[i]==1){
			for(int j=0;j<a.size();j++){
				ll tmp=(i+a[j])%k;
				if(pos[tmp]!=1){
					pos[tmp]=1;
				}
			}
		}
	}
	for(int i=k-1;i>=0;i--){
		//cout<<i<<endl;
		if(pos[i]==1) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k;i++){
		if(pos[i]==1) cout<<i<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int gcd(int a,int b){
	if(a==0) return b;
	return gcd(b%a,a);
}
int main(){
	int n;
	ll k;
	cin>>n>>k;
	int x;
	cin>>x;
	int g=x;
	for(int i=1;i<n;i++){
		cin>>x;
		g=gcd(g,x);
	}
	ll tmp=g%k;
	vector<bool> pos(k,0);
	for(ll i=1;i<k;i++){
		ll y=(tmp*i)%k;
		pos[y]=1;
	}
	int count=0;
	for(int i=0;i<k;i++){
		if(pos[i]) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k;i++){
		if(pos[i]) cout<<i<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int gcd(int a, int b){
    if(a==0)return b;
    else return gcd(b%a, a);
}

void solution2(){
    int g=0, S=0;
    loop(i,0,N)g=gcd(g,a[i]);

    loop(i,0,K){
        answer.insert(S%K);
        S+=g;
    }

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution1();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int gcd(int a, int b){
    if(a==0)return b;
    else return gcd(b%a, a);
}

void solution2(){
    int g=0, S=0;
    loop(i,0,N)g=gcd(g,a[i]%K);

    loop(i,0,K){
        answer.insert();
        S+=g;
        S%=K;
    }

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution2();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int gcd(int a, int b){
    if(a==0)return b;
    else return gcd(b%a, a);
}

void solution2(){
    int g=0, S=0;
    loop(i,0,N)g=gcd(g,a[i]);

    loop(i,0,K){
        answer.insert(S%K);
        S+=g;
    }

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution2();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution1();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int gcd(int a, int b){
    if(a==0)return b;
    else return gcd(b%a, a);
}

void solution2(){
    int g=0, S=0;
    loop(i,0,N)g=gcd(g,a[i]%K);

    loop(i,0,K){
        answer.insert(S%K);
        S+=g;
    }

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution2();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution1();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <bits/stdc++.h>
#define loop(i, a, n) for(int i=a; i<n; i++)
#define loop_decr(i, a, n) for(int i=n-1; i>=a; i--)
#define ll long long
#define PI 3.14159265
#define debug 0

using namespace std;

int N,K,a[100000+5];
set<int> denominations, answer;
vector<int> mo;

void print(){
    cout<<"print set: ";
    for(int i:denominations){
        cout<<i<<" ";
    }
    cout<<endl;
}

void process(int i, int sum){
    if(i==mo.size()){
        if(debug)cout<<"insert "<<sum<<endl;
        answer.insert(sum%K);
        return;
    }

    int j=0;
    while((mo[i]*j)%K!=0 || j==0){
        if(debug)cout<<mo[i]<<"*"<<j<<"="<<mo[i]*j<<endl;
        process(i+1, sum+mo[i]*j);
        j++;
    }
}

void solution1(){
    loop(i,0,N){
        a[i] = a[i]%K;
        denominations.insert(a[i]);
    }

    set<int>::iterator it=denominations.begin(), it2;

    for(;it!=denominations.end(); it++){
        if(*it==0)continue;
        it2=it;
        it2++;
        for(;it2!=denominations.end(); it2++){
            if(*it2%*it==0){
                it2=denominations.erase(it2);
                it2--;
                //print();
            }
        }
    }

    for(int i:denominations){
        if(i==0)continue;
        mo.push_back(i);
        if(debug)cout<<i<<" ";
    }
    if(debug)cout<<endl;

    process(0,0);

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int gcd(int a, int b){
    if(a==0)return b;
    else return gcd(b%a, a);
}

void solution2(){
    int g=0, S=0;
    loop(i,0,N)g=gcd(g,a[i]%K);

    loop(i,0,K){
        answer.insert(S);
        S+=g;
        S%=K;
    }

    cout<<answer.size()<<endl;
    for(int i:answer){
        cout<<i<<" ";
    }
}

int main()
{
    cin>>N>>K;
    loop(i,0,N)cin>>a[i];
    solution2();
    return 0;
}

/*
Q:

hint:

testcase:
2 8
12 20

5 10
2 3 4 6 8
*/


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

const int maxn=1e5+10;
int a[maxn];

int gcd(int a,int b)
{
    if(a<b) swap(a,b);
    return b?gcd(b,a%b):a;
}

int main()
{
    int n,k,t=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        t=gcd(a[i],t);
    }
    set<int> st;
    for(int i=0,s=0;i<k;i++,s+=t)
        st.insert(s%k);
    printf("%d\n",st.size());
    for(set<int>::iterator iter=st.begin();iter!=st.end();iter++)
        printf("%d ",*iter);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

const int maxn=1e5+10;
int a[maxn];

int gcd(int a,int b)
{
    if(a<b) swap(a,b);
    return b?gcd(b,a%b):a;
}

int main()
{
    int n,k,t=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        t=gcd(a[i],t);
    }
    set<int> st;
    for(int i=0,s=t;i<k;i++,s+=t)
        st.insert(s%k);
    printf("%d\n",st.size());
    for(set<int>::iterator iter=st.begin();iter!=st.end();iter++)
        printf("%d ",*iter);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

const int maxn=1e5+10;
int a[maxn];

int main()
{
    int n,k,t=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        t=__gcd(a[i],t);
    }
    set<int> st;
    for(int i=0,s=t;i<k;i++,s+=t)
        st.insert(s%k);
    printf("%d\n",st.size());
    for(set<int>::iterator iter=st.begin();iter!=st.end();iter++)
        printf("%d ",*iter);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

const int maxn=1e5+10;
int a[maxn];

int gcd(int a,int b)
{
    if(a<b) swap(a,b);
    return b?gcd(b,a%b):a;
}

int main()
{
    int n,k,t=0;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        t=gcd(a[i],t);
    }
    set<int> st;
    for(long long i=0,s=0;i<k;i++,s+=t)
        st.insert(s%k);
    printf("%d\n",st.size());
    for(set<int>::iterator iter=st.begin();iter!=st.end();iter++)
        printf("%d ",*iter);
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;
int n, k;
int num = 0;

void cal(int a, set<int> &cnt)
{
	long long tmp = a;
	while (true) {
		tmp = tmp % k;
		if (cnt.count(tmp)) break;
		else cnt.insert(tmp);
		tmp += a;
	}
}

int main()
{
	scanf("%d %d", &n, &k);
	vector<int> flag(k, false);
	for (int i = 0; i < n; i += 1) {
		int a;
		scanf("%d", &a);
		set<int> cnt;
		cal(a, cnt);
		for (int x : cnt) {
			if (!flag[x]) num += 1;
			flag[x] = true;
		}
		if (num == k) break;
	}

	for (int i = 1; i < k && num < k; i += 1) {
		if (!flag[i]) continue;
		int s = i;
		int p = s;
		while (true) {
			vector<bool> nflag(k, false);
			for (int j = 0; j < k; j += 1) {
				if (flag[s]) {
					int next = (s + i) % k;
					if (!flag[next]) {
						num += 1;
						flag[next] = true;
						nflag[next]= true;
					}
				}
				s = (s + 1) % k;
			}
			s = -1;
			for (int j = p+1; j < p + i; j += 1) {
				if (nflag[j % k]) {
					s = j % k;
					break;
				}
			}
			if (s == -1) break;
			p = s;
		}
	}
	printf("%d\n", num);
	for (int i = 0; i < k; i += 1)
		if (flag[i]) printf("%d ", i);
	printf("\n");
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;
int n, k;
int num = 0;

void cal(int a, set<int> &cnt)
{
	long long tmp = a;
	while (true) {
		tmp = tmp % k;
		if (cnt.count(tmp)) break;
		else cnt.insert(tmp);
		tmp += a;
	}
}

int main()
{
	cin >> n >> k;
	vector<int> flag(k, false);
	for (int i = 0; i < n; i += 1) {
		int a;
		cin >> a;
		set<int> cnt;
		cal(a, cnt);
		for (int x : cnt) {
			if (!flag[x]) num += 1;
			flag[x] = true;
		}
	}

	for (int i = 1; i < k && num < k; i += 1) {
		if (!flag[i]) continue;
		int s = i;
		int p = s;
		while (true) {
			vector<bool> nflag(k, false);
			for (int j = 0; j < k; j += 1) {
				if (flag[s]) {
					int next = (s + i) % k;
					if (!flag[next]) {
						num += 1;
						flag[next] = true;
						nflag[next]= true;
					}
				}
				s = (s + 1) % k;
			}
			s = -1;
			for (int j = p+1; j < p + i; j += 1) {
				if (nflag[j % k]) {
					s = j % k;
					break;
				}
			}
			if (s == -1) break;
			p = s;
		}
	}
	cout << num << endl;
	for (int i = 0; i < k; i += 1)
		if (flag[i]) cout << i << " ";
	cout << endl;
}


#include <iostream>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;
int n, k;
int num = 0;

void cal(int a, set<int> &cnt)
{
	long long tmp = a;
	while (true) {
		tmp = tmp % k;
		if (cnt.count(tmp)) break;
		else cnt.insert(tmp);
		tmp += a;
	}
}

int main()
{
	scanf("%d %d", &n, &k);
	vector<int> flag(k, false);
	for (int i = 0; i < n; i += 1) {
		int a;
		scanf("%d", &a);
		set<int> cnt;
		cal(a, cnt);
		for (int x : cnt) {
			if (!flag[x]) num += 1;
			flag[x] = true;
		}
	}

	for (int i = 1; i < k && num < k; i += 1) {
		if (!flag[i]) continue;
		int s = i;
		int p = s;
		while (true) {
			vector<bool> nflag(k, false);
			for (int j = 0; j < k; j += 1) {
				if (flag[s]) {
					int next = (s + i) % k;
					if (!flag[next]) {
						num += 1;
						flag[next] = true;
						nflag[next]= true;
					}
				}
				s = (s + 1) % k;
			}
			s = -1;
			for (int j = p+1; j < p + i; j += 1) {
				if (nflag[j % k]) {
					s = j % k;
					break;
				}
			}
			if (s == -1) break;
			p = s;
		}
	}
	printf("%d\n", num);
	for (int i = 0; i < k; i += 1)
		if (flag[i]) printf("%d ", i);
	printf("\n");
}


#include <iostream>
#include <vector>
#include <set>
#include <cstdio>

using namespace std;

int gcd(int a, int b)
{
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int g = 0;
	bool first = true;
	for (int i = 0; i < n; i += 1) {
		int a;
		scanf("%d", &a);
		if (first) g = a, first = false;
		else g = gcd(a, g);
	}
	vector<bool> flag(k, false);
	int cnt = 0;
	long long s = g;
    for (int i = 0; i < k; i += 1) {
		s %= k;
		if (!flag[s]) {
			cnt += 1;
			flag[s] = true;
		}
		s += g;
	}
    cout << cnt << endl;
	for (int i = 0; i < k; i += 1)
		if (flag[i]) cout << i << " ";
	cout << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}
	sort(a + 1, a + n + 1);
	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            ans.emplace_back(i % k);
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	sort(every(ans));
	ans.resize(unique(every(ans)) - ans.begin());

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 101010 > st;
vector < int > ans;

int main () {
	cin >> n >> k;

	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    st[a[i]] = 1;
	    st |= (st << a[i]);
	}

	For (i, 0, k) {
	    if (st[i]) {
	        ans.emplace_back(i % k);
	    }
	}
	sort(every(ans));

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    was[a[i] & 1] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && n & 1) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && was[1]) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 5; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[a[i] & 1] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
int gcd;
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[(a[i] & 1)] = 1;
	    gcd = __gcd(gcd, a[i]);
	}

	if (gcd == 1) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	int cur = gcd;
	for (int it = 1; it <= 1e5; it ++) {
	    used[gcd] = 1;
	    gcd += cur;
	    gcd %= k;
	}

	For (i, 0, k - 1) {
        if (used[i])
	        ans.pb(i);
    	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
vector < int > ans;

int main () {
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}
	for (int it = 1; it <= 60; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            ans.emplace_back(i % k);
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	sort(every(ans));
	ans.resize(unique(every(ans)) - ans.begin());

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 8; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB