public class BichromePainting
{
int n;
char[][] board;
{
n = _board.length;
board = new char[n][n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
board[i][j] = _board[i].charAt(j);
while(true)
{
boolean find = false;
for(int i = 0; i+k <= n; i++)
for(int j = 0; j+k <= n; j++)
{
boolean haveBlack = false;
boolean haveWhite = false;
for(int di = 0; di < k; di ++)
for(int dj = 0; dj < k; dj ++)
{
if(board[i+di][j+dj] == 'W')
haveWhite = true;
if(board[i+di][j+dj] == 'B')
haveBlack = true;
}
if(haveBlack != haveWhite)
{
find = true;
for(int di = 0; di < k; di ++)
for(int dj = 0; dj < k; dj ++)
board[i+di][j+dj] = '?';
}
}
if(!find)
break;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(board[i][j] == 'B')
return "Impossible";
return "Possible";
}
}
cHVibGljIGNsYXNzIEJpY2hyb21lUGFpbnRpbmcKewoKCWludCBuOwoJY2hhcltdW10gYm9hcmQ7CgoJcHVibGljIFN0cmluZyBpc1RoYXRQb3NzaWJsZShTdHJpbmdbXSBfYm9hcmQsIGludCBrKQoJewoJCW4gPSBfYm9hcmQubGVuZ3RoOwoJCWJvYXJkID0gbmV3IGNoYXJbbl1bbl07CgkJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykKCQkJZm9yKGludCBqID0gMDsgaiA8IG47IGorKykKCQkJCWJvYXJkW2ldW2pdID0gX2JvYXJkW2ldLmNoYXJBdChqKTsKCQl3aGlsZSh0cnVlKQoJCXsKCQkJYm9vbGVhbiBmaW5kID0gZmFsc2U7CgkJCWZvcihpbnQgaSA9IDA7IGkrayA8PSBuOyBpKyspCgkJCQlmb3IoaW50IGogPSAwOyBqK2sgPD0gbjsgaisrKQoJCQkJewoJCQkJCWJvb2xlYW4gaGF2ZUJsYWNrID0gZmFsc2U7CgkJCQkJYm9vbGVhbiBoYXZlV2hpdGUgPSBmYWxzZTsKCQkJCQlmb3IoaW50IGRpID0gMDsgZGkgPCBrOyBkaSArKykKCQkJC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