Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. 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 the 4 × 4 field 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 gets three 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 letter x), or 'o' (lowercase English letter o). 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.


-----Examples-----
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.

Difficulty: interview

Starter code:

Solutions:
def chk(l):
	for i in range(4):
		for j in range(2):
			if l[i][j]==l[i][j+1]==l[i][j+2]=='x':
				return True
	for i in range(2):
		for j in range(4):
			if l[i][j]==l[i+1][j]==l[i+2][j]=='x':
				return True
	for i in range(2):
		for j in range(2):
			if l[i][j]==l[i+1][j+1]==l[i+2][j+2]=='x':
				return True
	for i in range(2):
		for j in range(2, 4):
			if l[i][j]==l[i+1][j-1]==l[i+2][j-2]=='x':
				return True
	return False
a = [list(input()), list(input()), list(input()), list(input())]
for i in range(4):
	for j in range(4):
		if a[i][j] != '.':
			continue
		a[i][j]='x'
		if chk(a):
			print("YES"); return
		a[i][j]='.'
print("NO")


import sys

m = [list(input()) for _ in range(4)]

def trans(m):
    return [[m[0][0], m[1][0], m[2][0], m[3][0]],
            [m[0][1], m[1][1], m[2][1], m[3][1]],
            [m[0][2], m[1][2], m[2][2], m[3][2]],
            [m[0][3], m[1][3], m[2][3], m[3][3]]]

def check(m):
    res = any('xxx' in ''.join(x) for x in m)
    res |= any('xxx' in ''.join(x) for x in trans(m))

    for i in range(1, 3):
        for j in range(1, 3):
            res |= m[i-1][j-1] + m[i][j] + m[i+1][j+1] == 'xxx'
            res |= m[i-1][j+1] + m[i][j] + m[i+1][j-1] == 'xxx'

    return res

for i in range(4):
    for j in range(4):
        if m[i][j] == '.':
            m[i][j] = 'x'
            if check(m):
                print("YES")
                return
            m[i][j] = '.'

print("NO")


a = []
for i in range(4):
	a += [input()]
f = False
for i in range(4):
	for j in range(2):
		f |= a[i][j: j + 3].count('.') == 1 and a[i][j: j + 3].count('o') == 0
for j in range(4):
	for i in range(2):
		f |= ([a[i][j]] + [a[i + 1][j]] + [a[i + 2][j]]).count('.') == 1 and ([a[i][j]] + [a[i + 1][j]] + [a[i + 2][j]]).count('o') == 0
for i in range(2):
	for j in range(2):
		f |= [a[i][j], a[i + 1][j + 1], a[i + 2][j + 2]].count('.') == 1 and [a[i][j], a[i + 1][j + 1], a[i + 2][j + 2]].count('o') == 0
		f |= [a[3 - i][j], a[2 - i][j + 1], a[1 - i][j + 2]].count('.') == 1 and [a[3 - i][j], a[2 - i][j + 1], a[1 - i][j + 2]].count('o') == 0
if f:
	print('YES')
else:
	print('NO')

def tri(ar):
    d={'.':0,'x':0,'o':0}
    for i,j in ar:
        d[a[i][j]]+=1
    if d['.']==1 and d['x']==2:
        ans[0]='YES'
    #print(d)
        
ans=['NO']
a=[input() for i in range(4)]
for i in range(2):
    for j in range(2):
        tri([(i,j),(i+1,j+1),(i+2,j+2)])
    for j in range(2,4):
        tri([(i,j),(i+1,j-1),(i+2,j-2)])
for i in range(4):
    for j in range(2):
        tri([(i,j),(i,j+1),(i,j+2)])
        tri([(j,i),(j+1,i),(j+2,i)])
print(ans[0])



A = []
for _ in range(4):
    A += [list(input())]

found = False

def check(list_of_sigs):
    return list_of_sigs.count('.') == 1 and \
           list_of_sigs.count('x') == 2

for col_offset in range(2):
    for row_offset in range(2):
        found = found or check([A[row_offset][col_offset],
                                A[row_offset + 1][col_offset + 1],
                                A[row_offset + 2][col_offset + 2]])
        found = found or check([A[row_offset][3 - col_offset],
                                A[row_offset + 1][2 - col_offset],
                                A[row_offset + 2][1 - col_offset]])

