//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define si(x) scanf("%d",&x)
#define sii(a,b) scanf("%d%d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define siiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(x) scanf("%I64d",&x)
#define sll(a,b) scanf("%I64d%I64d",&a,&b)
#define slll(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sllll(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define ss(x) scanf("%s",x+1)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define piiii(a,b,c,d) printf("%d %d %d %d",a,b,c,d)
#define Pi(x) printf("%d\n",x)
#define Pii(x,y) printf("%d %d\n",x,y)
#define Piii(a,b,c) printf("%d %d %d\n",a,b,c)
#define Piiii(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define pl(x) printf("%I64d",x)
#define pll(x,y) printf("%I64d %I64d",x,y)
#define plll(a,b,c) printf("%I64d %I64d %I64d",a,b,c)
#define pllll(a,b,c,d) printf("%I64d %I64d %I64d %I64d",a,b,c,d)
#define Pl(x) printf("%I64d\n",x)
#define Pll(x,y) printf("%I64d %I64d\n",x,y)
#define Plll(a,b,c) printf("%I64d %I64d %I64d\n",a,b,c)
#define Pllll(a,b,c,d) printf("%I64d %I64d %I64d %I64d\n",a,b,c,d)
#define ps(x) printf("%s",x+1)
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;typedef long long LL;typedef long double LD;const LL pp=1e9+7;const LD eps=1e-8;
inline LL ksm(LL x,LL y=pp-2){x=(x%pp+pp)%pp;LL ans=1;while (y){if (y&1) ans=ans*x%pp;x=x*x%pp;y>>=1;}return ans;}
inline LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
inline void reads(char s[],int &n){n=0;char ch=getchar();while (ch==' ' || ch=='\n' || ch=='\r') ch=getchar();
while (ch!=' ' && ch!='\n' && ch!='\r' && ch!=EOF) s[++n]=ch,ch=getchar();}

// HEAP Attention : Int + Array_Size + Stores In key[] + Top.id/v = Min
// init() empty() top() push(id,value) pop()
/*
struct HEAP
{
    int sz;
    struct HEAP_Pair{int id,v;}T[100009];
    inline int ls(int x){return x<<1;}
    inline int rs(int x){return ((x<<1)|1);}
    inline int f(int x){return x>>1;}
    inline void init(){sz=0;}
    inline bool empty(){return sz==0;}
    inline HEAP_Pair top(){return T[1];}
    inline void push(int x,int v)
    {
        T[++sz].id=x;
        T[sz].v=v;
        pushup(sz);
    }
    inline void pop()
    {
        T[1]=T[sz--];
        pushdown(1);
    }
    void pushup(int x)
    {
        if (x==1) return;
        if (T[x].v<T[f(x)].v)    //
        {
            HEAP_Pair tmp=T[f(x)];
            T[f(x)]=T[x];
            T[x]=tmp;
            pushup(f(x));
        }
    }
    void pushdown(int x)
    {
        if (ls(x)>sz) return;
        int t=ls(x);
        if (rs(x)<=sz)
            if (T[rs(x)].v<T[t].v) t=rs(x);   //
        if (T[t].v<T[x].v)   //
        {
            HEAP_Pair tmp=T[t];
            T[t]=T[x];
            T[x]=tmp;
            pushdown(t);
        }
    }
};*/

// BIT Attention : Bit.init(Size) + Int + Array_Size + [ add1(x,v) sum(l,r) ] Or [ add(l,r,v) get(x) ]
// init(Size) [ add1(x,v) sum(l,r) ] Or [ add(l,r,v) get(x) ]
/*
struct BIT
{
	int T[100009],sz;
	inline int lowbit(int x){return x&(-x);}
	inline void init(int x){sz=x;}
	inline void Badd(int x,int v)
	{
		while (x<=sz)
		{
			T[x]+=v;
			x+=lowbit(x);
		}
	}
	inline int Bsum(int x)
	{
		int ans=0;
		while (x>=1)
		{
			ans+=T[x];
			x-=lowbit(x);
		}
		return ans;
	}
	inline void add1(int x,int v){Badd(x,v);}
	inline int sum(int l,int r){if (l>r) return 0;return Bsum(r)-Bsum(l-1);}
	inline void add(int l,int r,int v){Badd(l,v);Badd(r+1,-v);}
	inline int get(int x){return Bsum(x);}
};
*/

//Min/Max Pri Que Attention : MPQ.init(Size,Type [0=Min;1=Max] ) + get().id/v/t + Int + Array_Size
//get().id/v/t push(id,value,time) init(Size,Type) upd(L,R) empty()
/*
struct MPQ
{
	int sz,l,r,type;
	struct MPQ_Pair{int id,v,t;}q[1000009];
	inline void init(int thesz,int thetype){sz=thesz;l=r=0;type=thetype;}
	inline bool empty(){return l==r;}
	inline int pre(int x){if (x-1<0) return sz;return x-1;}
	inline int suc(int x){if (x+1>sz) return 1;return x+1;}
	inline void push(int id,int v,int t)
	{
		if (!type)
			while (q[pre(r)].v>=v && !empty()) r=pre(r);
		else
			while (q[pre(r)].v<=v && !empty()) r=pre(r);
		q[r].id=id,q[r].v=v,q[r].t=t;
		r=suc(r);
	}
	inline MPQ_Pair get(){return q[l];}
	inline void upd(int tL,int tR){while ((q[l].t<tL || q[l].t>tR) && !empty()) l=suc(l);}
};
*/
//========================    C    ========================    F    ==================================
int n;
char S[5009];
int cnt[1009];
int main()
{
	//freopen("r.txt","r",stdin);
	//freopen("w1.txt","w",stdout);
	reads(S,n);
	for (int i=1;i<=n;i++)
		cnt[S[i]]++;
	if (!(n&1))
	{
		bool ok=0;
		for (int i=1;i<=n/2;i++)
			if (S[i]!=S[n/2-i+1])
			{
				ok=1;
				break;
			}
		if (ok) puts("1"); else
		{
			if (cnt[S[n]]==n)
			puts("Impossible");
			else
				puts("2");
		}
	}
	else
	{
		bool ok=0;
		for (int i=1;i<=n/2;i++)
			if (S[i]!=S[n/2-i+1])
			{
				ok=1;
				break;
			}
		if (ok) puts("2"); else
		{
			if (cnt[S[n]]>=n-1)

			puts("Impossible");
			else puts("2");
		}
	}
	return 0;
}


//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define si(x) scanf("%d",&x)
#define sii(a,b) scanf("%d%d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define siiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(x) scanf("%I64d",&x)
#define sll(a,b) scanf("%I64d%I64d",&a,&b)
#define slll(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sllll(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define ss(x) scanf("%s",x+1)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define piiii(a,b,c,d) printf("%d %d %d %d",a,b,c,d)
#define Pi(x) printf("%d\n",x)
#define Pii(x,y) printf("%d %d\n",x,y)
#define Piii(a,b,c) printf("%d %d %d\n",a,b,c)
#define Piiii(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define pl(x) printf("%I64d",x)
#define pll(x,y) printf("%I64d %I64d",x,y)
#define plll(a,b,c) printf("%I64d %I64d %I64d",a,b,c)
#define pllll(a,b,c,d) printf("%I64d %I64d %I64d %I64d",a,b,c,d)
#define Pl(x) printf("%I64d\n",x)
#define Pll(x,y) printf("%I64d %I64d\n",x,y)
#define Plll(a,b,c) printf("%I64d %I64d %I64d\n",a,b,c)
#define Pllll(a,b,c,d) printf("%I64d %I64d %I64d %I64d\n",a,b,c,d)
#define ps(x) printf("%s",x+1)
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;typedef long long LL;typedef long double LD;const LL pp=1e9+7;const LD eps=1e-8;
inline LL ksm(LL x,LL y=pp-2){x=(x%pp+pp)%pp;LL ans=1;while (y){if (y&1) ans=ans*x%pp;x=x*x%pp;y>>=1;}return ans;}
inline LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
inline void reads(char s[],int &n){n=0;char ch=getchar();while (ch==' ' || ch=='\n' || ch=='\r') ch=getchar();
while (ch!=' ' && ch!='\n' && ch!='\r' && ch!=EOF) s[++n]=ch,ch=getchar();}

