#include <bits/stdc++.h>
typedef long long ll;
#define get(a) scanf("%lld", &a)
#define repVector(v)  for( auto it = v.begin(); it != v.end(); it++ )
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define FOR(i,a,b) for( ll i = (ll)(a); i <= (ll)(b); i++ )
#define ROF(i,a,b) for( ll i = (ll)(a); i >= (ll)(b); i-- )
#define debug(x) cerr << "[DEBUG] " << #x << " = " << x << endl
#define matrix vector< vector<ll> >
#define F first
#define S second
#define mp make_pair
#define INPFILE freopen("input.in","r",stdin)
#define BOOST ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

ll v[505];

bool dp[501][501][501];
bool visit[501][501][501];

bool rec( ll x, ll sub, ll sum ) {

  if( x == 0 && sub == 0 && sum == 0 )
    return 1;
  if( x <= 0 || sub > sum )
    return 0;

  if( visit[x][sub][sum] )
    return dp[x][sub][sum];

  bool ret = 0;

  FOR(i,0,x-1) {
    if( sub-v[x] >= 0 && sum-v[x] >= 0 )
      ret |= rec( i, sub-v[x], sum-v[x] );
    if( sum-v[x] >= 0 )
      ret |= rec( i, sub, sum-v[x] );
    ret |= rec( i, sub, sum );
  }

  visit[x][sub][sum] = 1;
  return dp[x][sub][sum] = ret;
}

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

  FOR(i,1,n) cin >> v[i];

  vector<ll> ans;

  FOR(i,0,500) {
    bool flag = 0;
    FOR(j,1,n)
      if( rec( j, i, k ) )
        { flag = 1; break; }
    if(flag)
      ans.pb(i);
  }

  cout << ans.size() << '\n';
  for( ll x : ans ) cout << x << ' ';
}


#include <bits/stdc++.h>
typedef int ll;
#define get(a) scanf("%lld", &a)
#define repVector(v)  for( auto it = v.begin(); it != v.end(); it++ )
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define FOR(i,a,b) for( ll i = (ll)(a); i <= (ll)(b); i++ )
#define ROF(i,a,b) for( ll i = (ll)(a); i >= (ll)(b); i-- )
#define debug(x) cerr << "[DEBUG] " << #x << " = " << x << endl
#define matrix vector< vector<ll> >
#define F first
#define S second
#define mp make_pair
#define INPFILE freopen("input.in","r",stdin)
#define BOOST ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

ll v[505];

bool dp[501][501][501];
bool visit[501][501][501];

bool rec( ll x, ll sub, ll sum ) {

  if( x == 0 && sub == 0 && sum == 0 )
    return 1;
  if( x <= 0 || sub > sum )
    return 0;

  if( visit[x][sub][sum] )
    return dp[x][sub][sum];

  bool ret = 0;

  if( sub-v[x] >= 0 && sum-v[x] >= 0 )
    ret |= rec( x-1, sub-v[x], sum-v[x] );
  if( !ret && sum-v[x] >= 0 )
    ret |= rec( x-1, sub, sum-v[x] );
  if( !ret )
    ret |= rec( x-1, sub, sum );

  visit[x][sub][sum] = 1;
  return dp[x][sub][sum] = ret;
}

int main() {
  BOOST;

  ll n, k;
  cin >> n >> k;

  FOR(i,1,n) cin >> v[i];

  vector<ll> ans;

  FOR(i,0,k)
    if( rec( n, i, k ) )
      ans.pb(i);

  cout << ans.size() << '\n';
  for( ll x : ans ) cout << x << ' ';
}


#include <bits/stdc++.h>
typedef long long ll;
#define get(a) scanf("%lld", &a)
#define repVector(v)  for( auto it = v.begin(); it != v.end(); it++ )
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define FOR(i,a,b) for( ll i = (ll)(a); i <= (ll)(b); i++ )
#define ROF(i,a,b) for( ll i = (ll)(a); i >= (ll)(b); i-- )
#define debug(x) cerr << "[DEBUG] " << #x << " = " << x << endl
#define matrix vector< vector<ll> >
#define F first
#define S second
#define mp make_pair
#define INPFILE freopen("input.in","r",stdin)
#define BOOST ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

ll v[505];

bool dp[501][501][501];
bool visit[501][501][501];

bool rec( ll x, ll sub, ll sum ) {

  if( x == 0 && sub == 0 && sum == 0 )
    return 1;
  if( x <= 0 || sub > sum )
    return 0;

  if( visit[x][sub][sum] )
    return dp[x][sub][sum];

  bool ret = 0;

  FOR(i,0,x-1) {
    if( sub-v[x] >= 0 && sum-v[x] >= 0 )
      ret |= rec( i, sub-v[x], sum-v[x] );
    if( sum-v[x] >= 0 )
      ret |= rec( i, sub, sum-v[x] );
    ret |= rec( i, sub, sum );
  }

  visit[x][sub][sum] = 1;
  return dp[x][sub][sum] = ret;
}

