Ilya and tic-tac-toe game

  Ilya and tic-tac-toe game

Ilya is an experienced player in tic-tac-toe on the4 × 4field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.

The rules of tic-tac-toe on the4 × 4field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first getsthree of his signs in a row next to each other(horizontal, vertical or diagonal).

Input

The tic-tac-toe position is given in four lines.

Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letterx), or 'o' (lowercase English lettero). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.

Output

Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.

Example

Input

xx..

.oo.

x...

oox.

Output

YES

Input

x.ox

ox..

x.o.

oo.x

Output

NO

Input

x..x

..oo

o...

x.xo

Output

YES

Input

o.x.

o...

.x..

ooxx

Output

NO

Note

In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.

In the second example it wasn't possible to win by making single turn.

In the third example Ilya could have won by placing X in the last row between two existing Xs.

In the fourth example it wasn't possible to win by making single turn.

#include#includeusing namespace std;

int b[6][6];

int main()

{

char a[4][4];

int k=0,i,j;

memset(b,-1,sizeof(b));

for(i = 0; i < 4; i++) scanf("%s", a[i]);

for(i = 1; i <= 4; i++)//转换地图

{

for(j = 1; j <= 4; j++)

{

if(a[i-1][j-1]=='x')

b[i][j]=1;

if(a[i-1][j-1]=='.')

b[i][j]=0;

}

}

for(i=1;i<=4;i++)

{

for(j=1;j<=4;j++)//以一点为中心判断四种情况

{

if(b[i][j]+b[i-1][j]+b[i+1][j]==2)

k=1;

if(b[i][j]+b[i-1][j-1]+b[i+1][j+1]==2)

k=1;

if(b[i][j]+b[i][j-1]+b[i][j+1]==2)

k=1;

if(b[i][j]+b[i-1][j+1]+b[i+1][j-1]==2)

k=1;

}

}

if(k==1)

printf("YES\n");

else

printf("NO\n");

return 0;

}

你可能感兴趣的:(Ilya and tic-tac-toe game)