for col in range(2):
    for row in range(4):
        found = found or check([A[row][col],
                                A[row][col + 1],
                                A[row][col + 2]])

for col in range(4):
    for row in range(2):
        found = found or check([A[row][col],
                                A[row + 1][col],
                                A[row + 2][col]])

if found:
    print("YES")
else:
    print("NO")




n = 4
def check(f):
	nonlocal n
	for i in range(n):
		ok = True
		for j in range(n - 1):
			ok &= f[i][j] == 'x'
		if ok : return ok
		ok = True
		for j in range(1, n):
			ok &= f[i][j] == 'x'
		if ok : return ok
	for i in range(n):
		ok = True
		for j in range(n - 1):
			ok &= f[j][i] == 'x'
		if ok : return ok
		ok = True
		for j in range(1, n):
			ok &= f[j][i] == 'x'
		if ok : return ok
	ok = True
	for i in range(n -1 ):
		ok &= f[i][i] == 'x'
	if ok: return ok
	ok = True
	for i in range(1, n):
		ok &= f[i][i] == 'x'
	if ok: return ok
	if f[1][0] == f[2][1] == f[3][2] == 'x' or f[0][1] == f[1][2] == f[2][3] == 'x': return True
	return f[3][0] == f[2][1] == f[1][2] == 'x' or f[0][3] == f[2][1] == f[1][2] == 'x' or f[2][0] == f[1][1] == f[0][2] == 'x' or f[1][3] == f[2][2] == f[3][1] == 'x'
f = [list(input()) for i in range(n)]
for i in range(n):
	for j in range(n):
		if f[i][j] == '.':
			f[i][j] = 'x'
			if check(f):
				print("YES")
				return
			f[i][j] = '.'
print("NO")


def c(i, j):
    if i < 4 and j < 4 and i >= 0 and j >= 0:
        if a[i][j] == 'x':
            return True
    return False

a = [[x for x in input().strip()] for j in range(4)]
ans = True
for i in range(4):
    for j in range(4):
        if a[i][j] == '.':
            if c(i+1,j) and c(i+2,j):
                ans = False
            if c(i-1,j) and c(i-2,j):
                ans = False
            if c(i+1,j+1) and c(i+2,j+2):
                ans = False
            if c(i-1,j-1) and c(i-2,j-2):
                ans = False
            if c(i,j+1) and c(i,j+2):
                ans = False
            if c(i,j-1) and c(i,j-2):
                ans = False
            if c(i+1,j-1) and c(i+2,j-2):
                ans = False
            if c(i-1,j+1) and c(i-2,j+2):
                ans = False

            if c(i-1,j-1) and c(i+1,j+1):
                ans = False
            if c(i-1,j) and c(i+1,j):
                ans = False
            if c(i-1,j+1) and c(i+1,j-1):
                ans = False
            if c(i,j-1) and c(i,j+1):
                ans = False

if ans:
    print('NO')
else:
    print('YES')

def get_field(i, j, val):
    if i < 0 or j < 0 or i > 3 or j > 3:
        return False
    return d[i][j] == val


def check_field(i, j, c):
    if get_field(i - 2, j, c) and get_field(i - 1, j, c):
        return True
    if get_field(i + 2, j, c) and get_field(i + 1, j, c):
        return True
    if get_field(i, j - 2, c) and get_field(i, j - 1, c):
        return True    
    if get_field(i, j + 2, c) and get_field(i, j + 1, c):
        return True
    if get_field(i - 1, j, c) and get_field(i + 1, j, c):
        return True
    if get_field(i, j - 1, c) and get_field(i, j + 1, c):
        return True
    
    if get_field(i + 2, j + 2, c) and get_field(i + 1, j + 1, c):
        return True    
    if get_field(i - 2, j - 2, c) and get_field(i - 1, j - 1, c):
        return True
    if get_field(i + 2, j - 2, c) and get_field(i + 1, j - 1, c):
        return True    
    if get_field(i - 2, j + 2, c) and get_field(i - 1, j + 1, c):
        return True    
    if get_field(i + 1, j + 1, c) and get_field(i - 1, j - 1, c):
        return True    
    if get_field(i - 1, j + 1, c) and get_field(i + 1, j - 1, c):
        return True

d = [[''] * 4 for i in range(4)]
for i in range(4):
    s = input()
    for j in range(4):
        d[i][j] = s[j]