int main() {
  BOOST;

  ll n, k;
  cin >> n >> k;

  FOR(i,1,n) cin >> v[i];

  vector<ll> ans;

  FOR(i,0,k)
    if( rec( n, i, k ) )
      ans.pb(i);

  cout << ans.size() << '\n';
  for( ll x : ans ) cout << x << ' ';
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=1067;
bool check[N],f[N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    check[0]=true;
    For(i,1,n) Ford(j,k,0) if(check[j]) {
        check[j+a[i]]=true;
        f[i][j]=true;
    }
    For(i,0,k-1) check[i]=false;
    check[k]=true;
    Ford(i,n,1) For(j,0,k) if (check[j]&&f[i][j-a[i]]) {
        check[j-a[i]]=true;
        check[k-j]=true;
        Ford(h,i-1,1) {
            if (f[h][j-a[i]-a[h]]) f[h][j-a[h]]=true;
        }
    }
    For(j,0,k) if (check[j]) check[k-j]=true;
    For(i,0,k) if (check[i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) Ford(j,k,0) For(h,j,0) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) For(j,0,k) For(h,0,j) if (f[i-1][j][h]) f[i][min(k+1,j+a[i])][min(k+1,h+a[i])]=true,
    f[i][j][h]=true,f[i][min(k+1,j+a[i])][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) Ford(j,0,k) Ford(h,0,j) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) Ford(j,k,0) Ford(h,j,0) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=1067;
bool check[N],f[N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    check[0]=true;
    For(i,1,n) Ford(j,k,0) if(check[j]) {
        check[j+a[i]]=true;
        f[i][j]=true;
    }
    For(i,0,k-1) check[i]=false;
    check[k]=true;
    Ford(i,n,1) For(j,0,k) if (check[j]&&f[i][j-a[i]]) {
        check[j-a[i]]=true;
        check[k-j+a[i]]=true;
        Ford(h,i-1,1) {
            if (f[h][j-a[i]-a[h]]) f[h][j-a[h]]=true;
        }
    }
    For(i,0,k) if (check[i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=1067;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) For(j,0,k) For(h,0,j) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) For(j,0,k-a[i]) For(h,0,j) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define dream_hyojooslh

using namespace std;
const int N=567;
bool check[N],f[N][N][N];

int n,k;
int a[N],nnn,mmm[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("dream_hyojooslh.inp","r",stdin);
    cin>>n>>k;
    For(i,1,n) {
        cin>>a[i];
    }
    f[0][0][0]=true;
    For(i,1,n) For(j,0,k) For(h,0,j) if (f[i-1][j][h]) f[i][j+a[i]][h+a[i]]=true,f[i][j][h]=true,f[i][j+a[i]][h]=true;
    //For(i,0,k) if (check[i]) check[k-i]=true;
    For(i,0,k) if (f[n][k][i]) {
        ++nnn;
        mmm[nnn]=i;
    }
    cout<<nnn<<endl;
    For(i,1,nnn) cout<<mmm[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=505;
bool dp[2][N][N];
int main(){

	int n,k,x;
	bool dp[2][N][N];

	cin>>n>>k;
	dp[1][0][0]=true;
	for(int i=0;i<n;i++){
		int now =i%2;
		int last=1-now;
		cin>>x;
		for(int j=0;j<=k;j++){
			for(int y=0;y<=j;y++){
				dp[now][j][y]=dp[last][j][y];
				if(j>=x){
					dp[now][j][y]|=dp[last][j-x][y];
					if(x<=y){
						dp[now][j][y]|=dp[last][j-x][y-x];
					}
				}
			}
		}
	}
	int now=(n-1)%2,count=0;
	for(int i=0;i<n;i++){
		if(dp[now][k][i]) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k+1;i++){
		if(dp[now][k][i]) cout<<i<<" ";
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef int ll;
int gcd(ll a,ll b){
   return __gcd(b,a);
}
int lcm(ll a ,ll b){
	return a*1ll*b/gcd(a,b);
}
int main(){
	int n,k,temp=1;
	cin>>n>>k;
	int x;
	for(int i=0;i<n;i++){
		cin>>x;
		temp=gcd(lcm(x,temp),k);
		//if(temp==k) {cout<<"YES";return 0;}
	}
	if(temp==k) cout<<"YES";
	else cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
const int N=505;
bool dp[2][N][N];
int main(){

	int n,k,x;
	bool dp[2][N][N];

	cin>>n>>k;
	dp[1][0][0]=true;
	for(int i=0;i<n;i++){
		int now =i%2;
		int last=1-now;
		cin>>x;
		for(int j=0;j<=k;j++){
			for(int y=0;y<=j;y++){
				dp[now][j][y]=dp[last][j][y];
				if(j>=x){
					dp[now][j][y]|=dp[last][j-x][y];
					if(x<=y){
						dp[now][j][y]|=dp[last][j-x][y-x];
					}
				}
			}
		}
	}
	int now=(n-1)%2,count=0;
	for(int i=0;i<k+1;i++){
		if(dp[now][k][i]) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<k+1;i++){
		if(dp[now][k][i]) cout<<i<<" ";
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N=505;
bool dp[2][N][N];
int main(){
	int n,k,x;
	bool dp[2][N][N];
	cin>>n>>k;
	dp[1][0][0]=true;
	for(int i=0;i<n;i++){
		int now =i%2;
		int last=1-now;
		cin>>x;
		for(int j=0;j<=k;j++){
			for(int y=0;y<=j;y++){
				dp[now][j][y]=dp[last][j][y];
				if(j>=x){
					dp[now][j][y]|=dp[last][j-x][y];
					if(x<=y){
						dp[now][j][y]|=dp[last][j-x][y-x];
					}
				}
			}
		}
	}
	int now=(n-1)%2,count=0;
	for(int i=0;i<N;i++){
		if(dp[now][k][i]) count++;
	}
	cout<<count<<endl;
	for(int i=0;i<N;i++){
		if(dp[now][k][i]) cout<<i<<" ";
	}
}


#include<bits/stdc++.h>
using namespace std;
class Graph{
	int V;
	list<int> *adj;
	list<int> A,B;
public:
	Graph(int V){
		this->V=V;
		adj=new list<int>[V];
	}
	void addEdge(int source,int dest){
		adj[source-1].push_back(dest-1);
	}
	int find(int parent[],int rank[],int i){
	//path compression
		if(parent[i]==-1) return i;
		else{
			parent[i]=find(parent,rank,parent[i]);
		}
	}
	void Union(int parent[],int rank[],int x,int y){
		if(rank[x]>rank[y]) parent[y]=x;
		else if(rank[y]>rank[x]) parent[x]=y;
		else{
			parent[x]=y;
			rank[y]++;
		}
	}
	bool isCyclic(){
		int parent[V],rank[V];
		memset(parent,-1,sizeof(parent));
		memset(rank,0,sizeof(rank));
		for(int u=0;u<V;u++){
			list<int>::iterator v;
			for(v=adj[u].begin();v!=adj[u].end();v++){
				int x=find(parent,rank,u);
				int y=find(parent,rank,*v);
				if(x==y){
					// for(int i=0;i<V;i++){
					// 	//cout<<parent[i]<<" ";
					// }
					//cout<<endl;
					if((2*rank[x]-rank[u]-rank[*v])%2==1)return true;
				}
				Union(parent,rank,x,y);
			}
		}
		return false;
	}
	void DFSUtil(int source,bool visited[],int distance[]){
		//cout<<source<<" ";
		list<int>::iterator i;
		for(i=adj[source].begin();i!=adj[source].end();i++){
			if(!visited[*i]){
				visited[*i]=true;
				distance[*i]=distance[source]+1;
				if(distance[*i]%2==0) A.push_back(*i);
				else B.push_back(*i);
				DFSUtil(*i,visited,distance);

			}
		}
	}
	void DFS(){
		int *distance=new int[V];
		bool *visited=new bool[V];

		for(int i=0;i<V;i++){
			visited[i]=false;
			distance[i]=0;
		}
		// visited[source]=true;

		// DFSUtil(source,visited);
		//for a non-connected graph-

		for(int j=0;j<V;j++){
			if(distance[j]==0 && !adj[j].empty()) A.push_back(j);
			DFSUtil(j,visited,distance);
		}
		 cout<<A.size()<<endl;
    for(auto it=A.begin();it!=A.end();it++){
    	cout<<*it+1<<" ";
    }
    cout<<endl;
    cout<<B.size()<<endl;
   for(auto it=B.begin();it!=B.end();it++){
    	cout<<*it+1<<" ";
    }

	}
	int BFS(int s,int dest)
{
    // Mark all the vertices as not visited
    int *distance=new int[V];
    bool *visited = new bool[V];
    for(int i = 0; i < V; i++){
        visited[i] = false;
        distance[i] = 0;
    }
    //int distance=0;
    // Create a queue for BFS
    list<int> queue;
 	list<int> A,B;
    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);

    // 'i' will be used to get all adjacent vertices of a vertex
    list<int>::iterator i;

    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print it
        s = queue.front();
        // cout << s << " ";
        queue.pop_front();
        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
                visited[*i] = true;
                distance[*i]=distance[s]+1;
                if(*i==dest){ return distance[*i];}
                queue.push_back(*i);

                if(distance[*i]%2==0) A.push_back(*i);
                else B.push_back(*i);
            }
        }
        //distance++;

    }

}
};
// Driver program to test above functions
int main()
{
	int V,E;
	cin>>V>>E;
    Graph g(V);
    for(int i=0;i<E;i++){
    	int x,y;
    	cin>>x>>y;
    	g.addEdge(x,y);
    }
    // g1.addEdge(1, 0);
    // g1.addEdge(0, 2);
    // g1.addEdge(2, 0);
    // g1.addEdge(0, 3);
    // g1.addEdge(3, 4);
    // g1.isCyclic()? cout << "Graph contains cycle\n":
    //             cout << "Graph doesn't contain cycle\n";

    // Graph g2(3);
    // g2.addEdge(0, 1);
    // g2.addEdge(1, 2);
    // // g2.addEdge(0, 2);
    // g2.isCyclic()? cout << "Graph contains cycle\n":
    //             cout << "Graph doesn't contain cycle\n";
    if(g.isCyclic()) {
    cout<<-1;//fuck
}
	else g.DFS();
	int x;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define PF           printf
#define SF(n)        scanf("%d", &n)
#define SFF(a,b)     scanf("%d %d", &a, &b)
#define SFFF(a,b,c)  scanf("%d %d %d", &a, &b, &c)
#define INF_I        2147483647    //max limit
#define INF          1999999999
#define PB           push_back
#define MEM(n, val)  memset((n), val, sizeof(n))
#define F            first
#define S            second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ALL(c)       c.begin(), c.end()
#define BOOST        std::ios_base::sync_with_stdio(false);
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define MP           make_pair
#define INIT_RAND    srand(time(NULL))
#define MOD          1000007
#define MX           (100010)
#define PI           acos(-1.0)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef priority_queue<int> PQ;
typedef queue<int> Q;
typedef stringstream SS;

/*dir array
//8 moves
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
//4 moves
int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
*/
int n, k;
int ara[510];

bool vis[600][600];
bool dp[600][600];

bool func(int pos, int make)  {
    //cout << "pos : " << pos << "\n";
    if(make == k)   {
        //cout << "hi\n";
        return dp[pos][make] = 1;
    }
    if(pos == n) {
        return dp[pos][make] = 0;
    }
    if(vis[pos][make]) {
        return dp[pos][make];
    }
    bool ans = 0;
    ans = ans | func(pos + 1, make);//na niye
    if((make + ara[pos]) <= k)   {
        ans = ans | func(pos + 1, make + ara[pos]);//niye
    }
    vis[pos][make] = 1;
    return dp[pos][make] = ans;
}

int chk[600];

int vromon[600][600];
vector<int> cop;

void pung(int pos, int make)  {
    chk[make] = 1;
    if(pos == cop.size()) {
        return;
    }
    if(vromon[pos][make]) {
        return;
    }
    pung(pos + 1, make);//na niye
    if((make + ara[pos]) <= k)   {
        pung(pos + 1, make + cop[pos]);//niye
    }
    vromon[pos][make] = 1;
}

int koi;
void bt(int pos, int make, vector<int> cc)  {
    //chk[make] = 1;
    //cout << "make : " << make << "\n";
    if(make == k)   {
        cop = cc;
        MEM(vromon, 0);
        pung(0, 0);
        koi++;
        /*
        cout << "hi " << cc.size() << "\n";
        FOR(i, 0, (int)(cc.size() - 1)) {
            cout << cc[i] << " ";
        }
        cout << "\n";
        */
        return;
    }
    if(dp[pos + 1][make])   {
        bt(pos + 1, make, cc);
    }
    if((make + ara[pos]) <= k)   {
        if(dp[pos + 1][make + ara[pos]])   {
            //cout << "ara : " << ara[pos] << "\n";
            cc.PB(ara[pos]);
            bt(pos + 1, make + ara[pos], cc);
        }
    }
}

int sec[510];

int main()  {
    //BOOST;
    int nn;
    cin >> nn >> k;
    FOR(i, 0, nn - 1)   {
        int tmp;cin >> tmp;
        sec[tmp]++;
    }
    FOR(i, 0, 500)   {
        if((sec[i]) && (sec[i] > (k / i)))    {
            sec[i] = (k / i);
        }
    }
    n = 0;
    FOR(i, 0, 500)   {
        FOR(j, 0, sec[i] - 1)   {
            ara[n] = i;
            n++;
        }
    }
    /*
    FOR(i, 0, n - 1)   {
        cout << ara[i] << " ";
    }
    cout << "\n";
    */
    func(0, 0);
    koi = 0;
    vector<int> tmp;
    bt(0, 0, tmp);
    //cout << koi << "\n";

    FOR(i, 0, 500)   {
        if(chk[i])  {
            cout << i << " ";
        }
    }

	return 0;
}
/*
6 18
5 6 1 10 12 2

160 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


#include<bits/stdc++.h>

using namespace std;

#define PF           printf
#define SF(n)        scanf("%d", &n)
#define SFF(a,b)     scanf("%d %d", &a, &b)
#define SFFF(a,b,c)  scanf("%d %d %d", &a, &b, &c)
#define INF_I        2147483647    //max limit
#define INF          1999999999
#define PB           push_back
#define MEM(n, val)  memset((n), val, sizeof(n))
#define F            first
#define S            second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ALL(c)       c.begin(), c.end()
#define BOOST        std::ios_base::sync_with_stdio(false);
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define MP           make_pair
#define INIT_RAND    srand(time(NULL))
#define MOD          1000007
#define MX           (100010)
#define PI           acos(-1.0)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef priority_queue<int> PQ;
typedef queue<int> Q;
typedef stringstream SS;

/*dir array
//8 moves
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
//4 moves
int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
*/
int n, k;
int ara[510];

bool vis[510][510][510];
//bool dp[600][600];
int chk[510];

void func(int pos, int make, int make2)  {
    //cout << "pos : " << pos << "\n";
    if(make == k)   {
        chk[make2] = 1;
        //cout << "hi\n";
        return;
    }
    if(pos == n) {
        return;
    }
    if(vis[pos][make][make2]) {
        return;
    }
    bool ans = 0;
    func(pos + 1, make, make2);//na niye
    if((make + ara[pos]) <= k)   {//niye
        func(pos + 1, make + ara[pos], make2 + ara[pos]);
        func(pos + 1, make + ara[pos], make2);
    }
    vis[pos][make][make2] = 1;
    return;
}

int sec[510];

int main()  {
    BOOST;
    int nn;
    cin >> n >> k;
    FOR(i, 0, n - 1)   {
        cin >> ara[i];
    }
    func(0, 0, 0);
    int ans = 0;
    FOR(i, 0, 500)   {
        if(chk[i])  {
            ans++;
        }
    }
    cout << ans << "\n";

    FOR(i, 0, 500)   {
        if(chk[i])  {
            cout << i << " ";
        }
    }

	return 0;
}
/*
6 18
5 6 1 10 12 2

160 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


#include<bits/stdc++.h>

using namespace std;

#define PF           printf
#define SF(n)        scanf("%d", &n)
#define SFF(a,b)     scanf("%d %d", &a, &b)
#define SFFF(a,b,c)  scanf("%d %d %d", &a, &b, &c)
#define INF_I        2147483647    //max limit
#define INF          1999999999
#define PB           push_back
#define MEM(n, val)  memset((n), val, sizeof(n))
#define F            first
#define S            second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ALL(c)       c.begin(), c.end()
#define BOOST        std::ios_base::sync_with_stdio(false);
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define MP           make_pair
#define INIT_RAND    srand(time(NULL))
#define MOD          1000007
#define MX           (100010)
#define PI           acos(-1.0)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef priority_queue<int> PQ;
typedef queue<int> Q;
typedef stringstream SS;

/*dir array
//8 moves
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
//4 moves
int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
*/
int n, k;
int ara[510];

bool vis[600][600];
bool dp[600][600];

bool func(int pos, int make)  {
    //cout << "pos : " << pos << "\n";
    if(make == k)   {
        //cout << "hi\n";
        return dp[pos][make] = 1;
    }
    if(pos == n) {
        return dp[pos][make] = 0;
    }
    if(vis[pos][make]) {
        return dp[pos][make];
    }
    bool ans = 0;
    ans = ans | func(pos + 1, make);//na niye
    if((make + ara[pos]) <= k)   {
        ans = ans | func(pos + 1, make + ara[pos]);//niye
    }
    vis[pos][make] = 1;
    return dp[pos][make] = ans;
}

int chk[600];

int vromon[600][600];
vector<int> cop;

void pung(int pos, int make)  {
    chk[make] = 1;
    if(pos == cop.size()) {
        return;
    }
    if(vromon[pos][make]) {
        return;
    }
    pung(pos + 1, make);//na niye
    if((make + ara[pos]) <= k)   {
        pung(pos + 1, make + cop[pos]);//niye
    }
    vromon[pos][make] = 1;
}

int koi;
void bt(int pos, int make, vector<int> cc)  {
    //chk[make] = 1;
    //cout << "make : " << make << "\n";
    if(make == k)   {
        cop = cc;
        MEM(vromon, 0);
        pung(0, 0);
        koi++;
        /*
        cout << "hi " << cc.size() << "\n";
        FOR(i, 0, (int)(cc.size() - 1)) {
            cout << cc[i] << " ";
        }
        cout << "\n";
        */
        return;
    }
    if(dp[pos + 1][make])   {
        bt(pos + 1, make, cc);
    }
    if((make + ara[pos]) <= k)   {
        if(dp[pos + 1][make + ara[pos]])   {
            //cout << "ara : " << ara[pos] << "\n";
            cc.PB(ara[pos]);
            bt(pos + 1, make + ara[pos], cc);
        }
    }
}

int sec[510];

int main()  {
    //BOOST;
    int nn;
    cin >> nn >> k;
    FOR(i, 0, nn - 1)   {
        int tmp;cin >> tmp;
        sec[tmp]++;
    }
    FOR(i, 0, 500)   {
        if((sec[i]) && (sec[i] > (k / i)))    {
            sec[i] = (k / i);
        }
    }
    n = 0;
    FOR(i, 0, 500)   {
        FOR(j, 0, sec[i] - 1)   {
            ara[n] = i;
            n++;
        }
    }
    /*
    FOR(i, 0, n - 1)   {
        cout << ara[i] << " ";
    }
    cout << "\n";
    */
    func(0, 0);
    koi = 0;
    vector<int> tmp;
    bt(0, 0, tmp);
    //cout << koi << "\n";
    int ans = 0;
    FOR(i, 0, 500)   {
        if(chk[i])  {
            ans++;
        }
    }
    cout << ans << "\n";

    FOR(i, 0, 500)   {
        if(chk[i])  {
            cout << i << " ";
        }
    }

	return 0;
}
/*
6 18
5 6 1 10 12 2

160 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


#include<bits/stdc++.h>

using namespace std;

#define PF           printf
#define SF(n)        scanf("%d", &n)
#define SFF(a,b)     scanf("%d %d", &a, &b)
#define SFFF(a,b,c)  scanf("%d %d %d", &a, &b, &c)
#define INF_I        2147483647    //max limit
#define INF          1999999999
#define PB           push_back
#define MEM(n, val)  memset((n), val, sizeof(n))
#define F            first
#define S            second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ALL(c)       c.begin(), c.end()
#define BOOST        std::ios_base::sync_with_stdio(false);
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define MP           make_pair
#define INIT_RAND    srand(time(NULL))
#define MOD          1000007
#define MX           (100010)
#define PI           acos(-1.0)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef priority_queue<int> PQ;
typedef queue<int> Q;
typedef stringstream SS;

/*dir array
//8 moves
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
//4 moves
int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
*/
int n, k;
int ara[510];

bool vis[510][510][510];
//bool dp[600][600];
int chk[510];

void func(int pos, int make, int make2)  {
    //cout << "pos : " << pos << "\n";
    if(make == k)   {
        chk[make2] = 1;
        //cout << "hi\n";
        return;
    }
    if(pos == n) {
        return;
    }
    if(vis[pos][make][make2]) {
        return;
    }
    bool ans = 0;
    func(pos + 1, make, make2);//na niye
    if((make + ara[pos]) <= k)   {//niye
        func(pos + 1, make + ara[pos], make2 + ara[pos]);
        func(pos + 1, make + ara[pos], make2);
    }
    vis[pos][make][make2] = 1;
    return;
}

int sec[510];

int main()  {
    //BOOST;
    int nn;
    cin >> nn >> k;
    FOR(i, 0, nn - 1)   {
        int tmp;cin >> tmp;
        sec[tmp]++;
    }
    FOR(i, 0, 500)   {
        if((sec[i]) && (sec[i] > (k / i)))    {
            sec[i] = (k / i);
        }
    }
    n = 0;
    FOR(i, 0, 500)   {
        FOR(j, 0, sec[i] - 1)   {
            ara[n] = i;
            n++;
        }
    }
    /*
    FOR(i, 0, n - 1)   {
        cout << ara[i] << " ";
    }
    cout << "\n";
    */
    func(0, 0, 0);
    int ans = 0;
    FOR(i, 0, 500)   {
        if(chk[i])  {
            ans++;
        }
    }
    cout << ans << "\n";

    FOR(i, 0, 500)   {
        if(chk[i])  {
            cout << i << " ";
        }
    }

	return 0;
}
/*
6 18
5 6 1 10 12 2

160 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


#include<bits/stdc++.h>

using namespace std;

#define PF           printf
#define SF(n)        scanf("%d", &n)
#define SFF(a,b)     scanf("%d %d", &a, &b)
#define SFFF(a,b,c)  scanf("%d %d %d", &a, &b, &c)
#define INF_I        2147483647    //max limit
#define INF          1999999999
#define PB           push_back
#define MEM(n, val)  memset((n), val, sizeof(n))
#define F            first
#define S            second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ALL(c)       c.begin(), c.end()
#define BOOST        std::ios_base::sync_with_stdio(false);
#define INP          freopen("in.txt", "r", stdin);
#define OUT          freopen("out.txt", "w", stdout);
#define MP           make_pair
#define INIT_RAND    srand(time(NULL))
#define MOD          1000007
#define MX           (100010)
#define PI           acos(-1.0)

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef priority_queue<int> PQ;
typedef queue<int> Q;
typedef stringstream SS;

/*dir array
//8 moves
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
//4 moves
int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
*/
int n, k;
int ara[510];

bool vis[510][510][510];
//bool dp[600][600];
int chk[510];

void func(int pos, int make, int make2)  {
    //cout << "pos : " << pos << "\n";
    if(make == k)   {
        chk[make2] = 1;
        //cout << "hi\n";
        return;
    }
    if(pos == n) {
        return;
    }
    if(vis[pos][make][make2]) {
        return;
    }
    bool ans = 0;
    func(pos + 1, make, make2);//na niye
    if((make + ara[pos]) <= k)   {//niye
        func(pos + 1, make + ara[pos], make2 + ara[pos]);
        func(pos + 1, make + ara[pos], make2);
    }
    vis[pos][make][make2] = 1;
    return;
}

int sec[510];

int main()  {
    BOOST;
    int nn;
    cin >> nn >> k;
    FOR(i, 0, nn - 1)   {
        int tmp;cin >> tmp;
        sec[tmp]++;
    }
    FOR(i, 0, 500)   {
        if((sec[i]) && (sec[i] > (k / i)))    {
            sec[i] = (k / i);
        }
    }
    n = 0;
    FOR(i, 0, 500)   {
        FOR(j, 0, sec[i] - 1)   {
            ara[n] = i;
            n++;
        }
    }
    /*
    FOR(i, 0, n - 1)   {
        cout << ara[i] << " ";
    }
    cout << "\n";
    */
    func(0, 0, 0);
    int ans = 0;
    FOR(i, 0, 500)   {
        if(chk[i])  {
            ans++;
        }
    }
    cout << ans << "\n";

    FOR(i, 0, 500)   {
        if(chk[i])  {
            cout << i << " ";
        }
    }

	return 0;
}
/*
6 18
5 6 1 10 12 2

160 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 2;

int n, k, a[N];
vector<int> rs;
bool F[N][N][N];

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    rs.push_back(0);
    memset(F, false, sizeof (F));
}

bool DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return true;
    if (i > n || t > k || (t == k && c_sum != 0)) return false;

    if (F[i][t][c_sum]) return true;

    bool res = false;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        bool res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    cout << rs.size() << '\n';
    for (int i : rs) cout << i << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 5;

int n, k, a[N];
vector<int> rs;
bool F[N][N][N];

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    rs.push_back(0);
}

void Solve()
{
    for (int i = 1; i <= n + 1; i++)
        F[i][k][0] = 1;

    for (int i = n; i >= 1; i--)
    {
        for (int t = k; t >= 0; t--)
        {
            for (int j = 0; j <= k; j++)
                F[i][t][j] = F[i + 1][t + a[i]][j] | F[i + 1][t][j];

            for (int j = 0; j <= k; j++)
            {
                if (j - a[i] >= 0 && t + a[i] <= k)
                    F[i][t][j] |= F[i + 1][t + a[i]][j - a[i]];
            }
        }
    }

    for (int s = 1; s <= k; s++)
        if (F[1][0][s]) rs.push_back(s);

    cout << rs.size() << '\n';
    for (int i : rs) cout << i << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 5;

int n, k, a[N];
vector<int> rs;
bool cal[N][N][N], F[N][N][N];

void Input()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    rs.push_back(0);
}

bool DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return true;
    if (i > n || t > k || c_sum < 0 || (t == k && c_sum != 0)) return false;

    if (cal[i][t][c_sum]) return F[i][t][c_sum];

    bool res = false;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    cal[i][t][c_sum] = true;
    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        bool res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    printf("%d \n", rs.size());
    for (int i : rs) printf("%d ", i);
}

int main()
{
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 5;

int n, k, a[N];
vector<int> rs;
bool cal[N][N][N], F[N][N][N];

void Input()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    rs.push_back(0);
}

bool DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return true;
    if (i > n || t > k || (t == k && c_sum != 0)) return false;

    if (cal[i][t][c_sum]) return F[i][t][c_sum];

    bool res = false;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    cal[i][t][c_sum] = true;
    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        bool res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    printf("%d \n", rs.size());
    for (int i : rs) printf("%d ", i);
}

int main()
{
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 2;

int n, k, a[N], F[N][N][N];
vector<int> rs;

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    rs.push_back(0);
    memset(F, -1, sizeof (F));
}

int DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return 1;
    if (i > n || t > k || (t == k && c_sum != 0))
        return 0;

    if (F[i][t][c_sum] != -1) return F[i][t][c_sum];

    int res = 0;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        int res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    cout << rs.size() << '\n';
    for (int i : rs) cout << i << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 5;

int n, k, a[N], F[N][N][N];
vector<int> rs;

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    rs.push_back(0);
    memset(F, -1, sizeof (F));
}

int DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return 1;
    if (i > n || t > k || (t == k && c_sum != 0))
        return 0;

    if (F[i][t][c_sum] != -1) return F[i][t][c_sum];

    int res = 0;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        int res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    cout << rs.size() << '\n';
    for (int i : rs) cout << i << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 5;

int n, k, a[N];
vector<int> rs;
bool F[N][N][N];

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    rs.push_back(0);
}

void Solve()
{
    for (int i = 1; i < N; i++)
        F[i][k][0] = 1;

    for (int i = n; i >= 1; i--)
    {
        for (int t = k; t >= 0; t--)
        {
            for (int j = 0; j <= k; j++)
            {
                F[i][t][j] |= F[i + 1][t][j];
                if (t + a[i] <= k) F[i][t][j] |= F[i + 1][t + a[i]][j];
            }

            for (int j = 0; j <= k; j++)
            {
                if (j - a[i] >= 0 && t + a[i] <= k)
                    F[i][t][j] |= F[i + 1][t + a[i]][j - a[i]];
            }
        }
    }

    for (int s = 1; s <= k; s++)
        if (F[1][0][s]) rs.push_back(s);

    cout << rs.size() << '\n';
    for (int i : rs) cout << i << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 2;

int n, k, a[N];
vector<int> rs;
bool F[N][N][N];

void Input()
{
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    rs.push_back(0);
    memset(F, false, sizeof (F));
}

bool DP(int i, int t, int c_sum)
{
    if (t == k && c_sum == 0) return true;
    if (i > n || t > k || (t == k && c_sum != 0)) return false;

    if (F[i][t][c_sum]) return true;

    bool res = false;
    res |= DP(i + 1, t, c_sum);
    res |= DP(i + 1, t + a[i], c_sum);
    res |= DP(i + 1, t + a[i], c_sum - a[i]);

    return (F[i][t][c_sum] = res);
}

void Solve()
{
    for (int i = 1; i <= k; i++)
    {
        bool res = DP(1, 0, i);
        if (res) rs.push_back(i);
    }

    printf("%d \n", rs.size());
    for (int i : rs) printf("%d ", i);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    Input();
    Solve();
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define dd second
#define ff first
#define pp pair<int,int>
#define pb push_back
#define mp make_pair
#define in insert
using namespace std;

int n,k;
vector<int> liczby;
vector<set<int>> jakie(501);

void dodaj(int x) {
  for(int i = 500; i >= 0; --i) {
      if(i+x > 500) continue;
      for(auto &it:jakie[i]) {
        jakie[i+x].in((it));
      }
      jakie[i+x].in(i+x);
      jakie[i+x].in(x);
  }

}

main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  liczby.resize(n);
  jakie[0].in(0);
  for(auto &i:liczby) cin >> i,dodaj(i);
  cout << jakie[k].size() << endl;
  for(auto &i:jakie[k]) cout << (i) << " ";
  cout << endl;
}


#include <bits/stdc++.h>
//#define int long long
#define dd second
#define ff first
#define pp pair<int,int>
#define pb push_back
#define mp make_pair
#define in insert
using namespace std;

int n,k;
vector<int> liczby;
vector<set<int>> jakie(501);

void dodaj(int x) {
   //cout << "dodaje " << x << endl;
  for(int i = 500; i >= 0; --i) {
      if(i+x > 500) continue;
      for(auto &it:jakie[i]) {
        jakie[i+x].in((it));
        if(it+x <= 500) jakie[x+i].in(it+x);
      }
  }
//  for(int i = 0; i < 19; ++i) {
//     cout << i << " | ";
//    for(auto &x:jakie[i]) cout << x << " ";
//    cout << endl;
//  }

}

main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> n >> k;
  liczby.resize(n);
  jakie[0].in(0);
  for(auto &i:liczby) cin >> i,dodaj(i);
  cout << jakie[k].size() << endl;
  for(auto &i:jakie[k]) cout << (i) << " ";
  cout << endl;
}


#include <bits/stdc++.h>
#define int long long
#define dd second
#define ff first
#define pp pair<int,int>
#define pb push_back
#define mp make_pair
#define in insert
using namespace std;

int n,k;
vector<int> liczby;
vector<set<int>> jakie(501);

void dodaj(int x) {
   //cout << "dodaje " << x << endl;
  for(int i = 500; i >= 0; --i) {
      if(i+x > 500) continue;
      for(auto &it:jakie[i]) {
        jakie[i+x].in((it));
        if(it+x <= 500) jakie[x+i].in(it+x);
      }
  }
//  for(int i = 0; i < 19; ++i) {
//     cout << i << " | ";
//    for(auto &x:jakie[i]) cout << x << " ";
//    cout << endl;
//  }

}

main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  liczby.resize(n);
  jakie[0].in(0);
  for(auto &i:liczby) cin >> i,dodaj(i);
  cout << jakie[k].size() << endl;
  for(auto &i:jakie[k]) cout << (i) << " ";
  cout << endl;
}


#include <bits/stdc++.h>
#define int short int
#define dd second
#define ff first
#define pp pair<int,int>
#define pb push_back
#define mp make_pair
#define in insert
using namespace std;

int n,k;
vector<int> liczby;
vector<unordered_set<int>> jakie(501);

void dodaj(int x) {
   //cout << "dodaje " << x << endl;
  for(int i = 500; i >= 0; --i) {
      if(i+x > 500) continue;
      for(auto &it:jakie[i]) {
        jakie[i+x].in((it));
        if(it+x <= 500) jakie[x+i].in(it+x);
      }
  }
//  for(int i = 0; i < 19; ++i) {
//     cout << i << " | ";
//    for(auto &x:jakie[i]) cout << x << " ";
//    cout << endl;
//  }

}

main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> n >> k;
  liczby.resize(n);
  jakie[0].in(0);
  for(auto &i:liczby) cin >> i,dodaj(i);
  cout << jakie[k].size() << endl;
  vector<int> res;
  for(auto &i:jakie[k]) res.pb(i);
  sort(res.begin(),res.end());
  for(auto &i:res) cout << i << " ";
  cout << endl;
}


#include"bits/stdc++.h"

using namespace std;
int dp[505][505];
int c[505];
vector<int> ans;
int n, k;
int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &c[i]);
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++){
        dp[c[i]][c[i]] = 1;
        dp[c[i]][0] = 1;
    }
    for(int i = 1; i <= n; i ++){
        for(int j = k; j >= c[i]; j --){
            for(int p = j; p >= 0; p --){
                dp[j][p] = dp[j][p] | dp[j - c[i]][p];
                if(p >= c[i])
                    dp[j][p] = dp[j][p] | dp[j - c[i]][p - c[i]];
            }
        }
    }
    for(int i = 0; i <= k; i ++){
        if(dp[k][i] == 1)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size() - 1; i ++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size() - 1] << endl;
    return 0;
}


#include"bits/stdc++.h"

using namespace std;
int dp[505][505];
int c[505];
vector<int> ans;
int n, k;
int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &c[i]);
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++){
        dp[c[i]][c[i]] = 1;
        dp[c[i]][0] = 1;
    }
    for(int i = 2; i <= n; i ++){
        for(int j = k; j >= c[i]; j --){
            for(int p = j; p >= 0; p --){
                dp[j][p] = dp[j][p] | dp[j - c[i]][p];
                if(p >= c[i])
                    dp[j][p] = dp[j][p] | dp[j - c[i]][p - c[i]];
            }
        }
    }
    for(int i = 0; i <= k; i ++){
        if(dp[k][i] == 1)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size() - 1; i ++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size() - 1] << endl;
    return 0;
}


#include"bits/stdc++.h"

using namespace std;
int dp[505][505];
int c[505];
vector<int> ans;
int n, k;
int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &c[i]);
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++){
        dp[c[i]][c[i]] = 1;
        dp[c[i]][0] = 1;
    }
    for(int i = 2; i <= n; i ++){
        for(int j = k; j >= c[i]; j --){
            for(int p = k; p >= 0; p --){
                dp[j][p] = dp[j][p] | dp[j - c[i]][p];
                if(p >= c[i])
                    dp[j][p] = dp[j][p] | dp[j - c[i]][p - c[i]];
            }
        }
    }
    for(int i = 0; i <= k; i ++){
        if(dp[k][i] == 1)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size() - 1; i ++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size() - 1] << endl;
    return 0;
}


#include"bits/stdc++.h"

using namespace std;
int dp[505][505];
int c[505];
vector<int> ans;
int n, k;
int main()
{
    cin >> n >> k;
    int sum = 0;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &c[i]);
        sum += c[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++){
        for(int j = k; j >= c[i]; j --){
            for(int p = k; p >= 0; p --){
                dp[j][p] = (dp[j][p] || dp[j - c[i]][p]);
                if(p >= c[i])
                    dp[j][p] = (dp[j][p] || dp[j - c[i]][p - c[i]]);
            }
        }
    }
    for(int i = 0; i <= k; i ++){
        if(dp[k][i] == 1)
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size() - 1; i ++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size() - 1] << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 510

bool dp[MR][MR];

int main()
{
    dp[0][0] = 1;
    int n, k;
    scanf( "%d%d", &n, &k );
    REP( i, n )
    {
        int c;
        scanf( "%d", &c );
        FORD( v1, k + 1, 0 )FORD( v2, k + 1, 0 )
            if (( v1 >= c && dp[v1 - c][v2] ) || ( v2 >= c && dp[v1][v2 - c] ))
                dp[v1][v2] = 1;
    }

    set<int> res;
    REP( i, k + 1 )
    {
        if (dp[i][k - i])
        {
            res.insert( i );
            res.insert( k - i );
        }
    }

    printf( "%d\n", res.size() );
    for (auto it = res.begin(); it != res.end(); it++)
    {
        printf( "%d ", *it );
    }
    printf( "\n" );
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 510

bool res[MR], ok[MR];

int c[MR];

bool dp1[MR], dp2[MR];

int n, k;

bool ok2( int v )
{
    memset( dp2, 0, sizeof( dp2 ) );
    dp2[0] = 1;
    REP( i, n )
    {
        if (ok[i])
        {
            FORD( j, v + 1, c[i] )
            {
                if (dp2[j - c[i]])
                    dp2[j] = 1;
            }
        }
    }

    return dp2[v];
}

int last[MR];
bool ok1( int v )
{
    memset( ok, 1, sizeof( ok ) );
    memset( dp1, 0, sizeof( dp1 ) );
    dp1[0] = 1;
    REP( i, n )
    {
        FORD( j, v + 1, c[i] )
        {
            if (dp1[j - c[i]] && !dp1[j])
            {
                dp1[j] = 1;
                last[j] = i;
            }
        }
    }

    if (dp1[v])
    {
        int pom = v;
        while (pom)
        {
            ok[last[pom]] = 0;
            pom -= c[last[pom]];
        }

        return ok2( k - v );
    }

    return 0;
}

int main()
{
    scanf( "%d%d", &n, &k );
    REP( i, n )
        scanf( "%d", &c[i] );

    res[0] = res[k] = 1;
    FOR( i, 1, k )
        res[i] = ok1( i );

    sort( c, c + n );
    FOR( i, 1, k )
        if (!res[i])
            res[i] = ok1( i );

    reverse( c, c + n );
    FOR( i, 1, k )
        if (!res[i])
            res[i] = ok1( i );

    REP( i, 10000 )
    {
        random_shuffle( c, c + n );
        FOR( i, 1, k )
            if (!res[i])
                res[i] = ok1( i );
    }

    vector <int > r;
    REP( i, k + 1 )
        if (res[i])
            r.push_back( i );
    printf( "%d\n", r.size() );
    REP( i, r.size() )
        printf( "%d ", r[i] );
    printf( "\n" );
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 510

bool res[MR], ok[MR];

int c[MR];

bool dp1[MR], dp2[MR];

int n, k;

bool ok2( int v )
{
    memset( dp2, 0, sizeof( dp2 ) );
    dp2[0] = 1;
    REP( i, n )
    {
        if (ok[i])
        {
            FORD( j, v + 1, c[i] )
            {
                if (dp2[j - c[i]])
                    dp2[j] = 1;
            }
        }
    }

    return dp2[v];
}

int last[MR];
bool ok1( int v )
{
    memset( ok, 1, sizeof( ok ) );
    memset( dp1, 0, sizeof( dp1 ) );
    dp1[0] = 1;
    REP( i, n )
    {
        FORD( j, v + 1, c[i] )
        {
            if (dp1[j - c[i]] && !dp1[j])
            {
                dp1[j] = 1;
                last[j] = i;
            }
        }
    }

    if (dp1[v])
    {
        int pom = v;
        while (pom)
        {
            ok[last[pom]] = 0;
            pom -= c[last[pom]];
        }

        return ok2( k - v );
    }

    return 0;
}

int main()
{
    scanf( "%d%d", &n, &k );
    REP( i, n )
        scanf( "%d", &c[i] );

    res[0] = res[k] = 1;
    FOR( i, 1, k )
        res[i] = ok1( i );

    sort( c, c + n );
    FOR( i, 1, k )
        if (!res[i])
            res[i] = ok1( i );

    reverse( c, c + n );
    FOR( i, 1, k )
        if (!res[i])
            res[i] = ok1( i );

    REP( i, 1000 )
    {
        random_shuffle( c, c + n );
        FOR( i, 1, k )
            if (!res[i])
                res[i] = ok1( i );
    }

    vector <int > r;
    REP( i, k + 1 )
        if (res[i])
            r.push_back( i );
    printf( "%d\n", r.size() );
    REP( i, r.size() )
        printf( "%d ", r[i] );
    printf( "\n" );
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 510

bool dp[MR][MR];

int main()
{
    dp[0][0] = 1;
    int n, k;
    scanf( "%d%d", &n, &k );
    REP( i, n )
    {
        int c;
        scanf( "%d", &c );
        FORD( v1, k + 1, c )FORD( v2, k + 1, c )
            if (dp[v1 - c][v2] || dp[v1][v2 - c])
                dp[v1][v2] = 1;
    }

    set<int> res;
    REP( i, k + 1 )
    {
        if (dp[i][k - i])
        {
            res.insert( i );
            res.insert( k - i );
        }
    }

    printf( "%d\n", res.size() );
    for (auto it = res.begin(); it != res.end(); it++)
    {
        printf( "%d ", *it );
    }
    printf( "\n" );
    return 0;
}


#include<bits/stdc++.h>
#define maxn 505
#define maxC 1000000000
#define MOD 1000000007
#define mp make_pair
#define PB push_back
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define repd(i, a, b) for(int i=(a) ; i>=(b) ; --i)
#define Task ""
using namespace std;
bool dp[maxn][maxn][maxn];
int n, sum, a[maxn], luu[maxn], dem;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n >> sum;
    rep(i, 1, n) cin >> a[i];
    dp[0][0][0] = 1;
    rep(i, 1, n)
        repd(j, sum, 0)
            repd(k, j, 0) {
                dp[i][j][k] |= dp[i-1][j][k];
                if(j >= a[i]) {
                    dp[i][j][k] |= dp[i-1][j-a[i]][k];
                    if(k >= a[i]) dp[i][j][k] |= dp[i-1][j-a[i]][k-a[i]];
                }
            }
    rep(i, 0, sum) {
        if(dp[n][sum][i]) luu[++dem] = i;
    }
    cout << dem << '\n';
    rep(i, 1, dem) cout << luu[i] << ' ';
    return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX][MAX];

int c[MAX];
int main() {
    int n; int k;
    cin >> n >> k;
    F0R(i, n) { cin >> c[i+1]; }
    sort(c+1, c+n+1);
    F0R(i, n+1) { vals[0][i].insert(0); }

    FOR(i, 1, k+1) {
        FOR(j, 1, n+1) {
            /* getting total of i with first jth coins */
            if (i-c[j] < 0) {
                for (int m : vals[i][j]) { vals[i][j+1].insert(m); }
                continue;
            }
            set<int> targ = vals[i-c[j]][j-1];
            if (targ.empty()) {
                for (int m : vals[i][j]) { vals[i][j+1].insert(m); }
                continue;
            }
            for (int m : targ) { vals[i][j].insert(m); vals[i][j].insert(m+c[j]); }
            for (int m : vals[i][j]) { vals[i][j+1].insert(m); }
        }
    }
    cout << vals[k][n].size() << endl;
    for (int i : vals[k][n]) { cout << i << " "; }
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX];

int c[MAX];
int main() {
    read2(n, k);
    F0R(i, n) { scanf("%d", &c[i+1]); }
    sort(c+1, c+n+1);
    vals[0].insert(0);
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            for (int l : vals[i]) {
                if (i+c[j] >= MAX) { continue; }
                vals[i+c[j]].insert(l);
                vals[i+c[j]].insert(l+c[j]);
            }
        }
    }
    printf("%d\n", vals[k].size());
    pv(vals[k]);
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX];

int c[MAX];
int main() {

    int n; int k;
    cin >> n >> k;
    F0R(i, n) { cin >> c[i+1]; }
    sort(c+1, c+n+1);
    vals[0].insert(0);
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            for (int l : vals[i]) {
                vals[i+c[j]].insert(l);
                vals[i+c[j]].insert(l+c[j]);
            }
        }
    }
    cout << vals[k].size() << endl;
    pv(vals[k]);
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

