#include #include using namespace std; #define rep(i,s,n) for (int i=s;i>S; int n=S.length(); int bef=S[0]; bool kaibun=true,same=true; rep(i,0,n/2){ if(S[i]!=S[n-1-i]){ kaibun=same=false; break; } if(bef!=S[i] || bef!=S[n-1-i]){ same=false; } bef=S[i]; } if((n%2)&&bef!=S[n/2])same=false; if(same){ if(n>1) cout<<0; else cout<<-1; }else if(kaibun){ if(n>3) cout<