for i in range(4):
    for j in range(4):
        if d[i][j] == '.':
            if check_field(i, j, 'x'):
                print("YES")
                return
print("NO")

def vaild(i,j):
    per = 1
    per1 = 1
    per2 = 1
    per3 = 1
    for t in range(i-1,-1,-1):
        if A[t][j] == 'x':
            per +=1
        else:
            break
    for t in range(i+1,4):
        if A[t][j] == 'x':
            per+=1
        else:
            break
    if per >= 3:
        return True
    for t in range(j-1,-1,-1):
        if A[i][t] == 'x':
            per1+=1
        else:
            break
    for t in range(j+1,4):
        if A[i][t] == 'x':
            per1+=1
        else:
            break
    if per1 >=3:
        return True
    i1 = i-1
    j1 = j-1
    i2 = i+1
    j2 = j+1
    while (i1>= 0 and j1>=0):
        if A[i1][j1] == 'x':
            i1 -= 1
            j1-=1
            per2+=1
        else:
            break
    while (i2<= 3 and j2<=3):
        if A[i2][j2] == 'x':
            per2+=1
            i2+=1
            j2+=1
        else:
            break   
    if per2>=3:
        return True
    i3 = i-1
    j3 = j+1
    while (i3>= 0 and j3<=3):
        if A[i3][j3] == 'x':
            i3 -= 1
            j3+=1
            per3+=1
        else:
            break
    i4 = i+1
    j4 = j -1
    while (i4<=3 and j4>=0):
        if A[i4][j4] == 'x':
            i4 +=1
            j4 -= 1
            per3+=1
        else:
            break
    if per3 >= 3:
        return True
    return False
A = [0] * 4
for j in range(4):
    A[j] = input()
s = 0
for i in range(4):
    for j in range(4):
        if A[i][j] == '.':
            
            if vaild(i,j):
                s = 1
                break
if s == 1:
    print('YES')
else:
    print('NO')

fields = []
fields.append([ input() for i in range(4)])
fields.append([ '' for i in range(4)])
for i in range(4):
    c = 0
    for j in fields[0][i]:
        fields[1][c] += j
        c += 1
line1 = ''
line2 = ''
for i in range(4):
    line1 += fields[0][i][i]
    line2 += fields[0][i][3 - i]
fields.append([line1, line2])
fields[2].append(fields[0][1][0]+fields[0][2][1]+fields[0][3][2])
fields[2].append(fields[0][0][1]+fields[0][1][2]+fields[0][2][3])
fields[2].append(fields[0][0][2]+fields[0][1][1]+fields[0][2][0])
fields[2].append(fields[0][1][3]+fields[0][2][2]+fields[0][3][1])
for i in fields:
    for j in i:
        if 'x.x' in j or '.xx' in j or 'xx.' in j:
            print('YES')
            return
print('NO')

def check(A):
    for x1 in range(4):
        for y1 in range(4):
            for x2 in range(4):
                for y2 in range(4):
                    for x3 in range(4):
                        for y3 in range(4):
                            if A[x1][y1] == A[x2][y2] == A[x3][y3] == 'x':
                                # print('!')
                                if x1 == x2 == x3 and y1 == y2 + 1 == y3 + 2:
                                    return True
                                if y1 == y2 == y3 and x1 == x2 + 1 == x3 + 2:
                                    return True
                                if x1 == x2 + 1 == x3 + 2 and y1 == y2 + 1 == y3 + 2:
                                    return True
                                if x1 == x2 + 1 == x3 + 2 and y3 == y2 + 1 == y1 + 2:
                                    return True
    return False

A = [0] * 4
for i in range(4):
    A[i] = list(input())
for i in range(4):
    for j in range(4):
        if A[i][j] == '.':
            A[i][j] = 'x'
            # print(A)
            if check(A):
                print('YES')
                return
            A[i][j] = '.'
print('NO')


N = 4
board = [input() for _ in range(4)]
for i in range(N):
    for j in range(N):
        cand = []
        if j + 2 < N:
            cand.append([board[i][j+k] for k in range(3)])
        if i + 2 < N:
            cand.append([board[i+k][j] for k in range(3)])
        if i + 2 < N and j + 2 < N:
            cand.append([board[i+k][j+k] for k in range(3)])
        if i + 2 < N and j - 2 >= 0:
            cand.append([board[i+k][j-k] for k in range(3)])
        for row in cand:
            for k in range(3):
                if all(c == 'x' if i != k else c == '.' for i, c in enumerate(row)):
                    print("YES")
                    quit()