vector<int> vals[MAX];
bool vals2[MAX][MAX];

int c[MAX];
int main() {
    read2(n, k);
    F0R(i, n) { scanf("%d", &c[i+1]); }
    sort(c+1, c+n+1);
    vals[0].pb(0);
    vals2[0][0] = true;
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            for (int l : vals[i]) {
                if (i+c[j] >= MAX) { continue; }
                if (!vals2[i+c[j]][l]) {
                    vals[i+c[j]].pb(l);
                    vals2[i+c[j]][l] = true;
                }
                if (!vals2[i+c[j]][l+c[j]]) {
                    vals[i+c[j]].pb(l+c[j]);
                    vals2[i+c[j]][l+c[j]] = true;
                }
            }
        }
    }
    printf("%d\n", vals[k].size());
    pv(vals[k]);
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

bitset<500> vals[MAX];

int c[MAX];
int main() {
    read2(n, k);
    F0R(i, n) { scanf("%d", &c[i+1]); }
    sort(c+1, c+n+1);
    vals[0].set(0, 1);
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            F0R(l, 500) {
                if (vals[i][l] == 0) { continue; }
                if (i+c[j] >= MAX) { continue; }
                vals[i+c[j]].set(l, 1);
                vals[i+c[j]].set(l+c[j], 1);
            }
        }
    }
    printf("%d\n", vals[k].count());
    F0R(i, MAX) { if (vals[k][i]) { cout << i << " "; } }
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX][MAX];

