poj1753
#include<iostream>
using namespace std;
int chess;
int step;
bool Flag=false;
void upset(int i)
{
chess=chess^(0x1<<i);
if(i-1>=0&&i%4)
chess=chess^(0x1<<(i-1));
if(i-4>=0)
chess=chess^(0x1<<(i-4));
if(i+1<=15&&(i+1)%4)
chess=chess^(0x1<<(i+1));
if(i+4<=15)
chess=chess^(0x1<<(i+4));
}
void Init()
{
chess=0;
char temp;
for(int i=0;i<16;i++)
{
cin>>temp;
if(temp=='b')
{
chess=chess|0x1<<i;
}
}
}
void dfs(int i,int deep)
{
if(step==deep)
{
Flag=(chess==65535||chess==0);
return;
}
if(i>15||Flag)return;
upset(i);
dfs(i+1,deep+1);
if(!Flag)
{
upset(i);
dfs(i+1,deep);
}
}
int main()
{
Init();
for(step=0;step<=16;step++)
{
dfs(0,0);
if(Flag)
break;
}
if(!Flag)cout<<"Impossible"<<endl;
else cout<<step<<endl;
return 0;
}