print("NO")


a = [0] * 4
for i in range(4):
    a[i] = input()
t = False
for i in range(4):
    q1 = [a[0][i], a[1][i], a[2][i]]
    q2 = [a[1][i], a[2][i], a[3][i]]
    if (q1.count("x") == 2 and q1.count(".") == 1) or (q2.count("x") == 2 and q2.count(".") == 1):
        t = True  
for i in range(4):
    q3 = [a[i][0], a[i][1], a[i][2]]
    q4 = [a[i][1], a[i][2], a[i][3]]    
    if (q3.count("x") == 2 and q3.count(".") == 1) or (q4.count("x") == 2 and q4.count(".") == 1):
        t = True    
q1 = [a[0][1], a[1][2], a[2][3]]
q2 = [a[1][0], a[2][1], a[3][2]]
q3 = [a[2][0], a[1][1], a[0][2]]
q4 = [a[3][1], a[2][2], a[1][3]]
if (q3.count("x") == 2 and q3.count(".") == 1) or (q4.count("x") == 2 and q4.count(".") == 1):
    t = True  
if (q1.count("x") == 2 and q1.count(".") == 1) or (q2.count("x") == 2 and q2.count(".") == 1):
    t = True
q1 = [a[0][0], a[1][1], a[2][2]]
q2 = [a[1][1], a[2][2], a[3][3]]
q3 = [a[3][0], a[2][1], a[1][2]]
q4 = [a[2][1], a[1][2], a[0][3]]
if (q3.count("x") == 2 and q3.count(".") == 1) or (q4.count("x") == 2 and q4.count(".") == 1):
    t = True  
if (q1.count("x") == 2 and q1.count(".") == 1) or (q2.count("x") == 2 and q2.count(".") == 1):
    t = True
if t:
    print("YES")
else:
    print("NO")

from math import *
from sys import *
from decimal import *

def gcd(a,b):
    if b:
        return gcd(b,a%b)
    return a

mat=[]
for i in range(4):
    mat.append(input())
for st in mat:
    if ("xx." in st) or (".xx" in st) or ("x.x" in st):
        print("YES")
        return
for i in range(4):
    st=""
    for j in range(4):
        st+=mat[j][i]
    if ("xx." in st) or (".xx" in st) or ("x.x" in st):
        print("YES")
        return
for su in range(2,5):
    st=""
    for j in range(max(0,su-3),min(su+1,4)):
        st+=mat[j][su-j]
    if ("xx." in st) or (".xx" in st) or ("x.x" in st):
        print("YES")
        return
for ee in range(-1,2):
    st=""
    for j in range(max(0,-ee),min(4,4-ee)):
        st+=mat[j][j+ee]
    if ("xx." in st) or (".xx" in st) or ("x.x" in st):
        print("YES")
        return
print("NO")    

#!/usr/bin/env python3

b = [list(input().strip()) for _ in range(4)]

r = "NO"

def check(b):
    for i in range(4):
        for j in range(2):
            if b[i][j] == 'x' and b[i][j+1] == 'x' and b[i][j+2] == 'x':
                return True

    for i in range(2):
        for j in range(4):
            if b[i][j] == 'x' and b[i+1][j] == 'x' and b[i+2][j] == 'x':
                return True

    for i in range(2):
        for j in range(2):
            if b[i][j] == 'x' and b[i+1][j+1] == 'x' and b[i+2][j+2] == 'x':
                return True

    for i in range(2):
        for j in range(2, 4):
            if b[i][j] == 'x' and b[i+1][j-1] == 'x' and b[i+2][j-2] == 'x':
                return True

    return False

for i in range(4):
    for j in range(4):
        c = b[i][j]
        if c == '.':
            b[i][j] = 'x'
            if check(b):
                r = "YES"
            b[i][j] = '.'
print(r)


#!/usr/bin/env pypy3
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.1415926535897932
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

l=[]
for i in range(4):
    x=input()
    if 'xx.' in x or '.xx' in x or 'x.x' in x:
        print('YES')
        return
    elif 'ooo' in x:
        print('NO')
        return

    l.append(x)