int c[MAX];
int main() {
    int n; int k;
    cin >> n >> k;
    F0R(i, n) { cin >> c[i+1]; }
    sort(c+1, c+n+1);
    F0R(i, n+1) { vals[0][i].insert(0); }

    FOR(i, 1, k+1) {
        FOR(j, 1, n+1) {
            /* getting total of i with first jth coins */
            if (i-c[j] < 0) { continue; }
            set<int> targ = vals[i-c[j]][j-1];
            if (targ.empty()) { continue; }
            for (int m : targ) { vals[i][j].insert(m); vals[i][j].insert(m+c[j]); }
            for (int m : vals[i][j]) { vals[i][j+1].insert(m); }
        }
    }
    cout << vals[k][n].size() << endl;
    for (int i : vals[k][n]) { cout << i << " "; }
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX];

int c[MAX];
int main() {
    read2(n, k);
    F0R(i, n) { scanf("%d", &c[i+1]); }
    sort(c+1, c+n+1);
    vals[0].insert(0);
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            for (int l : vals[i]) {
                if (i+c[j] > MAX) { continue; }
                vals[i+c[j]].insert(l);
                vals[i+c[j]].insert(l+c[j]);
            }
        }
    }
    printf("%d\n", vals[k].size());
    pv(vals[k]);
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