// HEAP Attention : Int + Array_Size + Stores In key[] + Top.id/v = Min
// init() empty() top() push(id,value) pop()
/*
struct HEAP
{
    int sz;
    struct HEAP_Pair{int id,v;}T[100009];
    inline int ls(int x){return x<<1;}
    inline int rs(int x){return ((x<<1)|1);}
    inline int f(int x){return x>>1;}
    inline void init(){sz=0;}
    inline bool empty(){return sz==0;}
    inline HEAP_Pair top(){return T[1];}
    inline void push(int x,int v)
    {
        T[++sz].id=x;
        T[sz].v=v;
        pushup(sz);
    }
    inline void pop()
    {
        T[1]=T[sz--];
        pushdown(1);
    }
    void pushup(int x)
    {
        if (x==1) return;
        if (T[x].v<T[f(x)].v)    //
        {
            HEAP_Pair tmp=T[f(x)];
            T[f(x)]=T[x];
            T[x]=tmp;
            pushup(f(x));
        }
    }
    void pushdown(int x)
    {
        if (ls(x)>sz) return;
        int t=ls(x);
        if (rs(x)<=sz)
            if (T[rs(x)].v<T[t].v) t=rs(x);   //
        if (T[t].v<T[x].v)   //
        {
            HEAP_Pair tmp=T[t];
            T[t]=T[x];
            T[x]=tmp;
            pushdown(t);
        }
    }
};*/

// BIT Attention : Bit.init(Size) + Int + Array_Size + [ add1(x,v) sum(l,r) ] Or [ add(l,r,v) get(x) ]
// init(Size) [ add1(x,v) sum(l,r) ] Or [ add(l,r,v) get(x) ]
/*
struct BIT
{
	int T[100009],sz;
	inline int lowbit(int x){return x&(-x);}
	inline void init(int x){sz=x;}
	inline void Badd(int x,int v)
	{
		while (x<=sz)
		{
			T[x]+=v;
			x+=lowbit(x);
		}
	}
	inline int Bsum(int x)
	{
		int ans=0;
		while (x>=1)
		{
			ans+=T[x];
			x-=lowbit(x);
		}
		return ans;
	}
	inline void add1(int x,int v){Badd(x,v);}
	inline int sum(int l,int r){if (l>r) return 0;return Bsum(r)-Bsum(l-1);}
	inline void add(int l,int r,int v){Badd(l,v);Badd(r+1,-v);}
	inline int get(int x){return Bsum(x);}
};
*/

//Min/Max Pri Que Attention : MPQ.init(Size,Type [0=Min;1=Max] ) + get().id/v/t + Int + Array_Size
//get().id/v/t push(id,value,time) init(Size,Type) upd(L,R) empty()
/*
struct MPQ
{
	int sz,l,r,type;
	struct MPQ_Pair{int id,v,t;}q[1000009];
	inline void init(int thesz,int thetype){sz=thesz;l=r=0;type=thetype;}
	inline bool empty(){return l==r;}
	inline int pre(int x){if (x-1<0) return sz;return x-1;}
	inline int suc(int x){if (x+1>sz) return 1;return x+1;}
	inline void push(int id,int v,int t)
	{
		if (!type)
			while (q[pre(r)].v>=v && !empty()) r=pre(r);
		else
			while (q[pre(r)].v<=v && !empty()) r=pre(r);
		q[r].id=id,q[r].v=v,q[r].t=t;
		r=suc(r);
	}
	inline MPQ_Pair get(){return q[l];}
	inline void upd(int tL,int tR){while ((q[l].t<tL || q[l].t>tR) && !empty()) l=suc(l);}
};
*/
//========================    C    ========================    F    ==================================
int n;
char S[5009];
int cnt[1009];
int main()
{
	freopen("r.txt","r",stdin);
	freopen("w1.txt","w",stdout);
	reads(S,n);
	for (int i=1;i<=n;i++)
		cnt[S[i]]++;
	if (!(n&1))
	{
		bool ok=0;
		for (int i=1;i<=n/2;i++)
			if (S[i]!=S[n/2-i+1])
			{
				ok=1;
				break;
			}
		if (ok) puts("1"); else
		{
			if (cnt[S[n]]==n)
			puts("Impossible");
			else
				puts("2");
		}
	}
	else
	{
		bool ok=0;
		for (int i=1;i<=n/2;i++)
			if (S[i]!=S[n/2-i+1])
			{
				ok=1;
				break;
			}
		if (ok) puts("2"); else
		{
			if (cnt[S[n]]>=n-1)

			puts("Impossible");
			else puts("2");
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define rep(i, s, t) for (int i = s; i < t; i++)
#define per(i, s, t) for (int i = s; i >= t; i--)
#define sz(x) ((int)x.size())
#define mp make_pair
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;

bool is_eq(const string &s) {
    bool eq = true;
    int n = sz(s);
    rep(i, 1, n) eq &= s[i] == s[0];
    return eq;
}

bool is_pal(const string &s) {
    string rs = s;
    reverse(rs.begin(), rs.end());
    return rs == s;
}

int main() {
    string s;
    cin >> s;
    int n = sz(s);
    if (is_eq(s)) {
        cout << "Impossible\n";
        return 0;
    }
    rep(i, 1, n) {
        string a = s.substr(0, i);
        string b = s.substr(i, n - i);
        if (b + a != s && is_pal(b + a)) {
            cout << "1\n";
            return 0;
        }
    }
    rep(i, 1, (n - 1) / 2 + 1) {
        string a = s.substr(0, i);
        string b = s.substr(i, n - 2 * i);
        string c = s.substr(n - i, i);
        if (c + b + a != s && is_pal(c + b + a)) {
            cout << "2\n";
            return 0;
        }
    }
    if (n % 2 == 0) {
        cout << "5\n";
    } else {
        if (is_eq(s.substr(0, n / 2))) {
            cout << "Impossible\n";
            return 0;
        }
        cout << "6\n";
        return 0;
    }
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, s, t) for (int i = s; i < t; i++)
#define per(i, s, t) for (int i = s; i >= t; i--)
#define sz(x) ((int)x.size())
#define mp make_pair
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;

bool is_eq(const string &s) {
    bool eq = true;
    int n = sz(s);
    rep(i, 1, n) eq &= s[i] == s[0];
    return eq;
}

bool is_pal(const string &s) {
    string rs = s;
    reverse(rs.begin(), rs.end());
    return rs == s;
}

int main() {
    string s;
    cin >> s;
    int n = sz(s);
    if (is_eq(s)) {
        cout << "Impossible\n";
        return 0;
    }
    rep(i, 1, n) {
        string a = s.substr(0, i);
        string b = s.substr(i, n - i);
        if (b + a != s && is_pal(b + a)) {
            cout << "1\n";
            return 0;
        }
    }
    rep(i, 1, (n - 1) / 2 + 1) {
        string a = s.substr(0, i);
        string b = s.substr(i, n - 2 * i);
        string c = s.substr(n - i, i);
        if (c + b + a != s && is_pal(c + b + a)) {
            cout << "2\n";
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,c,i;string s,r,t;
int main(){
	cin>>s;n=s.size();
	for(;i<n/2;i++)c+=s[i]!=s[0];
	if(!c)return cout<<"Impossible",0;
	for(i=1;i<=n/2;i++){
		t=s.substr(i,n)+s.substr(0,i);
		r=t;reverse(r.begin(),r.end());
		if(t==r&&t!=s)return cout<<1,0;
	}
	cout<<2;
}


#include<bits/stdc++.h>
using namespace std;
int n,c,i;string s,r,t;
int main(){
	cin>>s;n=s.size();
	for(;i<n/2;i++)c+=s[i]!=s[0];if(!c)return cout<<"Impossible",0;
	for(i=0;i<n/2;i++){
		t=s.substr(i,n)+s.substr(0,i);
		r=t;reverse(r.begin(),r.end());
		if(t==r&&t!=s)return cout<<1,0;
	}
	cout<<2;
}


#include<bits/stdc++.h>
using namespace std;
string s,qz;
int main(){
    cin>>s;
    int len=s.length();
    bool flg=1;
    if(len%2){
        for(int i=0;i<len;i++){
            if(i!=len/2&&s[i]!=s[0]){
                flg=0;break;
            }
        }
        if(flg){
            puts("Impossible");return 0;
        }
    } else {
        for(int i=0;i<len;i++){
            if(s[i]!=s[0]){
                flg=0;break;
            }
        }
        if(flg){
            puts("Impossible");return 0;
        }
    }
    flg=0;
    int qaq=(len/2)-1;
    for(int i=0;i<len-1;i++){
        qz+=s[i];
        string hz="";
        for(int j=i+1;j<len;j++) hz+=s[j];
        hz+=qz;
        bool flgg=1;
        for(int i=0;i<=qaq;i++){
            if(hz[i]!=hz[len-i-1]) flgg=0;
            }
        if(flgg&&hz!=s){
           // cout<<hz<<endl;
            flg=1;break;
        }
    }

    if(flg) printf("1\n");
    else puts("2");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,qz;
int main(){
    cin>>s;
    int len=s.length();
    bool flg=1;
    if(len%2){
        for(int i=0;i<len;i++){
            if(i!=len/2&&s[i]!=s[0]){
                flg=0;break;
            }
        }
        if(flg){
            puts("Impossible");return 0;
        }
    } else {
        for(int i=0;i<len;i++){
            if(s[i]!=s[0]){
                flg=0;break;
            }
        }
        if(flg){
            puts("Impossible");return 0;
        }
    }
    flg=0;
    int qaq=(len/2)-1;
    for(int i=0;i<len-1;i++){
        qz+=s[i];
        string hz="";
        for(int j=i+1;j<len;j++) hz+=s[j];
        hz+=qz;
        bool flgg=1;
        for(int i=0;i<=qaq;i++){
            if(hz[i]!=hz[len-i-1]) flgg=0;
            }
        if(flgg){
           // cout<<hz<<endl;
            flg=1;break;
        }
    }

    if(flg) printf("1\n");
    else puts("2");
    return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn*2+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2,j=1; i<=n; j=i,++i,(n%2==1)&&(i==n/2+1)&&(++i))
    {
      if(s[i]!=s[j])
        {
          ans=0;
        }
    }
  if(ans)
    {
      puts("Impossible");
      return 0;
    }
  ans=2;
  for(int i=1; i<=n; ++i)
    {
      s[i+n]=s[i];
    }
  for(int i=2; i<=n; ++i)
    {
      int flag=1;
      for(int j=1,k=i; j<=n; ++j,++k)
        {
          if(s[j]!=s[k])
            {
              flag=0;
            }
        }
      if(flag)
        {
          continue;
        }
      if(ispd(i,i+n-1))
        {
          ans=1;
          break;
        }
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]!=s[i-1])
        {
          ans=2;
          break;
        }
    }
  if(ans==-1)
    {
      puts("Impossible");
      return 0;
    }
  int flag=(n%2==1);
  for(int i=n/2; i; i>>=1)
    {
      if(!ispd(1,i))
        {
          if(!flag)
            {
              ans=1;
            }
          break;
        }
      if(i%2==1)
        {
          flag=1;
        }
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn*2+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]!=s[i-1])
        {
          ans=2;
          break;
        }
    }
  if(ans==-1)
    {
      puts("Impossible");
      return 0;
    }
  for(int i=1; i<=n; ++i)
    {
      s[i+n]=s[i];
    }
  for(int i=2; i<=n; ++i)
    {
      int flag=1;
      for(int j=1,k=i; j<=n; ++j,++k)
        {
          if(s[j]!=s[k])
            {
              flag=0;
            }
        }
      if(flag)
        {
          continue;
        }
      if(ispd(i,i+n-1))
        {
          ans=1;
          break;
        }
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn*2+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]==ans)
        {
          ans=-2;
        }
      if(s[i]!=s[i-1])
        {
          if(ans!=-1)
            {
              ans=-2;
            }
          ans=s[i];
          break;
        }
    }
  if(ans<=-2)
    {
      puts("Impossible");
      return 0;
    }
  ans=2;
  for(int i=1; i<=n; ++i)
    {
      s[i+n]=s[i];
    }
  for(int i=2; i<=n; ++i)
    {
      int flag=1;
      for(int j=1,k=i; j<=n; ++j,++k)
        {
          if(s[j]!=s[k])
            {
              flag=0;
            }
        }
      if(flag)
        {
          continue;
        }
      if(ispd(i,i+n-1))
        {
          ans=1;
          break;
        }
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]!=s[i-1])
        {
          ans=4;
          break;
        }
    }
  if(ans==-1)
    {
      puts("Impossible");
      return 0;
    }
  if(n%2==0)
    {
      ans=3;
    }
  int flag=(n%2==0)?0:s[n/2+1];
  for(int i=n/2; i; i>>=1)
    {
      if(!ispd(1,i))
        {
          if(!flag)
            {
              ans=1;
            }
          break;
        }
      if((i%2==1)&&(s[i+1]!=flag))
        {
          flag=-1;
        }
    }
  if(flag>0)
    {
      ans=2;
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn*2+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]!=s[i-1])
        {
          ++ans;
          break;
        }
    }
  if(ans<=0)
    {
      puts("Impossible");
      return 0;
    }
  for(int i=1; i<=n; ++i)
    {
      s[i+n]=s[i];
    }
  for(int i=2; i<=n; ++i)
    {
      int flag=1;
      for(int j=1,k=i; j<=n; ++j,++k)
        {
          if(s[j]!=s[k])
            {
              flag=0;
            }
        }
      if(flag)
        {
          continue;
        }
      if(ispd(i,i+n-1))
        {
          ans=1;
          break;
        }
    }
  printf("%d\n",ans);
  return 0;
}