for i in range(2):
    for j in range(4):
        tate=l[i][j]+l[i+1][j]+l[i+2][j]
        if 'xx.' in tate or '.xx' in tate or 'x.x' in tate:
            print('YES')
            return
        elif 'ooo' in tate:
            print('NO')
            return
        if j>=2:
            y=l[i][j]+l[i+1][j-1]+l[i+2][j-2]
            if 'xx.' in y or '.xx' in y or 'x.x' in y:
                print('YES')
                return
            elif 'ooo' in y:
                print('NO')
                return
        if j<2:
            y=l[i][j]+l[i+1][j+1]+l[i+2][j+2]
            if 'xx.' in y or '.xx' in y or 'x.x' in y:
                print('YES')
                return
            elif 'ooo' in y:
                print('NO')
                return
print('NO')

s =[[] for  i in range(4)]
s[0] = [i for i in input()]
s[1] = [i for i in input()]
s[2] = [i for i in input()]
s[3] = [i for i in input()]
a = 0
for i in range(4):
    for j in range(4):
        if i>1:
            if s[i][j] == '.' and s[i-1][j] == 'x' and s[i-2][j] == 'x':
                print("YES")
                a = 1
                break
            if j>1:
                if s[i][j] == '.' and s[i - 1][j-1] == 'x' and s[i - 2][j-2] == 'x':
                    print("YES")
                    a = 1
                    break
            if j < 2:
                if s[i][j] == '.' and s[i - 1][j+1] == 'x' and s[i - 2][j+2] == 'x':
                    print("YES")
                    a = 1
                    break
        if i < 2:
            if s[i][j] == '.' and s[i+1][j] == 'x' and s[i+2][j] == 'x':
                print("YES")
                a = 1
                break
            if j>1:
                if s[i][j] == '.' and s[i + 1][j-1] == 'x' and s[i + 2][j-2] == 'x':
                    print("YES")
                    a = 1
                    break
            if j < 2:
                if s[i][j] == '.' and s[i + 1][j+1] == 'x' and s[i + 2][j+2] == 'x':
                    print("YES")
                    a = 1
                    break
        if j>1:
            if s[i][j] == '.' and s[i][j - 1] == 'x' and s[i][j - 2] == 'x':
                print("YES")
                a = 1
                break
        if j <2:
            if s[i][j] == '.' and s[i][j + 1] == 'x' and s[i][j + 2] == 'x':
                print("YES")
                a = 1
                break
        if i!= 3 and i !=0:
            if s[i][j] == '.' and s[i+1][j] == 'x' and s[i-1][j] == 'x':
                print("YES")
                a = 1
                break
            if j != 3 and j != 0:
                if s[i][j] == '.' and s[i+1][j + 1] == 'x' and s[i-1][j - 1] == 'x':
                    print("YES")
                    a = 1
                    break
                if s[i][j] == '.' and s[i-1][j + 1] == 'x' and s[i+1][j - 1] == 'x':
                    print("YES")
                    a = 1
                    break
        if j != 3 and j!= 0:
            if s[i][j] == '.' and s[i][j + 1] == 'x' and s[i][j -1] == 'x':
                print("YES")
                a = 1
                break
    if a:
        break
else:
    print("NO")

def check(a):
    for i in range(4):
        if "xxx" in a[i]:
            return True
    if a[1][0] == "x" and a[2][0] == "x" and (a[0][0] == "x" or a[3][0] == "x"):
        return True
    if a[1][1] == "x" and a[2][1] == "x" and (a[0][1] == "x" or a[3][1] == "x"):
        return True
    if a[1][2] == "x" and a[2][2] == "x" and (a[0][2] == "x" or a[3][2] == "x"):
        return True
    if a[1][3] == "x" and a[2][3] == "x" and (a[0][3] == "x" or a[3][3] == "x"):
        return True
    if a[0][2] == a[1][1] == a[2][0] == "x":
        return True
    if a[1][2] == a[2][1] == "x" and (a[3][0] == "x" or a[0][3] == "x"):
        return True
    if a[3][1] == a[2][2] == a[1][3] == "x":
        return True
    if a[0][1] == a[1][2] == a[2][3] == "x":
        return True
    if a[1][1] == a[2][2] == "x" and (a[0][0] == "x" or a[3][3] == "x"):
        return True
    if a[1][0] == a[2][1] == a[3][2] == "x":
        return True
    return False