set<int> vals[MAX][10];

int c[MAX];
int main() {
    int n; int k;
    cin >> n >> k;
    F0R(i, n) { cin >> c[i+1]; }
    sort(c+1, c+n+1);
    F0R(i, n+1) { vals[0][i%5].insert(0); }

    FOR(j, 1, n+1) {
        FOR(i, 1, k+1) { vals[i][(j+2)%5].clear(); }
        FOR(i, 1, k+1) {
            /* getting total of i with first jth coins */
            if (i-c[j] < 0) {
                for (int m : vals[i][j%5]) { vals[i][(j+1)%5].insert(m); }
                continue;
            }
            set<int> targ = vals[i-c[j]][(j+4)%5];
            if (targ.empty()) {
                for (int m : vals[i][j%5]) { vals[i][(j+1)%5].insert(m); }
                continue;
            }
            for (int m : targ) { vals[i][j%5].insert(m); vals[i][j%5].insert(m+c[j]); }
            for (int m : vals[i][j%5]) { vals[i][(j+1)%5].insert(m); }
        }
    }
    cout << vals[k][n%5].size() << endl;
    for (int i : vals[k][n%5]) { cout << i << " "; }
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 505;

vector<int> vals[MAX];
bool vals2[MAX][MAX];

int c[MAX];
int main() {
    read2(n, k);
    F0R(i, n) { scanf("%d", &c[i+1]); }
    sort(c+1, c+n+1);
    vals[0].pb(0);
    vals2[0][0] = true;
    FOR(j, 1, n+1) {
        for (int i=k; i>=0; i--) {
            for (int l : vals[i]) {
                if (i+c[j] >= MAX) { continue; }
                if (!vals2[i+c[j]][l]) {
                    vals[i+c[j]].pb(l);
                    vals2[i+c[j]][l] = true;
                }
                if (!vals2[i+c[j]][l+c[j]]) {
                    vals[i+c[j]].pb(l+c[j]);
                    vals2[i+c[j]][l+c[j]] = true;
                }
            }
        }
    }
    sort(vals[k].begin(), vals[k].end());
    printf("%d\n", vals[k].size());
    pv(vals[k]);
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int arr[26];
int main()
{
	fast;
	int n; cin >> n;
	string s;
	cin >> s;
	set<char> c;
	int mx = 0;
	int l = s.size();
	for (int i = 0; i < l; i++)
	{
		arr[s[i] - 'a']++;
		c.insert(s[i]);
		mx = max(mx, arr[s[i] - 'a']);
	}
	int counter = 0;
	for (int i = 0; i < 26; i++) counter += arr[i];

	if ((c.size() != n && c.size() != 1 )) cout << -1 << endl;
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (auto i : c) cout << i;
		}
		cout << endl;
	}
		//pause;
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int main()
{
	fast;
	int n;
	cin >> n;
	string s;
	cin >> s;

	int m = s.length();
	if (m%n != 0) { cout << "-1"; return 0; }

	int c[26];
	for (int i = 0; i < 26; i++) c[i] = 0;
	for (int i = 0; i < m; i++) c[s[i] - 'a']++;

	for (int i = 0; i < 26; i++) if (c[i] % n != 0) { cout << "-1"; return 0; }

	string str;
	for (int i = 0; i < 26; i++) {

		if (c[i] != 0) {
			for (int j = 0; j < c[i]; j += n) str += (i + 'a');
		}
	}

	string sol;
	for (int i = 0; i < n; i++) sol += str;

	cout << sol;

	return 0;

}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int arr[26];
int main()
{
	fast;
	int n; cin >> n;
	string s;
	cin >> s;
	set<char> c;
	int mx = 0;
	int l = s.size();
	for (int i = 0; i < l; i++)
	{
		arr[s[i] - 'a']++;
		c.insert(s[i]);
		mx = max(mx, arr[s[i] - 'a']);
	}
	int counter = 0;
	for (int i = 0; i < 26; i++) counter += arr[i];

	if (c.size() != n || mx*c.size() != n * c.size()) cout << -1 << endl;
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (auto i : c) cout << i;
		}
		cout << endl;
	}
		//pause;
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;

	int m = s.length();
	if (m%n != 0) { cout << "-1"; return 0; }

	int c[26];
	for (int i = 0; i < 26; i++) c[i] = 0;
	for (int i = 0; i < m; i++) c[s[i] - 'a']++;

	for (int i = 0; i < 26; i++) if (c[i] % n != 0) { cout << "-1"; return 0; }

	string str;
	for (int i = 0; i < 26; i++) {

		if (c[i] != 0) {
			for (int j = 0; j < c[i]; j += n) str += (i + 'a');
		}
	}

	string sol;
	for (int i = 0; i < n; i++) sol += str;

	cout << sol;

	return 0;

}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int arr[26];
int main()
{
	fast;
	int n; cin >> n;
	string s;
	cin >> s;
	set<char> c;
	int mx = 0;
	int l = s.size();
	for (int i = 0; i < l; i++)
	{
		arr[s[i] - 'a']++;
		c.insert(s[i]);
		mx = max(mx, arr[s[i] - 'a']);
	}
	int counter = 0;
	for (int i = 0; i < 26; i++) counter += arr[i];

	if ((c.size() != n && c.size() != 1 ) || mx*c.size() != n * c.size()) cout << -1 << endl;
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (auto i : c) cout << i;
		}
		cout << endl;
	}
		//pause;
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int arr[26];
int main()
{
	fast;
	int n; cin >> n;
	string s;
	cin >> s;
	set<char> c;
	int mx = 0;
	int l = s.size();
	for (int i = 0; i < l; i++)
	{
		arr[s[i] - 'a']++;
		c.insert(s[i]);
		mx = max(mx, arr[s[i] - 'a']);
	}
	int counter = 0;
	for (int i = 0; i < 26; i++) counter += arr[i];

	if ((c.size() != n && c.size() != 1 )  || mx != n) cout << -1 << endl;
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (auto i : c) cout << i;
		}
		cout << endl;
	}
		//pause;
}


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef pair <int, int> intpair;
#define longlongvector vector<long long>
typedef long long ll;
#define pause system("pause")
#define overtwo >> 1
#define intvector vector<int>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
//#define size .size()
#define ever for(;;)
// max element in a vector --> maxelement
// count ... returns a number of time an element occurs in any array or vector  count ( a, a.end, item )
// lowerebound --> first equal or greater than
// you can memeset a 2d char array....
// a pair is sorted according to its first
// sort(v.rbegin(), v.rend()-1);
#define inf 0x3f3f3f3f
#define maxelement(x) *max_element(all(x));