#include <cstdio>
#include <cstring>

const int maxn=5000;

char s[maxn*2+10];
int n;

int ispd(int l,int r)
{
  for(int i=l,j=r; i<j; ++i,--j)
    {
      if(s[i]!=s[j])
        {
          return 0;
        }
    }
  return 1;
}

int main()
{
  scanf("%s",s+1);
  n=strlen(s+1);
  int ans=-1;
  for(int i=2; i<=n; ++i)
    {
      if(s[i]==ans)
        {
          ans=-2;
        }
      if(s[i]!=s[i-1])
        {
          if(ans!=-1)
            {
              ans=-2;
            }
          ans=s[i];
          break;
        }
    }
  if(ans<=-1)
    {
      puts("Impossible");
      return 0;
    }
  ans=2;
  for(int i=1; i<=n; ++i)
    {
      s[i+n]=s[i];
    }
  for(int i=2; i<=n; ++i)
    {
      int flag=1;
      for(int j=1,k=i; j<=n; ++j,++k)
        {
          if(s[j]!=s[k])
            {
              flag=0;
            }
        }
      if(flag)
        {
          continue;
        }
      if(ispd(i,i+n-1))
        {
          ans=1;
          break;
        }
    }
  printf("%d\n",ans);
  return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_ok(int L, int R, int x) {
	vector <int> pos;
	for ( int i = L; i <= R; i++ )
		if ( (x + 1) % (i + 1) == 0 && s[i] == s[x] ) pos.push_back(i);
	REP(i,pos.size()) {
		char tmp[5005] = {0};
		for ( int k = x + x - pos[i] - 1, i = R; i >= L; i--, k-- )
			tmp[i] = s[k];
		bool same = true;
		for ( int i = L; i <= R; i++ )
			if ( tmp[i] != s[i] ) same = false;
		if ( !same ) return true;
	}
	return false;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = INIT) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return 2;
		if ( prev == EVEN ) return 1;
		if ( !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return 2;
		if ( prev == EVEN ) return 2;
		if ( !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 3;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

bool is_palin(string &s) {
	for ( int i = 0, j = s.size()-1; i < j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	string str = s;
	sort(str.begin(),str.end());
	if ( str[0] == str[str.size()-2] )
		puts( "Impossible" );
	else {
		int ans = 2;
		for ( int i = 1; i < s.size(); i++ ) {
			string t = s.substr(i) + s.substr(0,i);
			if ( s == t ) continue;
			if ( !is_palin(t) ) continue;
			ans = 1;
			break;
		}
		printf( "%d\n", ans );
	}

	return 0;
}


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

bool is_palin(string &s) {
	for ( int i = 0, j = s.size()-1; i < j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	string str = s;
	sort(str.begin(),str.end());
	if ( str.size() <= 2 || str[0] == str[str.size()-2] )
		puts( "Impossible" );
	else {
		int ans = 2;
		for ( int i = 1; i < s.size(); i++ ) {
			string t = s.substr(i) + s.substr(0,i);
			if ( s == t ) continue;
			if ( !is_palin(t) ) continue;
			ans = 1;
			break;
		}
		printf( "%d\n", ans );
	}

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_ok(int L, int R, int x) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] == s[x] ) return true;
	return false;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 3;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return 6;
		if ( prev == EVEN ) return 4;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

bool is_palin(string &s) {
	for ( int i = 0, j = s.size()-1; i < j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	string str = s;
	sort(str.begin(),str.end());
	if ( str.size() <= 2
			 || str[0] == str[str.size()-2]
			 || str[1] == str[str.size()-1] )
		puts( "Impossible" );
	else {
		int ans = 2;
		for ( int i = 1; i < s.size(); i++ ) {
			string t = s.substr(i) + s.substr(0,i);
			if ( s == t ) continue;
			if ( !is_palin(t) ) continue;
			ans = 1;
			break;
		}
		printf( "%d\n", ans );
	}

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_ok(int L, int R, int x) {
	for ( int i = L; i <= R; i++ )
		if ( (x + 1) % (i + 1) == 0 && s[i] == s[x] ) return true;
	return false;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = INIT) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 1;
		if ( !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 3;
		if ( !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 4;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

bool is_palin(string &s) {
	for ( int i = 0, j = s.size()-1; i < j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	string str = s;
	sort(str.begin(),str.end());
	puts( str.c_str() );
	if ( str.size() <= 2 || str[0] == str[str.size()-2] )
		puts( "Impossible" );
	else {
		int ans = 2;
		for ( int i = 1; i < s.size(); i++ ) {
			string t = s.substr(i) + s.substr(0,i);
			if ( s == t ) continue;
			if ( !is_palin(t) ) continue;
			ans = 1;
			break;
		}
		printf( "%d\n", ans );
	}

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return 6;
		if ( prev == EVEN ) return 4;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid-1,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = 0) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return s[R] == s[R+1] ? 3 : 4;
		if ( prev == EVEN ) return 1;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return s[R] == s[R+1] ? 3 : 4;
		if ( prev == EVEN ) return 3;
		if ( prev == INIT && !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


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

#define REP(i,n)      for ( int i = 0, _n = (n); i < _n; i++ )
#define FOR(i,a,b)    for ( int i = (a), _n = (b); i <= _n; i++ )
#define FORD(i,a,b)   for ( int i = (a), _n = (b); i >= _n; i-- )
#define FORS(i,a,b,c) for ( int i = (a), _n = (b); i <= _n; i += c )
#define FOREACH(p,s)  for ( __typeof((s).begin()) p=(s).begin(); p!=(s).end(); p++)

const int inf = 100000;

char s[5005];

bool is_palindrome(int L, int R) {
	for ( int i = L, j = R; i <= j; i++, j-- )
		if ( s[i] != s[j] ) return false;
	return true;
}
bool is_all_same(int L, int R) {
	for ( int i = L; i <= R; i++ )
		if ( s[i] != s[L] ) return false;
	return true;
}
bool is_ok(int L, int R, int x) {
	vector <int> pos;
	for ( int i = L; i <= R; i++ )
		if ( (x + 1) % (i + 1) == 0 && s[i] == s[x] ) pos.push_back(i);
	REP(i,pos.size()) {
		char tmp[5005] = {0};
		for ( int k = x + x - pos[i] - 1, i = R; i >= L; i--, k-- )
			tmp[i] = s[k];
		bool same = true;
		for ( int i = L; i <= R; i++ )
			if ( tmp[i] != s[i] ) same = false;
		if ( !same ) return true;
	}
	return false;
}
bool is_even(int L, int R) { return (R - L + 1) % 2 == 0; }
bool is_odd(int L, int R)  { return (R - L + 1) % 2 == 1; }

const int INIT = 0;
const int ODD  = 1;
const int EVEN = 2;

int f(int L, int R, int prev = INIT) {
	if ( is_all_same(L,R) ) return -inf;
	int mid = (L + R - 1) / 2;
	if ( is_even(L,R) ) {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 1;
		if ( !is_palindrome(L,mid) ) return 1;
		return f(L,mid,EVEN);
	}
	else {
		if ( prev == ODD  ) return is_ok(L,R,R+1) ? 3 : 4;
		if ( prev == EVEN ) return 3;
		if ( !is_palindrome(L,mid) ) return 2;
		return f(L,mid,ODD);
	}
}

int main(int argc, char *argv[]) {

	scanf( "%s", s );

	int n = strlen(s);
	int ans = f(0,n-1);

	if ( ans < 0 )
		puts( "Impossible" );
	else
		printf( "%d\n", ans );

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,s1,s2;
int br[64];
int main()
{
    cin>>s;
    int i,l=false;
    for(i=0; i<s.size(); i++)br[s[i]-'a']++;
    for(i=0; i<30; i++)
    {
        if(br[i]==s.size()||br[i]==s.size()-1)l=true;
    }
    if(l==true)
    {
        cout<<"Impossible\n";
        return 0;
    }
    for(i=0; i<s.size()/2; i++)
    {
        s1+=s[i];
    }
    for(i=s.size()/2+s.size()%2; i<s.size(); i++)
    {
        s2+=s[i];
    }
    if(s.size()%2==1)
    {
        cout<<2<<endl;
        return 0;
    }
    else
    {
        if(s1==s2)
        {
            for(i=0; i<s.size(); i++)
            {
                s2=s.substr(0,i);
                s1=s.substr(i,s.size()-i);
                s1=s1+s2;
                l=false;
                if(s1!=s)
                {
                    l=true;
                    for(int j=0; j<s.size(); j++)
                    {
                        if(s1[j]==s[s.size()-j-1])l=false;
                    }
                }
                if(l==true)
                {
                    cout<<1<<endl;
                    return 0;
                }
            }
        }
        else
        {
            cout<<1<<endl;
            return 0;
        }
        if(!l)cout<<2<<endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
string s,s1,s2;
int br[64];
int main()
{
    cin>>s;
    int i,l=false;
    for(i=0; i<s.size(); i++)br[s[i]-'a']++;
    for(i=0; i<26; i++)
    {
        if(br[i]==s.size()||br[i]==s.size()-1)l=true;
    }
    if(l==true)
    {
        cout<<"Impossible\n";
        return 0;
    }
    for(i=0; i<s.size()/2; i++)
    {
        s1+=s[i];
    }
    for(i=s.size()/2+s.size()%2; i<s.size(); i++)
    {
        s2+=s[i];
    }
    if(s.size()%2==1)
    {
        cout<<2<<endl;
        return 0;
    }
    else
    {
        if(s1==s2)
        {
            for(i=0; i<s.size(); i++)
            {
                s2=s.substr(0,i);
                s1=s.substr(i,s.size()-i);
                s1=s1+s2;
                l=false;
                if(s1!=s)
                {
                    l=true;
                    for(int j=0; j<s.size(); j++)
                    {
                        if(s1[j]==s[s.size()-j-1])l=false;
                    }
                }
                if(l==true)
                {
                    cout<<1<<endl;
                    return 0;
                }
            }
        }
        else
        {
            cout<<1<<endl;
            return 0;
        }
        if(!l)cout<<2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,s1,s2;
int br[32];
int main()
{
    cin>>s;
    int sz=s.size(),i,j,l=0,mid;
    for(i=0; i<sz; i++)
    {
        br[s[i]-'a']++;
    }
    for(i=0; i<30; i++)
    {
        if(br[i]==sz||br[i]==sz-1)l=true;
    }
    if(l)
    {
        cout<<"Impossible\n";
        return 0;
    }
    for(i=0; i<sz/2; i++)
    {
        s1+=s[i];
    }
    for(i=sz/2+sz%2; i<sz; i++)
    {
        s2+=s[i];
    }
    if(sz%2)
    {
        cout<<2<<endl;
        return 0;
    }
    else
    {
        if(s1==s2)
            for(i=0; i<sz; i++)
            {
                s2=s.substr(0,i);
                s1=s.substr(i,sz-i);
                s1=s1+s2;
                l=false;
                if(s1!=s)
                {
                    l=true;
                    for(j=0; j<sz; j++)
                    {
                        if(s1[j]!=s1[sz-1-j])
                        {
                            l=false;
                        }
                    }
                }
                if(l)
                {
                    cout<<1<<endl;
                    break;
                }
            }
        else
        {
            cout<<1<<endl;
            return 0;
        }
        if(!l)cout<<2<<endl;
    }
    return 0;
}


/*/Saya-Javelin/*/
#include <cstdio>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#define Fo freopen ("file.in", "r", stdin), freopen ("file.out", "w", stdout)
#define Fc fclose (stdin), fclose (stdout)
#define iln inline
#define rgt register
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a)>0?(a):-(a))
#define Swap(a,b) (a)^=(b)^=(a)^=(b)
#define Sqr(x) ((x)*(x))
//#define int long long
#define ll long long
#define ld double

const int S=1000000;
char RRR[S];
char *SSR, *UR;

iln char fgc () {
    if (SSR==UR) UR=(SSR=RRR)+fread (RRR, 1, S, stdin);
    return *SSR++;
}

//#define gc rrr=fgc()
#define gc rrr=getchar()
iln void read (int &ur) {
    int ssr=1; char rrr; ur=0;
    while (gc, rrr>'9' || rrr<'0')
    if (rrr=='-') ssr=-1;
    while (rrr>='0' && rrr<='9')
    ur=ur*10+rrr-'0', gc;
    return (void) (ur*=ssr);
}
#undef gc

iln void write (int ur) {
    if (ur<0) putchar ('-'), ur*=-1;
    if (ur>=10) write (ur/10);
    return (void) putchar (ur%10+'0');
}

iln void wtn (int ur) {
    write (ur);
    return (void) putchar ('\n');
}
iln void wts (int ur) {
    write (ur);
    return (void) putchar (' ');
}

char s[5555];
bool use[16*2]={0};
int l, cnt=0;

iln bool check (int x, int r) {
    for (rgt int i=x; i<=(x+r)/2; ++i) {
        if (s[i]!=s[r-i+1]) return 0;
    }
    return 1;
}

signed main (void) {
    scanf ("%s", s+1);
    l=strlen (s+1);
    for (rgt int i=1; i<=l; ++i) {
        if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
    }
    if (cnt==1) puts ("Impossible");
    else if (l%2) puts ("2");
    else {
        int x=1, r=l/2;
        int last=r;
        while (check (x, r) && x!=r) {
            last=r;
            r=r/2;
        }
        if (last%2) puts ("2");
        else puts ("1");
    }
    return 0;
}
// mooboooombomboomobmmmboombmooboooombomboomobmmmboom


/*/Saya-Javelin/*/
#include <cstdio>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#define Fo freopen ("file.in", "r", stdin), freopen ("file.out", "w", stdout)
#define Fc fclose (stdin), fclose (stdout)
#define iln inline
#define rgt register
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a)>0?(a):-(a))
#define Swap(a,b) (a)^=(b)^=(a)^=(b)
#define Sqr(x) ((x)*(x))
//#define int long long
#define ll long long
#define ld double

const int S=1000000;
char RRR[S];
char *SSR, *UR;

iln char fgc () {
    if (SSR==UR) UR=(SSR=RRR)+fread (RRR, 1, S, stdin);
    return *SSR++;
}

//#define gc rrr=fgc()
#define gc rrr=getchar()
iln void read (int &ur) {
    int ssr=1; char rrr; ur=0;
    while (gc, rrr>'9' || rrr<'0')
    if (rrr=='-') ssr=-1;
    while (rrr>='0' && rrr<='9')
    ur=ur*10+rrr-'0', gc;
    return (void) (ur*=ssr);
}
#undef gc

iln void write (int ur) {
    if (ur<0) putchar ('-'), ur*=-1;
    if (ur>=10) write (ur/10);
    return (void) putchar (ur%10+'0');
}

iln void wtn (int ur) {
    write (ur);
    return (void) putchar ('\n');
}
iln void wts (int ur) {
    write (ur);
    return (void) putchar (' ');
}

char s[5555];
bool use[16*2]={0};
int l, cnt=0;

iln bool check (int x, int r) {
    for (rgt int i=x; i<=(x+r)/2; ++i) {
        if (s[i]!=s[r-i+1]) return 0;
    }
    return 1;
}

signed main (void) {
    scanf ("%s", s+1);
    l=strlen (s+1);
    for (rgt int i=1; i<=l; ++i) {
        if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
    }
    if (cnt==1) puts ("Impossible");
    else if (l%2) {
        cnt=0;
        memset (use, 0, sizeof (use));
        for (rgt int i=1; i<=l/2; ++i)
            if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
        if (cnt==1) puts ("Impossible");
        else puts ("2");
    }
    else {
        int x=1, r=l/2;
        int last=r;
        while (check (x, r) && x!=r) {
            last=r;
            r=r/2;
        }
        if (last%2) puts ("2");
        else puts ("1");
    }
    return 0;
}
// mooboooombomboomobmmmboombmooboooombomboomobmmmboom


/*/Saya-Javelin/*/
#include <cstdio>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#define Fo freopen ("file.in", "r", stdin), freopen ("file.out", "w", stdout)
#define Fc fclose (stdin), fclose (stdout)
#define iln inline
#define rgt register
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a)>0?(a):-(a))
#define Swap(a,b) (a)^=(b)^=(a)^=(b)
#define Sqr(x) ((x)*(x))
//#define int long long
#define ll long long
#define ld double

const int S=1000000;
char RRR[S];
char *SSR, *UR;

iln char fgc () {
    if (SSR==UR) UR=(SSR=RRR)+fread (RRR, 1, S, stdin);
    return *SSR++;
}

//#define gc rrr=fgc()
#define gc rrr=getchar()
iln void read (int &ur) {
    int ssr=1; char rrr; ur=0;
    while (gc, rrr>'9' || rrr<'0')
    if (rrr=='-') ssr=-1;
    while (rrr>='0' && rrr<='9')
    ur=ur*10+rrr-'0', gc;
    return (void) (ur*=ssr);
}
#undef gc

iln void write (int ur) {
    if (ur<0) putchar ('-'), ur*=-1;
    if (ur>=10) write (ur/10);
    return (void) putchar (ur%10+'0');
}

iln void wtn (int ur) {
    write (ur);
    return (void) putchar ('\n');
}
iln void wts (int ur) {
    write (ur);
    return (void) putchar (' ');
}

char s[5555];
bool use[16*2]={0};
int l, cnt=0;

signed main (void) {
    scanf ("%s", s);
    l=strlen (s);
    for (rgt int i=0; i<l; ++i) {
        if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
    }
    if (cnt==1) puts ("Impossible");
    else if (l%2) puts ("2");
    else {
        bool key=0;
        for (rgt int i=0; i<l/2; ++i) {
            if (s[i]!=s[l/2-i-1]) key=1;
        }
        if (key) puts ("1");
        else if (l/2%2) puts ("2");
        else puts ("1");
    }
    return 0;
}


/*/Saya-Javelin/*/
#include <cstdio>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#define Fo freopen ("file.in", "r", stdin), freopen ("file.out", "w", stdout)
#define Fc fclose (stdin), fclose (stdout)
#define iln inline
#define rgt register
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a)>0?(a):-(a))
#define Swap(a,b) (a)^=(b)^=(a)^=(b)
#define Sqr(x) ((x)*(x))
//#define int long long
#define ll long long
#define ld double

const int S=1000000;
char RRR[S];
char *SSR, *UR;

iln char fgc () {
    if (SSR==UR) UR=(SSR=RRR)+fread (RRR, 1, S, stdin);
    return *SSR++;
}

//#define gc rrr=fgc()
#define gc rrr=getchar()
iln void read (int &ur) {
    int ssr=1; char rrr; ur=0;
    while (gc, rrr>'9' || rrr<'0')
    if (rrr=='-') ssr=-1;
    while (rrr>='0' && rrr<='9')
    ur=ur*10+rrr-'0', gc;
    return (void) (ur*=ssr);
}
#undef gc

iln void write (int ur) {
    if (ur<0) putchar ('-'), ur*=-1;
    if (ur>=10) write (ur/10);
    return (void) putchar (ur%10+'0');
}

iln void wtn (int ur) {
    write (ur);
    return (void) putchar ('\n');
}
iln void wts (int ur) {
    write (ur);
    return (void) putchar (' ');
}

char s[5555];
bool use[16*2]={0};
int l, cnt=0;

iln bool check (int x, int r) {
    for (rgt int i=x; i<=(x+r)/2; ++i) {
        if (s[i]!=s[r-i+1]) return 0;
    }
    return 1;
}

signed main (void) {
    scanf ("%s", s+1);
    l=strlen (s+1);
    for (rgt int i=1; i<=l; ++i) {
        if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
    }
    if (cnt==1) puts ("Impossible");
    else if (l%2) {
        cnt=0;
        memset (use, 0, sizeof (use));
        for (rgt int i=1; i<=l/2; ++i)
            if (!use[s[i]-'a']) use[s[i]-'a']=1, cnt++;
        if (cnt==1) puts ("Impossible");
        else puts ("2");
    }
    else {
        int x=1, r=l/2;
        int last=r;
        while (check (x, r) && r%2==0) {
            last=r;
            r=r/2;
        }
        if (check (x, r)) puts ("2");
        else puts ("1");//hi,grandson
    }
    return 0;
}
// mooboooombomboomobmmmboombmooboooombomboomobmmmboom


#include<bits/stdc++.h>
using namespace std;
string s;
void check(int x){
	if(x!=0){
		int cn=0;
		for(int i=0;i<(x>>1);i++)
			if(s[i]!=s[x-i-1]){
				cn=1;
				break;
			}
		if(cn){
			printf("1");
			exit(0);
		}
		if(x&1){
			printf("2");
			exit(0);
		}
		check(x>>1);
	}
}
int main(){
	cin>>s;
	int l=s.size(),cn=0;
	for(int i=0;i<=l;i++)
		if(s[i]==s[0]) cn++;
	if(cn==l || cn==l-1){
		printf("Impossible");
		return 0;
	}
	if(l&1){
		printf("2");
		return 0;
	}
	else{
		check(l>>1);
		printf("Impossible");
		return 0;
	}
}


#include<bits/stdc++.h>
using namespace std;
string s;
void check(int x){
	if(x!=0){
		int cn=0;
		for(int i=0;i<(x>>1);i++)
			if(s[i]!=s[x-i-1]){
				cn=1;
				break;
			}
		if(cn){
			printf("1");
			exit(0);
		}
		if(x&1){
			printf("2");
			exit(0);
		}
		check(x>>1);
	}

}
int main(){
	cin>>s;
	int l=s.size(),cn=0;
	for(int i=0;i<=(l>>1);i++)
		if(s[i]==s[0]) cn++;
	if(cn==(l>>1)+1){ printf("Impossible"); return 0; }

	if(l&1){ printf("2"); return 0; }
	else{ check(l); printf("1"); return 0; }
}


#include<bits/stdc++.h>
using namespace std;
string s;
void check(int x){
	if(x!=0){
		int cn=0;
		for(int i=0;i<(x>>1);i++)
			if(s[i]!=s[x-i-1]){
				cn=1;
				break;
			}
		if(cn){
			printf("1");
			exit(0);
		}
		if(x&1){
			printf("2");
			exit(0);
		}
		check(x>>1);
	}
}
int main(){
	cin>>s;
	int l=s.size(),cn=0;
	for(int i=0;i<=(l>>1);i++)
		if(s[i]==s[0]) cn++;
	if(cn==(l>>1)+1){ printf("Impossible"); return 0; }

	if(l&1){ printf("2"); return 0; }
	else{ check(l); printf("Impossible"); return 0; }
}


#include<bits/stdc++.h>
using namespace std;
string s;
void check(int x){
	if(x!=0){
		if(x&1){
			printf("Impossible");
			exit(0);
		}
		int cn=0;
		for(int i=0;i<=(x>>1);i++)
			if(s[i]!=s[x-i]){
				cn=1;
				break;
			}
		if(cn){
			printf("1");
			exit(0);
		}
		else check(x>>1);
	}

}
int main(){
	cin>>s;
	int l=s.size();
	if(l&1){
		int cn=0;
		for(int i=0;i<=(l>>1);i++)
			if(s[i]!=s[0]){
				cn=1;
				break;
			}
		if(!cn){
			printf("Impossible");
			return 0;
		}
		printf("2");
		return 0;
	}
	else{
		l>>=1;
		check(l);
		printf("Impossible");
		return 0;
	}
}


#include<bits/stdc++.h>
using namespace std;
string s;
void check(int x){
	if(x!=0){
		int cn=0;
		for(int i=0;i<=(x>>1);i++)
			if(s[i]!=s[x-i]){
				cn=1;
				break;
			}
		if(cn){
			printf("1");
			exit(0);
		}
		if(x&1){
			printf("2");
			exit(0);
		}
		check(x>>1);
	}

}
int main(){
	cin>>s;
	int l=s.size();
	if(l&1){
		int cn=0;
		for(int i=0;i<=(l>>1);i++)
			if(s[i]!=s[0]){
				cn=1;
				break;
			}
		if(!cn){
			printf("Impossible");
			return 0;
		}
		printf("2");
		return 0;
	}
	else{
		l>>=1;
		check(l);
		printf("1");
		return 0;
	}
}


#include<bits/stdc++.h>
using namespace std;
int k,n,c[1000],f[1000][1000];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>c[i];
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=k;j>=0;j--)
		for(int kk=k;kk>=0;kk--)
		{
			if(j>=c[i]) f[j][kk]=max(f[j][kk],f[j-c[i]][kk]);
			if(kk>=c[i]) f[j][kk]=max(f[j][kk],f[j][kk-c[i]]);
		}
	}
	int ans=0;
	for(int i=0;i<=k;i++) if(f[k][i]) ans++;
	cout<<ans<<"\n";
	for(int i=0;i<=k;i++) if(f[k][i]) cout<<i<<" ";
	return 0;
 }


#include <cstdio>
#include <vector>
using namespace std;
bool dp[505][505][505];
vector<int> ans;
int main()
{
    int n,k,c,t=0;
    scanf("%d %d",&n,&k);
    dp[0][0][0]=1;
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&c);
        for (int j=0;j<=500;j++)
        {
            for (int p=0;p<=j&&p<=k;p++)
            {
                if (dp[i-1][j][p] || j>=c&&dp[i-1][j-c][p] || p>=c&&dp[i-1][j-c][p-c]) dp[i][j][p]=1;
            }
        }
    }
    for (int i=0;i<=k;i++)
    {
        if (dp[n][k][i])
        {
            ans.push_back(i);
        }
    }
    int l=ans.size();
    printf("%d\n",l);
    for (int i=0;i<l;i++) printf("%d ",ans[i]);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define Nmx 510
using namespace std;

int cnt=1,ans[Nmx],top;
bool f[Nmx];
int c[Nmx],suml[Nmx],n,k;
bool x[Nmx]={1};

void com(int sum,int t){
	if(t>top) return;
	for(int i=1;i<=top;++i){
		if(f[i]) continue;
		f[i]=1;sum+=ans[i];
		if(!x[sum]){
			cnt++;x[sum]=1;
		}
		com(sum,t+1);
		f[i]=0;sum-=ans[i];
	}
}

void dfs(int cur,int sum){
	if(sum>k) return;
	if(sum==k){
		com(0,0);
		/*
		for(int i=1;i<=top;++i)
		 printf("%d ", ans[i]);
		printf("\n");
		return;*/
	}
	if(suml[cur]<k) return;
	for(int i=cur;i<=n;++i){
		ans[++top]=c[i];
		dfs(i+1,sum+c[i]);
		ans[top--]=0;
	}
	return;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;++i){
		scanf("%d", &c[i]);
	}
	sort(c+1,c+n+1);
	for(int i=n;i>=1;--i)
	 suml[i]=suml[i+1]+c[i];
	dfs(1,0);
	printf("%d\n", cnt);
	for(int i=0;i<=Nmx;++i)
	 if(x[i]) printf("%d ",i);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,c,ans,dp[1010][1010];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d%d",&n,&k);
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&c);
		for(int i=k;i>=0;i--){
			for(int j=k;j>=0;j--){
				if(dp[i][j])dp[i+c][j]=dp[i][j+c]=1;
			}
		}
	}
	for(int i=0;i<=k;i++){
		if(dp[i][k-i])ans++;
	}
	printf("%d\n",ans);
	for(int i=0;i<=k;i++){
		if(dp[i][k-i])printf("%d ",i);
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
/*

*/


#include<bits/stdc++.h>
using namespace std;
#define maxn 505
int x,n,kk;
bool dp[maxn][maxn][maxn],vis[maxn][maxn],ans[maxn];
int main()
{
    scanf("%d%d",&n,&kk);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&x);
        for(int j=0;j<=kk;j++)
        {
            vis[i][j]=vis[i-1][j];
            for(int k=0;k<=kk;k++)
                dp[i][j][k]=dp[i-1][j][k];
        }
        for(int j=0;j<=kk;j++)
        {
            if(vis[i-1][j]&&j+x<=kk)
            {
                vis[i][j+x]=1;
                dp[i][j+x][x]=1;
                for(int k=0;k<=kk;k++)
                {
                    if(dp[i-1][j][k])
                    {
                        if(k+x<=kk)
                            dp[i][j+x][k+x]=1;
                        dp[i][j+x][k]=1;
                    }
                }
            }
        }
        vis[i][x]=1;
        dp[i][x][x]=1;
    }
    int cnt=1;
    ans[0]=1;
    for(int k=0;k<=kk;k++)
    {
        if(dp[n][kk][k])
        {
            if(ans[k]==0)
                    cnt++;
            ans[k]=1;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<=kk;i++)
    {
        if(ans[i])
            printf("%d ",i);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 505
int x,dp[maxn][maxn],n,k;
int check(int x)
{
    if(dp[n][k-x]&&k-x!=x)
        return 1;
    if(k-x==x)
    {
        if(dp[n][x]>=2)
            return 1;
        return 0;
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        for(int j=0;j<=k;j++)
            dp[i][j]=dp[i-1][j];

        for(int j=0;j<=k;j++)
        {
            if(dp[i-1][j]&&j+x<=k)
                dp[i][j+x]++;
        }
        if(x<=k)
            dp[i][x]++;
    }
    dp[n][0]=1;
    for(int i=0;i<=k;i++)
    {
        if(check(i))
            printf("%d ",i);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 505
int x,n,kk;
bool dp[maxn][maxn][maxn],vis[maxn][maxn],ans[maxn];
int main()
{
    scanf("%d%d",&n,&kk);
    vis[0][0]=1;
    dp[0][0][0]=1;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&x);
        for(int j=0;j<=kk;j++)
        {
            vis[i][j]=vis[i-1][j];
            for(int k=0;k<=kk;k++)
                dp[i][j][k]=dp[i-1][j][k];
        }
        for(int j=0;j<=kk;j++)
        {
            if(vis[i-1][j]&&j+x<=kk)
            {
                vis[i][j+x]=1;
                dp[i][j+x][x]=1;
                for(int k=0;k<=kk;k++)
                {
                    if(dp[i-1][j][k])
                    {
                        if(k+x<=kk)
                            dp[i][j+x][k+x]=1;
                        dp[i][j+x][k]=1;
                    }
                }
            }
        }
       // vis[i][x]=1;
        //dp[i][x][x]=1;
    }
    int cnt=1;
    ans[0]=1;
    for(int k=0;k<=kk;k++)
    {
        if(dp[n][kk][k])
        {
            if(ans[k]==0)
                    cnt++;
            ans[k]=1;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<=kk;i++)
    {
        if(ans[i])
            printf("%d ",i);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 505
int x,dp[maxn][maxn],n,k;
int check(int x)
{
    if(dp[n][k-x]&&k-x!=x&&dp[n][x])
        return 1;
    if(k-x==x)
    {
        if(dp[n][x]>=2)
            return 1;
        return 0;
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        for(int j=0;j<=k;j++)
            dp[i][j]=dp[i-1][j];

        for(int j=0;j<=k;j++)
        {
            if(dp[i-1][j]&&j+x<=k)
                dp[i][j+x]++;
        }
        if(x<=k)
            dp[i][x]++;
    }
    dp[n][0]=1;
    for(int i=0;i<=k;i++)
    {
        if(check(i))
            printf("%d ",i);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 505
int x,dp[maxn][maxn],n,k;
vector<int> ans;
int check(int x)
{
    if(dp[n][k-x]&&k-x!=x&&dp[n][x])
        return 1;
    if(k-x==x)
    {
        if(dp[n][x]>=2)
            return 1;
        return 0;
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        for(int j=0;j<=k;j++)
            dp[i][j]=dp[i-1][j];

        for(int j=0;j<=k;j++)
        {
            if(dp[i-1][j]&&j+x<=k)
                dp[i][j+x]++;
        }
        if(x<=k)
            dp[i][x]++;
    }
    dp[n][0]=1;
    int cnt=0;
    for(int i=0;i<=k;i++)
    {
        if(check(i))
        {
            cnt++;
            ans.push_back(i);
        }
    }
int    len=ans.size();
    printf("%d\n",len);
    for(int i=0;i<len;i++)
    {
        printf("%d ",ans[i]);
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll n, k;
vl cs;

vector<vector<vector<bool>>> mem1;
vector<vector<vector<bool>>> mem2;

bool dp(ll i, ll s, ll r) {
    if (s < 0 || r < 0) return false;
    if (mem1[i][s][r]) return mem2[i][s][r];

    if (i >= n) return s==0 && r == 0;

    bool res = dp(i+1, s-cs[i], r-cs[i]) ||
        dp(i+1, s-cs[i], r) ||
        dp(i+1, s, r);
    mem1[i][s][r] = true;
    mem2[i][s][r] = res;
    return res;
}
int main(){ cin.sync_with_stdio(0);
     cin >> n >> k;
     cs.resize(n);
     FOR(i,0,n) cin >> cs[i];

     mem1.assign(n+1, vector<vb>(k+1, vb(k+1, false)));
     mem2.assign(n+1, vector<vb>(k+1, vb(k+1, false)));

     vl res;
     FOR(r, 0, k+1) {
         if (dp(0, k, r)) res.pb(r);
     }
     cout << sz(res) << endl;
     for (ll val : res) {
         cout << val << " ";
     }
     cout << endl;
} //cin.tie(0) bei schnellem Wechseln


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll n, k;
vl cs;

vector<vector<vector<bool>>> mem;

set<ll> res;

void dp(ll i, ll s, ll r) {
    if (s < 0) return;
    if (mem[i][s][r]) return;
    mem[i][s][r] = true;
    if (s == 0) {
        res.insert(r);
        return;
    }
    if (i >= n) return;

    dp(i+1, s-cs[i], r+cs[i]);
    dp(i+1, s-cs[i], r);
    dp(i+1, s, r);
}
int main(){ cin.sync_with_stdio(0);
     cin >> n >> k;
     cs.resize(n);
     FOR(i,0,n) cin >> cs[i];

     mem.assign(n+1, vector<vb>(k+1, vb(k+1, false)));
     dp(0, k, 0);

     cout << sz(res) << endl;
     for (ll val : res) {
         cout << val << " ";
     }
     cout << endl;
} //cin.tie(0) bei schnellem Wechseln


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll n, k;
vl cs;

vector<vector<vector<bool>>> mem;

set<ll> res;

void dp(ll i, ll s, ll r) {
    if (s < 0) return;
    if (mem[i][s][r]) return;
    mem[i][s][r] = true;
    if (s == 0) {
        res.insert(r);
        return;
    }
    if (i >= n) return;

    dp(i+1, s-cs[i], r+cs[i]);
    dp(i+1, s-cs[i], r);
    dp(i+1, s, r);
}
int main(){ cin.sync_with_stdio(0);
     cin >> n >> k;
     cs.resize(n);
     FOR(i,0,n) cin >> cs[i];

     mem.assign(n+1, vector<vb>(k+1, vb(k+1, false)));
     dp(0, k, 0);

     for (ll val : res) {
         cout << val << " ";
     }
     cout << endl;
} //cin.tie(0) bei schnellem Wechseln


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll n, k;
vl cs;

/*
vector<vector<vector<bool>>> mem1;
vector<vector<vector<bool>>> mem2;

bool dp(ll i, ll s, ll r) {
    if (s < 0 || r < 0) return false;
    if (mem1[i][s][r]) return mem2[i][s][r];

    if (i >= n) return s==0 && r == 0;

    bool res = dp(i+1, s-cs[i], r-cs[i]) ||
        dp(i+1, s-cs[i], r) ||
        dp(i+1, s, r);
    mem1[i][s][r] = true;
    mem2[i][s][r] = res;
    return res;
}
*/
int main(){ cin.sync_with_stdio(0);
     cin >> n >> k;
     cs.resize(n);
     FOR(i,0,n) cin >> cs[i];

     vector<vector<vector<bool>>> mem(2, vector<vector<bool>>(505, vb(505)));

     mem[1][0][0] = 1;
     FOR(i, 0, n) {
         int now = i % 2;
         int last = 1 - now;
         FOR(j, 0, k+1) {
             FOR(y, 0, j+1) {
                 mem[now][j][y] = mem[last][j][y];
                 if (j >= cs[i]) {
                     mem[now][j][y] = mem[last][j-cs[i]][y] || mem[now][j][y];
                     if (y >= cs[i]) mem[now][j][y] = mem[now][j][y] || mem[last][j-cs[i]][y-cs[i]];
                 }
             }
         }
     }

     vl res;
     FOR(r, 0, k+1) {
         if(mem[1-(n%2)][k][r]) res.pb(r);
         //if (dp(0, k, r)) res.pb(r);
     }
     cout << sz(res) << endl;
     for (ll val : res) {
         cout << val << " ";
     }
     cout << endl;
} //cin.tie(0) bei schnellem Wechseln


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

void dfs(int u) {
	used[u] = true;
	for (auto v : from[u]) {

			temp.push_back(v);
		if (!used[u - c[v]]) {

			dfs(u - c[v]);
		}
	}
}
bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	for (int i = 0; i < n; i++) {
		if (pt < (int)temp.size() && i == temp[pt]) {
			pt++;
			continue;
		}
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		temp.emplace_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;
	res.emplace_back(0);

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

	dfs(k);

	sort(temp.begin(), temp.end());
	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i <= k / 2; i++) if (can[i] && can[k - i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

void dfs(int u) {
	used[u] = true;
	for (auto v : from[u]) {

			temp.push_back(v);
		if (!used[u - c[v]]) {

			dfs(u - c[v]);
		}
	}
}
bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	for (int i = 0; i < n; i++) {
		if (pt < (int)temp.size() && i == temp[pt]) {
			pt++;
			continue;
		}
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		if (find(temp.begin(), temp.end(), v) != temp.end()) continue;
		temp.push_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
	return false;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;
	res.emplace_back(0);

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

//	dfs(k);

//	sort(temp.begin(), temp.end());
//	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i <= k / 2; i++) if (can[i] && can[k - i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

void dfs(int u) {
	used[u] = true;
	for (auto v : from[u]) {

			temp.push_back(v);
		if (!used[u - c[v]]) {

			dfs(u - c[v]);
		}
	}
}
bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	for (int i = 0; i < n; i++) {
		if (pt < (int)temp.size() && i == temp[pt]) {
			pt++;
			continue;
		}
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		temp.emplace_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
	return false;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;
	res.emplace_back(0);

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

//	dfs(k);

//	sort(temp.begin(), temp.end());
//	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i < k; i++) if (can[i] && can[k - i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	sort(temp.begin(), temp.end());

	for (int i = 0; i < n; i++) {
		if (find(temp.begin(), temp.end(), i) != temp.end()) continue;
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		if (find(temp.begin(), temp.end(), v) != temp.end()) continue;
		temp.push_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
	return false;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

//	dfs(k);

//	sort(temp.begin(), temp.end());
//	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i <= k / 2; i++) if (can[i] && can[k - i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


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

int n, k;
bool dp[501][501][501];

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

	int x;

	dp[0][0][0] = true;

	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);

		for (int j = 0; j <= k; j++) {
			for (int l = 0; l <= k; l++) {
				dp[i][j][l] |= dp[i - 1][j][l];
				if (j - x >= 0 && l - x >= 0) dp[i][j][l] |= dp[i - 1][j - x][l - x];
				if (j - x >= 0) dp[i][j][l] |= dp[i - 1][j - x][l];
			}
		}
	}

	vector<int> res;

	for (int i = 0; i <= k; i++) if (dp[n][k][i]) res.emplace_back(i);

	printf("%d\n", res.size());

	for (auto u : res) printf("%d ", u);

	puts("");

	return 0;
}


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

void dfs(int u) {
	used[u] = true;
	for (auto v : from[u]) {

			temp.push_back(v);
		if (!used[u - c[v]]) {

			dfs(u - c[v]);
		}
	}
}
bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	sort(temp.begin(), temp.end());

	for (int i = 0; i < n; i++) {
		if (pt < (int)temp.size() && i == temp[pt]) {
			pt++;
			continue;
		}
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		if (find(temp.begin(), temp.end(), v) != temp.end()) continue;
		temp.push_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
	return false;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;
	res.emplace_back(0);

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

//	dfs(k);

//	sort(temp.begin(), temp.end());
//	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i <= k / 2; i++) if (can[i] && can[k - i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


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

int n, k;
int c[555];
vector<int> par[555];
bool can[555], used[555];
int cnt[555];
vector<int> from[555], res, temp;

bool f(int wtf) {
	bool diu[555];
	memset(diu, false, sizeof(diu));

	diu[0] = true;

	int pt = 0;

	sort(temp.begin(), temp.end());

	for (int i = 0; i < n; i++) {
		if (find(temp.begin(), temp.end(), i) != temp.end()) continue;
		for (int j = wtf; j >= c[i]; j--) {
			diu[j] |= diu[j - c[i]];
		}
	}

	return diu[wtf];
}
bool go(int u, int wtf) {
	if (u == 0) {
		return f(wtf);
	}

	for (auto v : from[u]) {
		if (find(temp.begin(), temp.end(), v) != temp.end()) continue;
		temp.push_back(v);
		if (go(u - c[v], wtf)) return true;
		temp.pop_back();
	}
	return false;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) scanf("%d", &c[i]), cnt[c[i]]++;

	can[0] = true;

	for (int i = 0; i < n; i++) {
		for (int j = k; j >= c[i]; j--) {
			if (can[j - c[i]]) {
				can[j] = true;
			//	res.emplace_back(c[i]);
			//	res.emplace_back(j);
				from[j].emplace_back(i);
			}
		}
	}

//	dfs(k);

//	sort(temp.begin(), temp.end());
//	temp.erase(unique(temp.begin(), temp.end()), temp.end());

	res.emplace_back(0);
	res.emplace_back(k);
	for (int i = 1; i <= k / 2; i++) if (can[i]) {
		temp.clear();
		if (go(i, k - i)) res.emplace_back(i), res.emplace_back(k - i);
	}

	sort(res.begin(), res.end());
	res.erase(unique(res.begin(), res.end()), res.end());
	printf("%d\n", (int)res.size());
	for (auto u : res) printf("%d\n", u);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
bool dp[505][505][505];
int c[555];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i - 1][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i - 1][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	for (int x : pas){
		printf("%d\n", x);
		putchar(' ');
	}
	printf("%d\n");

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
bool dp[505][505][505];
int c[505];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	printf("%d\n", pas.size());
	for (int x : pas){
		printf("%d", x);
		putchar(' ');
	}
	printf("\n");
	//system("pause");
	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
ll LP[SZ + 1];
vector<ll>pr;
void SV(){
	for (int i = 2; i <= SZ; i++){
		if (LP[i] == 0){
			LP[i] = i;
			pr.push_back(i);
		}

		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
			LP[i*pr[j]] = pr[j];
		}
	}

}

int tst;
int x;
int dp[555][555][555];
int c[555];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i - 1][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i - 1][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	for (int x : pas){
		printf("%d\n", x);
		putchar(' ');
	}
	printf("%d\n");

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
bool dp[505][505][505];
int c[505];
int main() {
	scanf("%d %d", &N, &M);

	for (int i = 0; i < N; i++){
		scanf("%d", &c[i]);
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	printf("%d\n", pas.size());
	for (int x : pas){
		printf("%d", x);
		putchar(' ');
	}
	printf("\n");
	//system("pause");
	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
void SV(){
	for (int i = 2; i <= SZ; i++){
		if (LP[i] == 0){
			LP[i] = i;
			pr.push_back(i);
		}

		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
			LP[i*pr[j]] = pr[j];
		}
	}

}

int tst;
int x;
int dp[505][505][505];
int c[555];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i - 1][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i - 1][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	for (int x : pas){
		printf("%d\n", x);
		putchar(' ');
	}
	printf("%d\n");

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
bool dp[505][505][505];
int c[505];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	printf("%d\n", pas.size());
	for (int x : pas){
		printf("%d", x);
		putchar(' ');
	}
	printf("%d\n");
	//system("pause");
	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}
int x;
bool dp[505][505][505];
int c[505];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	printf("%d\n", pas.size());
	for (int x : pas){
		printf("%d", x);
		putchar(' ');
	}
	printf("\n");
	//system("pause");
	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
int dp[505][505][505];
int c[555];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i - 1][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i - 1][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	for (int x : pas){
		printf("%d\n", x);
		putchar(' ');
	}
	printf("%d\n");

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPP(i,n)for(int i=1;i<=n;i++)
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ll long long
using namespace std;

// faster than scanf
int readInt() {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch - '0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result * 10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

const int NN = 170;
#define MOD 1000000007
//dig three six nine

//ll dp[52][52][52][52];

const int SZ = 200;
int N, M;
vector<int>pas;
//ll LP[SZ + 1];
vector<ll>pr;
//void SV(){
//	for (int i = 2; i <= SZ; i++){
//		if (LP[i] == 0){
//			LP[i] = i;
//			pr.push_back(i);
//		}
//
//		for (int j = 0; j < pr.size() && pr[j] <= LP[i] && i*pr[j] <= SZ; j++){
//			LP[i*pr[j]] = pr[j];
//		}
//	}
//
//}

int tst;
int x;
bool dp[505][505][505];
int c[505];
int main() {

	N = readInt();
	M = readInt();

	for (int i = 0; i < N; i++){
		c[i] = readInt();
	}
	dp[0][0][0] = 1;
	dp[0][0][c[0]] = 1;
	dp[0][c[0]][0] = 1;
	for (int i = 1; i < N; i++){
		dp[i][0][0] = 1;
		for (int j = 0; j <= M; j++){
			for (int k = 0; k <= M; k++){
				if (c[i] <= j){
					dp[i][j][k] = max(dp[i - 1][j - c[i]][k], dp[i - 1][j][k]);
				}
				if (c[i] <= k){
					dp[i][j][k] = max(dp[i - 1][j][k - c[i]], dp[i - 1][j][k]);
				}
				dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j][k]);
			}
		}
	}

	for (int i = 0; i <= M; i++){
		if (dp[N - 1][i][M - i])pas.push_back(i);
	}

	printf("%d\n", pas.size());
	for (int x : pas){
		printf("%d", x);
		putchar(' ');
	}
	printf("%d\n");
	//system("pause");
	return 0;

}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#define CLR(x) memset(x,0,sizeof(x))
#define OFF(x) memset(x,-1,sizeof(x))
#define MEM(x,a) memset((x),(a),sizeof(x))
#define BUG cout << "I am here" << endl
#define lookln(x) cout << #x << "=" << x << endl
#define SI(a) scanf("%d", &a)
#define SII(a,b) scanf("%d%d", &a, &b)
#define SIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
const int INF_INT = 0x3f3f3f3f;
const long long INF_LL = 0x7f7f7f7f;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
typedef long long  ll;
using namespace std;

int n, k;
int c[550];
int dp[2][555][555];

int main(int argc, char const *argv[]) {
#ifdef LOCAL
	freopen("C:\\Users\\john\\Desktop\\in.txt", "r", stdin);
	// freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);
#endif
	while (SII(n, k) == 2) {
		for (int i = 1; i <= n; i++)
			SI(c[i]);
		CLR(dp);
		dp[0][0][0] = 1;
		for (int i = 1; i <= n; i++) {
			int now = i % 2;
			int last = now ^ 1;
			for (int j = 0; j <= k; j++) {
				for (int s = 0; s <= j; s++) {
					dp[now][j][s] |= dp[last][j][s];
					if (j >= c[i]) dp[now][j][s] |= dp[last][j - c[i]][s];
					if (s >= c[i]) dp[now][j][s] |= dp[last][j - c[i]][s - c[i]];
				}
			}
		}
		vector<int> ans;
		for (int i = 0; i <= k; i++)
			if (dp[n % 2][k][i]) ans.push_back(i);
		cout << (int)ans.size() << endl;
		for (int i = 0; i < ans.size(); i++)
			cout << ans[i] << ' ';
		cout << endl;
	}
	return 0;
}


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

  if( sub-v[x] >= 0 && sum-v[x] >= 0 )
    ret |= rec( x-1, sub-v[x], sum-v[x] );
  if( sum-v[x] >= 0 )
    ret |= rec( x-1, sub, sum-v[x] );
  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 << ' ';
}