a = [input() for i in range(4)]
flag = False
for i in range(4):
    for j in range(4):
        if a[i][j] == ".":
            b = a[:]
            str = b[i]
            b[i] = str[:j] + "x" + str[j + 1:]
            if check(b):
                flag = True
if flag:
    print("YES")
else:
    print("NO")


s1 = input()
s2 = input()
s3 = input()
s4 = input()
s5 = s1[0] + s2[0] + s3[0] + s4[0]
s6 = s1[1] + s2[1] + s3[1] + s4[1]
s7 = s1[2] + s2[2] + s3[2] + s4[2]
s8 = s1[3] + s2[3] + s3[3] + s4[3]
s9 = s2[0] + s3[1] + s4[2]
s10 = s1[0] + s2[1] + s3[2] + s4[3]
s11 = s1[1] + s2[2] + s3[3]
s12 = s1[2] + s2[1] + s3[0]
s13 = s1[3] + s2[2] + s3[1] + s4[0]
s14 = s2[3] + s3[2] + s4[1]


f = False
if 'xx.' in s1 or 'xx.' in s2 or 'xx.' in s3 or 'xx.' in s4 or 'xx.' in s5 or 'xx.' in s6 or 'xx.' in s7 or 'xx.' in s8 or 'xx.' in s9 or 'xx.' in s10 or 'xx.' in s11 or 'xx.' in s12 or 'xx.' in s13 or 'xx.' in s14:
    f = True
if 'x.x' in s1 or 'x.x' in s2 or 'x.x' in s3 or 'x.x' in s4 or 'x.x' in s5 or 'x.x' in s6 or 'x.x' in s7 or 'x.x' in s8 or 'x.x' in s9 or 'x.x' in s10 or 'x.x' in s11 or 'x.x' in s12 or 'x.x' in s13 or 'x.x' in s14:
    f = True
if '.xx' in s1 or '.xx' in s2 or '.xx' in s3 or '.xx' in s4 or '.xx' in s5 or '.xx' in s6 or '.xx' in s7 or '.xx' in s8 or '.xx' in s9 or '.xx' in s10 or '.xx' in s11 or '.xx' in s12 or '.xx' in s13 or '.xx' in s14:
    f = True
if f:
    print('YES')
else:
    print('NO')


def has_win(mat, r, c):
    for i in range(-1, 2):
        for j in range(-1, 2):
            if (i == j and i == 0) or (not 0 <= i + r < 4) or (not 0 <= j + c < 4):
                continue
            if mat[r + i][c + j] in ['x', '.']:
                tm = '.' if mat[r + i][c + j] == 'x' else 'x'
                if 0<= r + 2*i < 4 and 0 <= c + 2*j < 4 and mat[r + 2*i][c + 2*j] == tm:
                    return True
    return False

def is_win(mat):
    for i in range(4):
        for j in range(4):
            if mat[i][j] == 'x' and has_win(mat, i, j):
                return True
    return False

def nput(n):
    for i in range(n):
        yield input()

def main():
    mat = [list(l) for l in nput(4)]
    if is_win(mat):
        print("YES")
    else:
        print("NO")

def __starting_point():
    main()

__starting_point()

def myc(a,b,c,d,e,f):
    return str(iph[a][b]+iph[c][d]+iph[e][f])
iph=[]
for i in range(4):
    iph.append(str(input()))
ipv=[]
b=0
for i in range(4):
    ipv.append(str(iph[0][i]+iph[1][i]+iph[2][i]+iph[3][i]))
for i in iph:
    if 'x.x' in i or 'xx.' in i or '.xx' in i:
        b=1
    if 'ooo' in i:
        b=2
        break
if b!=2:
    for i in ipv:
        if 'x.x' in i or 'xx.' in i or '.xx' in i:
            b=1
        if 'ooo' in i:
            b=2
            break
if b!=2:
    ipd=[myc(0,0,1,1,2,2),myc(1,1,2,2,3,3),myc(1,0,2,1,3,2),myc(0,1,1,2,2,3),
         myc(0,2,1,1,2,0),myc(0,3,1,2,2,1),myc(1,2,2,1,3,0),myc(1,3,2,2,3,1)]
    for i in ipd:
        if 'x.x' in i or 'xx.' in i or '.xx' in i and b==0:
            b=1
        if 'ooo' in i:
            b=2
            break