int arr[26];
int main()
{
	fast;
	int n; cin >> n;
	string s;
	cin >> s;
	set<char> c;
	int mx = 0;
	int l = s.size();
	for (int i = 0; i < l; i++)
	{
		arr[s[i] - 'a']++;
		c.insert(s[i]);
		mx = max(mx, arr[s[i] - 'a']);
	}
	int counter = 0;
	for (int i = 0; i < 26; i++) counter += arr[i];

	if ((c.size() != n && n != 1 ) || mx*c.size() != n * c.size()) cout << -1 << endl;
	else
	{
		for (int i = 0; i < n; i++)
		{
			for (auto i : c) cout << i;
		}
		cout << endl;
	}
		//pause;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    int c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
    {
        c[(int)(s[i] - 'a')]++;
    }

    for (int i = 0; i < s.length(); i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;
            return 0;
        }
    }

    for (int nn = 0; nn < n; nn++)
    {
        for (int i = 0; i < 26; i++)
        {
            for (int cc  = 0; cc < c[i]/n; cc++)
            {
                cout << (char)('a' + i);
            }
        }
    }
    return 0;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    if (s.length() % n != 0)
    {
        cout << -1;
        return 0;
    }

    char c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
    {
        c[(int)(s[i] - 'a')]++;
    }

    for (int i = 0; i < s.length(); i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;
            return 0;
        }
    }

    for (int nn = 0; nn < n; nn++)
    {
        for (int i = 0; i < 26; i++)
        {
            for (int cc  = 0; cc < c[i]/n; cc++)
            {
                cout << (char)('a' + i);
            }
        }
    }
    return 0;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    if (s.length() % n != 0)
    {
        cout << -1;
        return 0;
    }

    int c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
    {
        c[(int)(s[i] - 'a')]++;
    }

    for (int i = 0; i < s.length(); i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;
            return 0;
        }
    }

    for (int nn = 0; nn < n; nn++)
    {
        for (int i = 0; i < 26; i++)
        {
            for (int cc  = 0; cc < c[i]/n; cc++)
            {
                cout << (char)('a' + i);
            }
        }
    }
    return 0;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    if (s.length() % n != 0)
    {
        cout << -1;
        return 0;
    }

    int c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
        c[s[i] - 'a']++;

    for (int i = 0; i < 26; i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;
            return 0;
        }
    }

    string s1;
    for (int i = 0; i < 26; i++)
    {
        for (int j = 0; j < c[i] / n; j++)
        {
            s1 += char('a' + i);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << s1;
    }
    return 0;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    if (s.length() % n != 0)
    {
        cout << -1;
        return 0;
    }

    int c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
        c[s[i] - 'a']++;

    for (int i = 0; i < s.length(); i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;
            return 0;
        }
    }

    string s1;
    for (int i = 0; i < 26; i++)
    {
        for (int j = 0; j < c[i] / n; j++)
        {
            s1 += char('a' + i);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << s1;
    }
    return 0;
}


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

