import sequtils,strutils var W,H : int flag : array[0..101,array[0..101,bool]] stage : array[0..101,array[0..101,int]] line : seq[int] D = [[1,0],[0,1],[-1,0],[0,-1]] ans : bool x,y,cnt : int (W,H) = stdin.readline.split.map(parseInt) for h in 1..H: line = stdin.readline.split.map(parseInt) for i,l in line: stage[h][i + 1] = l proc tansaku(a,b : int)= if ((a,b) == (y,x) and cnt > 2) or ans == true: ans = true return for d in D: if (flag[a + d[0]][b + d[1]] == false and stage[a + d[0]][b + d[1]] == stage[a][b]): flag[a + d[0]][b + d[1]] = true cnt += 1 tansaku(a + d[0],b + d[1]) cnt -= 1 flag[a + d[0]][b + d[1]] = false block A: for i in 1..H: for j in 1..W: (y,x) = (i,j) cnt = 0 tansaku(i,j) if ans: break A if ans: echo "possible" else: echo "impossible"