if b==0 or b==2:
    print('NO')
else:
    print('YES')


import sys

rows = [input() for i in range(4)]
cols = []

for j in range(4):
    col = [rows[i][j] for i in range(4)]
    cols.append("".join(col))

diags = []
diags.append("".join([rows[i][i] for i in range(4)]))
diags.append("".join([rows[0][1], rows[1][2], rows[2][3]]))
diags.append("".join([rows[1][0], rows[2][1], rows[3][2]]))
diags.append("".join([rows[i][3-i] for i in range(4)]))
diags.append("".join([rows[0][2], rows[1][1], rows[2][0]]))
diags.append("".join([rows[1][3], rows[2][2], rows[3][1]]))

strs = rows + cols + diags

winstrs = ["xx.", "x.x", ".xx"]

for winstr in winstrs:
    for s in strs:
        if winstr in s:
            print("YES")
            return
print("NO")


def check(a):
    for i in range(4):
        if "xxx" in a[i]:
            return True
    if a[1][0] == "x" and a[2][0] == "x" and (a[0][0] == "x" or a[3][0] == "x"):
        return True
    if a[1][1] == "x" and a[2][1] == "x" and (a[0][1] == "x" or a[3][1] == "x"):
        return True
    if a[1][2] == "x" and a[2][2] == "x" and (a[0][2] == "x" or a[3][2] == "x"):
        return True
    if a[1][3] == "x" and a[2][3] == "x" and (a[0][3] == "x" or a[3][3] == "x"):
        return True
    if a[0][2] == a[1][1] == a[2][0] == "x":
        return True
    if a[1][2] == a[2][1] == "x" and (a[3][0] == "x" or a[0][3] == "x"):
        return True
    if a[3][1] == a[2][2] == a[1][3] == "x":
        return True
    if a[0][1] == a[1][2] == a[2][3] == "x":
        return True
    if a[1][0] == a[2][1] == a[3][2] == "x":
        return True
    if a[1][1] == a[2][2] == "x" and (a[0][0] == "x" or a[3][3] == "x"):
        return True
    return False



a, flag = [input() for i in range(4)], False
for i in range(4):
    for j in range(4):
        if a[i][j] == ".":
            b = a[:]
            str = b[i]
            b[i] = str[:j] + "x" + str[j + 1:]
            if check(b):
                flag = True
if flag:
    print("YES")
else:
    print("NO")


l1 = input()
l2 = input()
l3 = input()
l4 = input()

grid = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]

cross = 0
dots = []
for i in range(0, 4):
  if l1[i] == ".":
    dots += [[0+2, i+2]]
  elif l1[i] == "x":
    cross += 1
    grid[0+2][i+2] = 1

  if l2[i] == ".":
    dots += [[1+2, i+2]]
  elif l2[i] == "x":
    cross += 1
    grid[1+2][i+2] = 1

  if l3[i] == ".":
    dots += [[2+2, i+2]]
  elif l3[i] == "x":
    cross += 1
    grid[2+2][i+2] = 1

  if l4[i] == ".":
    dots += [[3+2, i+2]]
  elif l4[i] == "x":
    cross += 1
    grid[3+2][i+2] = 1

def check(dot, dir, delta):
  nonlocal grid
  grid[dot[0]][dot[1]] = 1
  
  acc = 1
  if dir == 0: #horizontal
    for i in range(delta, delta+3):
      acc *= grid[dot[0]+i][dot[1]]
  elif dir == 1: #vertical
    for i in range(delta, delta+3):
      acc *= grid[dot[0]][dot[1]+i]
  elif dir == 2: #diag1
    for i in range(delta, delta+3):
      acc *= grid[dot[0]+i][dot[1]+i]
  elif dir == 3: #diag2
    for i in range(delta, delta+3):
      acc *= grid[dot[0]+i][dot[1]-i]

  grid[dot[0]][dot[1]] = 0
  return acc

if cross < 2 or len(dots) == 0:
  print("NO")
else:
  for dot in dots:
    for dir in range(0, 4):
      for delta in range(-2, 1):
        if check(dot, dir, delta) == 1:
          print("YES")
          return
print("NO")