int main()
{
    string s;
    int n = 0;
    cin >> n;
    cin >> s;

    int c[26];
    for (int i = 0; i < 26; i++)
    {
        c[i] = 0;
    }

    for (int i = 0; i < s.length(); i++)
    {
        c[(int)(s[i] - 'a')]++;
    }

    for (int i = 0; i < s.length(); i++)
    {
        if (c[i] % n != 0)
        {
            cout << -1;3
            return 0;
        }
    }

    for (int nn = 0; nn < n; nn++)
    {
        for (int i = 0; i < 26; i++)
        {
            for (int cc  = 0; cc < c[i]/n; cc++)
            {
                cout << (char)('a' + i);
            }
        }
    }
    return 0;
}


#include <iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	set<char> myset;
	set<char>::iterator it;
	for (int i = 0; i < s.length(); i++) {
		myset.insert(s[i]);
	}
	int* freqArray = new int[myset.size()];
	for (int i = 0; i < myset.size(); i++) {
		freqArray[i] = 0;
	}
	int k = 0;
	for (it = myset.begin(); it != myset.end(); it++) {
		for (int j = 0; j < s.length(); j++) {
			if (*it == s[j]) {
				freqArray[k]++;
			}
		}
		k++;
	}
	bool flag = true;
	for (int i = 0; i < myset.size(); i++) {
		if (freqArray[i] % n==0) {
			continue;
		}
		else {
			flag = false;
		}
	}
	if (flag) {
		for (int i = 0; i < n; i++) {
			k = 0;
			for (it = myset.begin(); it != myset.end(); it++) {
				for (int j = 0; j < (freqArray[k] / n); j++) {
					cout << *it;
				}
				k++;
			}
		}
	}
	else {
		cout << -1;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	set<char> myset;
	set<char>::iterator it;
	for (int i = 0; i < s.length(); i++) {
		myset.insert(s[i]);
	}
	int* freqArray = new int[myset.size()];
	for (int i = 0; i < myset.size(); i++) {
		freqArray[i] = 0;
	}
	int k = 0;
	for (it = myset.begin(); it != myset.end(); it++) {
		for (int j = 0; j < s.length(); j++) {
			if (*it == s[j]) {
				freqArray[k]++;
			}
		}
		k++;
	}
	bool flag = true;
	for (int i = 0; i < myset.size(); i++) {
		if (freqArray[i] == n) {
			continue;
		}
		else {
			flag = false;
		}
	}
	if (flag) {
		for (int i = 0; i < n; i++) {
			for (it = myset.begin(); it != myset.end(); it++) {
				cout << *it;
			}
		}
	}
	else {
		cout << -1;
	}
	return 0;
}


#include <iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	set<char> myset;
	set<char>::iterator it;
	for (int i = 0; i < s.length(); i++) {
		myset.insert(s[i]);
	}
	int* freqArray = new int[myset.size()];
	for (int i = 0; i < myset.size(); i++) {
		freqArray[i] = 0;
	}
	int k = 0;
	for (it = myset.begin(); it != myset.end(); it++) {
		for (int j = 0; j < s.length(); j++) {
			if (*it == s[j]) {
				freqArray[k]++;
			}
		}
		k++;
	}
	bool flag = true;
	for (int i = 0; i < myset.size(); i++) {
		if (freqArray[i] % n==0) {
			continue;
		}
		else {
			flag = false;
		}
	}
	if (flag) {
		for (int i = 0; i < n; i++) {
			for (it = myset.begin(); it != myset.end(); it++) {
				for(int i=0;i<(n/freqArray[i]);i++)
				cout << *it;
			}
		}
	}
	else {
		cout << -1;
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main() {
	int input;
	int counter[27];
	int isTrue=0;
	char string[1001];
	scanf("%d", &input);
	scanf("%s", string);
	int length = strlen(string);

	for(int x=0; x<26; x++){
		counter[x]=0;
	}

	for(int i=0; i<length; i++){
		counter[string[i]-97]++;
	}
	for(int i=0; i<26; i++){
		if(counter[i]%input!=0){
			isTrue=0;
			break;
		} else {
			isTrue=1;
		}
	}

	if(isTrue==0){
		printf("-1\n");
	} else {
		for(int y=0; y<input; y++){
		for(int i=0; i<26; i++){
			for(int x=0; x<counter[i]/input; x++){
				printf("%c", i+97);
			}
		}
		}
		printf("\n");
	}
}


#include<iostream>
#include<string>
using namespace std;
int arr[1111];
int main() {
int k;
cin>>k;
string s;
cin>>s;
for(int i=0; i<s.size(); i++)
    arr[s[i]]++;
for(int i ='a'; i <='z'; i++){
    if(arr[i]%k!=0){
        cout<<-1;
        return 0;
    }
}
for(int qwe = 1; qwe<=k; qwe++)
    for(int i ='a'; i <='z'; i++)
        for(int j=1; j<=arr[i]/k; j++)
            cout<<char(i);
return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int k;
    string str;
    cin >> k;
    cin >> str;
    vector<int> freq(26, 0);
    for(int i = 0; i < str.size(); i++)
        freq[str[i] - 97]++;
    string result = "";
    for(int i = 0; i < 26; i++)
    {
        if(freq[i] % k != 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            for(int j = 0; j < freq[i] / k; j++)
            {
                result += char(i + 97);
            }
        }
    }
    for(int i = 0; i < k; i++)
        cout << result;
    return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
using namespace std;
int main()
{
	int k;   cin >> k;
	int arr[26] = { 0 };
	string s;  cin >> s;
	for (int i = 0; i < s.size(); i++)
		arr[s[i] - 'a']++;

	string c="";
	bool b = true;
	for (int i = 0; i < 26; i++)
	{

		if (arr[i] != 0)
		{
			if (arr[i] % k!=0)
			{

				b = false;
				break;
			}
			else
				for (int j= 1; j <= arr[i] / k; j++)
					c.push_back((char)(i + 'a'));

		}
	}

	if (!b)
		cout << "-1";
	else
		for (int i = 1; i <= k; i++)
			cout << c;

	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
					xoa(a,j);
			}
	while(n--)
		cout << a;

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	if(n==1)
	{
		cout << a;
		return 0;
	}
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		if(x==1)
		{
			cout << a;
			return 0;
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
					xoa(a,j);
			}
	while(n--)
		cout << a;

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	if(n==1)
	{
		cout << a;
		return 0;
	}
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		if(x==1)
		{
			cout << a;
			return 0;
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
				{
					xoa(a,j);
					j--;
				}
			}
	while(n--)
		cout << a;

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	if(n==1)
	{
		cout << a;
		return 0;
	}
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		if(x==1)
		{
			cout << a;
			return 0;
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
				{
					xoa(a,j);
					j--;
				}
			}
	int f = k/strlen(a);
	while(f--)
		cout << a;

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0;
	cin >> n;
	int d=n;
	char a[10007];
	cin >> a;
	if(n==1)
	{
		cout << a;
		return 0;
	}
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		if(x==1)
		{
			cout << a;
			return 0;
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
				{
					xoa(a,j);
					j--;
				}
			}
	while(n--)
	{
		for(int i=0; i<x; i++)
		{
			int l=c[i]/d;
			while(l--)
				cout << a[i];
		}
	}

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	if(n==1)
	{
		cout << a;
		return 0;
	}
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
					xoa(a,j);
			}
	while(n--)
		cout << a;

	}
}


#include<iostream>
#include<cstring>
using namespace std;

void xoa(char b[], int vitri)
{
	int n = strlen(b);
	for(int i=vitri; i<=n; i++)
	{
		b[i] = b[i+1];
	}
	b[n-1] = '\0';
}

int main()
{
	int n, dem=0, b[10007], c[10007], x=0, d=0;
	cin >> n;
	char a[10007];
	cin >> a;
	if(n==1) cout << a;
	return 0;
	int k = strlen(a);
	for(int i=0; i<k; i++)
		b[i] = 1;
	if(k%n!=0) cout << "-1";
	else
	{
		for(int i=0; i<k; i++)
		{
			dem=1;
			if(b[i])
			{
				for(int j=i+1; j<k; j++)
				{
					if(a[i]==a[j])
					{
						dem++;
						b[j] = 0;
					}
				}
				c[x] = dem;
				x++;
			}
		}
		for(int i=0; i<x; i++)
			if(c[i]%n!=0)
			{
				cout << "-1";
				return 0;
			}
		for(int i=0; i<strlen(a); i++)
			for(int j=i+1; j<strlen(a); j++)
			{
				if(a[i]==a[j])
					xoa(a,j);
			}
	while(n--)
		cout << a;

	}
}