Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.

In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.

Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.


-----Input-----

You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.

It is guaranteed that in the current arrangement nobody has still won.


-----Output-----

Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.


-----Examples-----
Input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........

Output
YES

Input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........

Output
NO

Difficulty: interview

Starter code:

Solutions:
s = [ [ c for c in input() ] for i in range(10) ]
def win():
  for i in range(10):
    for j in range(10):
      ok = True
      for k in range(5):
        if j+k>9: ok = False
        elif s[i][j+k] != 'X': ok = False
      if ok: return True
      ok = True
      for k in range(5):
        if i+k>9: ok = False
        elif s[i+k][j] != 'X': ok = False
      if ok: return True
      ok = True
      for k in range(5):
        if j+k>9 or i+k>9: ok = False
        elif s[i+k][j+k] != 'X': ok = False
      if ok: return True
      ok = True
      for k in range(5):
        if i-k<0 or j+k>9: ok = False
        elif s[i-k][j+k] != 'X': ok = False
      if ok: return True
  return False
for i in range(10):
  for j in range(10):
    if s[i][j]=='.':
      s[i][j] = 'X'
      if win():
        print('YES')
        return
      s[i][j] = '.'
print('NO')



import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

g=[list(input().strip()) for _ in range(10)]

ans=0

for i in range(10):
    for j in range(10):
        if g[i][j]!='.': continue
        g[i][j]='X'
        # check possible
        for p in range(10):
            for q in range(10):
                # cancer
                if p+4<10:
                    cnt=0
                    for r in range(5):
                        if g[p+r][q]=='X':
                            cnt+=1
                    if cnt==5: ans=1
                if q+4<10:
                    cnt=0
                    for r in range(5):
                        if g[p][q+r]=='X':
                            cnt+=1
                    if cnt==5: ans=1
                if p+4<10 and q+4<10:
                    cnt=0
                    for r in range(5):
                        if g[p+r][q+r]=='X':
                            cnt+=1
                    if cnt==5: ans=1
                    cnt=0
                    for r in range(5):
                        if g[p+4-r][q+r]=='X':
                            cnt+=1
                    if cnt==5: ans=1
        # done
        g[i][j]='.'

print("YES" if ans else "NO")

a = []
for i in range(10):
    a.append(input())

def valid(x, y):
    if 0 <= x <= 9 and 0 <= y <= 9:
        return True
    return False

def check(x, y, direction):
    ans = 1
    curr_x = x + direction[0]
    curr_y = y + direction[1]
    while valid(curr_x, curr_y) and a[curr_x][curr_y] == 'X':
        ans += 1
        curr_x += direction[0]
        curr_y += direction[1]
    curr_x = x - direction[0]
    curr_y = y - direction[1]
    while valid(curr_x, curr_y) and a[curr_x][curr_y] == 'X':
        ans += 1
        curr_x -= direction[0]
        curr_y -= direction[1]
    return ans

curr = 0
for i in range(10):
    for j in range(10):
        if a[i][j] == '.':
            for direction in [[1, 0], [0, 1], [1, 1], [1, -1]]:
                curr = max(curr, check(i, j, direction))

if curr >= 5:
    print('YES')
else:
    print('NO')
            


def check(r0, c0, dr, dc):
    cntx = 0
    cnte = 0
    for i in range(5):
        r = r0 + dr * i
        c = c0 + dc * i
        if r < 0 or 9 < r or c < 0 or 9 < c:
            break
        elif cells[r][c] == 'X':
            cntx += 1
        elif cells[r][c] == '.':
            cnte += 1
    return cntx == 4 and cnte == 1

cells = [list(input()) for _ in range(10)]
drc = [(1, 0), (0, 1), (1, 1), (1, -1)]
ans = 'NO'
for r0 in range(10):
    for c0 in range(10):
        for (dr, dc) in drc:
            if check(r0, c0, dr, dc):
                ans = 'YES'
print(ans)


def main():
    
    
    
    
    Map=[]
    for i in range(10):
        Map+=[input()]
        

    
    
    
    
    for i in range(10):
        for j in range(10):
            count=0
            count2=0
            if i<=5:
                for k in range(5):
                    if Map[i+k][j]=='X':
                        count+=1
                    elif Map[i+k][j]=='.':
                        count2+=1
                if count==4 and count2==1:
                    print('YES')
                    return 0

            count=0
            count2=0
            if j<=5:
                for k in range(5):
                    if Map[i][j+k]=='X':
                        count+=1
                    elif Map[i][j+k]=='.':
                        count2+=1                   
                if count==4 and count2==1:
                    print('YES')
                    return 0
            
            count=0
            count2=0            
            
            if i<=5 and j<=5:
                for k in range(5):
                    if Map[i+k][j+k]=='X':
                        count+=1
                    elif Map[i+k][j+k]=='.':
                        count2=1                    
                if count==4 and count2==1:
                    print('YES')
                    return 0
            count=0
            count2=0            
            
            if i>=4 and j<=5:
                count=0
                for k in range(5):
                    if Map[i-k][j+k]=='X':
                        count+=1
                    elif Map[i-k][j+k]=='O':
                        count-=1                                  
                        
                if count==4:
                    print('YES')
                    return 0
    print('NO')
    return 0
    
main()                    


def check(a, x, y):
    left = 0
    right = 0
    for i in range(1, 11):
        if x - i >= 0:
            if a[x - i][y] == 'X':
                left += 1
            else:
                break
        else:
            break
    for i in range(1, 11):
        if x + i < 10:
            if a[x + i][y] == 'X':
                right += 1
            else:
                break
        else:
            break
    if right + left >= 4:
        return 1
    left = 0
    right = 0
    for i in range(1, 11):
        if y - i >= 0:
            if a[x][y - i] == 'X':
                left += 1
            else:
                break
        else:
            break
    for i in range(1, 11):
        if y + i < 10:
            if a[x][y + i] == 'X':
                right += 1
            else:
                break
        else:
            break
    if right + left >= 4:
        return 1
    left = 0
    right = 0
    for i in range(1, 11):
        if x - i >= 0 and y - i >= 0:
            if a[x - i][y - i] == 'X':
                left += 1
            else:
                break
        else:
            break
    for i in range(1, 11):
        if x + i < 10 and y + i < 10:
            if a[x + i][y + i] == 'X':
                right += 1
            else:
                break
        else:
            break
    if right + left >= 4:
        return 1
    left = 0
    right = 0
    for i in range(1, 11):
        if x - i >= 0 and y + i < 10:
            if a[x - i][y + i] == 'X':
                left += 1
            else:
                break
        else:
            break
    for i in range(1, 11):
        if x + i < 10 and y - i >= 0:
            if a[x + i][y - i] == 'X':
                right += 1
            else:
                break
        else:
            break
    if right + left >= 4:
        return 1
    return 0
    
a = []
for i in range(10):
    gg = input()
    a.append([])
    for j in range(10):
        a[i].append(gg[j])
for i in range(10):
    for j in range(10):
        if a[i][j] == '.':
            a[i][j] = 'X'
            if check(a, i, j):
                print("YES")
                return
            a[i][j] = '.'
print("NO")
    


def check(a, b, c, d, e):
	countX = 0
	countD = 0
	
	if a == 'X': countX += 1
	elif a == '.': countD += 1
	
	if b == 'X': countX += 1
	elif b == '.': countD += 1
	
	if c == 'X': countX += 1
	elif c == '.': countD += 1
	
	if d == 'X': countX += 1
	elif d == '.': countD += 1
	
	if e == 'X': countX += 1
	elif e == '.': countD += 1
	
	return countX == 4 and countD == 1

def f(a):
	for i in range(10):
		for j in range(6):
			if (check(a[i][j], a[i][j+1], a[i][j+2], a[i][j+3], a[i][j+4])
			or i < 6 and check(a[i][j], a[i+1][j+1], a[i+2][j+2], a[i+3][j+3], a[i+4][j+4])):
			    return True
	
	for i in range(10):
		for j in range(6):
			if (check(a[j][i], a[j+1][i], a[j+2][i], a[j+3][i], a[j+4][i])
			or i > 3 and check(a[j][i], a[j+1][i-1], a[j+2][i-2], a[j+3][i-3], a[j+4][i-4])):
				return True
	
print('YES' if f([input() for _ in range(10)]) else 'NO')

#!/usr/local/bin/python3

import sys

table = [line.strip() for line in sys.stdin]

def check_position(table, row, column):

    if table[row][column] != '.':
        return False
    
    left_sum = 0
    tmp = column - 1
    while (tmp >= 0) and table[row][tmp] == 'X':
        left_sum += 1
        tmp -= 1

    right_sum = 0
    tmp = column + 1
    while (tmp < 10) and table[row][tmp] == 'X':
        right_sum += 1
        tmp += 1

    if left_sum + right_sum >= 4:
        return True

    # -----

    up_sum = 0
    tmp = row - 1
    while (tmp >= 0) and table[tmp][column] == 'X':
        up_sum += 1
        tmp -= 1

    down_sum = 0
    tmp = row + 1
    while (tmp < 10) and table[tmp][column] == 'X':
        down_sum += 1
        tmp += 1

    if up_sum + down_sum >= 4:
        return True 

    # -----

    maindup_sum = 0
    tmp_row = row - 1
    tmp_col = column - 1
    while (tmp_row >= 0) and (tmp_col >= 0) and table[tmp_row][tmp_col] == 'X':
        tmp_row -= 1
        tmp_col -= 1
        maindup_sum += 1
    
    maindup_down = 0
    tmp_row = row + 1
    tmp_col = column + 1
    while (tmp_row < 10) and (tmp_col < 10) and table[tmp_row][tmp_col] == 'X':
        tmp_row += 1
        tmp_col += 1
        maindup_down += 1

    if maindup_sum + maindup_down >= 4:
        return True

    # -----
    
    dup_sum = 0
    tmp_row = row - 1
    tmp_col = column + 1
    while (tmp_row >= 0) and (tmp_col < 10) and table[tmp_row][tmp_col] == 'X':
        tmp_row -= 1
        tmp_col += 1
        dup_sum += 1
    
    dup_down = 0
    tmp_row = row + 1
    tmp_col = column - 1
    while (tmp_row < 10) and (tmp_col >= 0) and table[tmp_row][tmp_col] == 'X':
        tmp_row += 1
        tmp_col -= 1
        dup_down += 1

    if dup_sum + dup_down >= 4:
        return True

    return False

for row in range(10):
    for column in range(10):
        if check_position(table, row, column):
            print("YES")
            return

print("NO")


a=[0 for i in range(10)]
for i in range(10):
    a[i]=input()

b=[[0 for i in range(10)] for i in range(10)]

f=False
for x1 in range(10):
    for y1 in range(10):
        for i in range(10):
            for j in range(10):
                b[i][j]=a[i][j]
        if b[x1][y1]=='.':
            b[x1][y1]='X'
        can=False
        for i in range(10): #ÅÐ¶ÏÊäÓ®
            for j in range(10):
                if j<6 and b[i][j]=='X' and b[i][j+1]=='X' and b[i][j+2]=='X' and b[i][j+3]=='X' and b[i][j+4]=='X':
                    can=True
                if i<6 and b[i][j]=='X' and b[i+1][j]=='X' and b[i+2][j]=='X' and b[i+3][j]=='X' and b[i+4][j]=='X':
                    can=True
                if i<6 and j<6 and b[i][j]=='X' and b[i+1][j+1]=='X' and b[i+2][j+2]=='X' and b[i+3][j+3]=='X' and b[i+4][j+4]=='X':
                    can=True
                if i<6 and j>3 and b[i][j]=='X' and b[i+1][j-1]=='X' and b[i+2][j-2]=='X' and b[i+3][j-3]=='X' and b[i+4][j-4]=='X':
                    can=True
        if can==True:
            f=True

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


s=10*[0]
for i in range(10):
	s[i]=input()
def trav(i,j,s,n):
	if n==1:
		if(i<9):
			if s[i+1][j]=='X':
				return 1 + trav(i+1,j,s,n)
			return 0
		return 0
	if n==-1:
		if(i>0):
			if s[i-1][j]=='X':
				return 1 + trav(i-1,j,s,n)
			return 0
		return 0
	if n==2:
		if(j<9):
			if s[i][j+1]=='X':
				return 1 + trav(i,j+1,s,n)
			return 0
		return 0
	if n==-2:
		if(j>0):
			if s[i][j-1]=='X':
				return 1 + trav(i,j-1,s,n)
			return 0
		return 0
	if n==3:
		if(i<9 and j<9):
			if s[i+1][j+1]=='X':
				return 1 + trav(i+1,j+1,s,n)
			return 0
		return 0
	if n==-3:
		if(i>0 and j>0):
			if s[i-1][j-1]=='X':
				return 1 + trav(i-1,j-1,s,n)
			return 0
		return 0
	if n==4:
		if(i>0 and j<9):
			if s[i-1][j+1]=='X':
				return 1 + trav(i-1,j+1,s,n)
			return 0
		return 0
	if n==-4:
		if(i<9 and j>0):
			if s[i+1][j-1]=='X':
				return 1 + trav(i+1,j-1,s,n)
			return 0
		return 0

flag=False		
for i in range(10):
	for j in range(10):
		if s[i][j]=='.':
			#print(trav(i,j,s,-2))
			#input()
			if trav(i,j,s,1)+trav(i,j,s,-1)>=4 or trav(i,j,s,2)+trav(i,j,s,-2)>=4 or trav(i,j,s,3)+trav(i,j,s,-3)>=4 or trav(i,j,s,4)+trav(i,j,s,-4)>=4:
				flag=True;
				print ('YES')
				break
	if flag:
		break
if not flag:
	print('NO')

matrix = []
N = 10

for i in range(N):
	matrix.append(list(input()))

won = False

def check_alice_won(matrix):
	maxScore = 0
	for i in range(N):
		curScore = 0
		for j in range(N):
			if matrix[i][j] == 'X':
				curScore += 1
			else:
				if curScore > maxScore:
					maxScore = curScore
				curScore = 0
		if curScore >= maxScore:
			maxScore = curScore
		if maxScore >= 5:
			return True

	maxScore = 0
	for i in range(N):
		curScore = 0
		for j in range(N):
			if matrix[j][i] == 'X':
				curScore += 1
			else:
				if curScore > maxScore:
					maxScore = curScore
				curScore = 0
		if curScore >= maxScore:
			maxScore = curScore
		if maxScore >= 5:
			return True

	maxScore = 0
	for p in range(0, 2*N - 1):
		curScore = 0
		# print(max(0, p - N + 1), min(p, N - 1) + 1)
		# print(list(range(max(0, p - N + 1), min(p, N - 1) + 1)))
		for q in list(range(max(0, p - N + 1), min(p, N - 1) + 1)):
			# print(matrix[p-q][q], end='')
			if matrix[p-q][q] == 'X':
				curScore += 1
			else:
				if curScore > maxScore:
					maxScore = curScore
				curScore = 0
		if curScore >= maxScore:
			maxScore = curScore
		if maxScore >= 5:
			return True

	maxScore = 0
	for p in range(0, 2*N - 1):
		curScore = 0
		# print(max(0, p - N + 1), min(p, N - 1) + 1)
		# print(list(range(max(0, p - N + 1), min(p, N - 1) + 1)))
		for q in list(range(max(0, p - N + 1), min(p, N - 1) + 1)):
			# print(matrix[p-q][N - 1 - q], end='')
			if matrix[p-q][N - 1 - q] == 'X':
				curScore += 1
				# print(curScore)
			else:
				if curScore >= maxScore:
					maxScore = curScore
				curScore = 0
		if curScore >= maxScore:
			maxScore = curScore
		# print("MAX")
		# print(maxScore)
		# input()
		if maxScore >= 5:
			return True

	return False

for i in range(N):
	for j in range(N):
		if matrix[i][j] == '.' and won == False:
			matrix[i][j] = 'X'
			# print(matrix)
			if check_alice_won(matrix) == True:
				won = True
			# print(won)
			# input()
			matrix[i][j] = '.'

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

field = []
for _ in range(10):
    field.append(input())

rows = [row for row in field]
columns = []
for i in range(10):
    s = ''
    for j in range(10):
        s += field[j][i]
    columns.append(s)
maindiags = []
for k in range(-9, 10):
    s = ''
    if k >= 0:
        for i in range(10 - k):
            for j in range(k, 10):
                if i == j - k:
                    s += field[i][j]
    else:
        for i in range(-k, 10):
            for j in range(10 + k):
                if i == j - k:
                    s += field[i][j]
    maindiags.append(s)
diags = []
for k in range(-9, 10):
    s = ''
    if k >= 0:
        for i in range(k, 10):
            for j in range(k, 10):
                if i == 9 - j + k:
                    s += field[i][j]
    else:
        for i in range(10 + k):
            for j in range(10 + k):
                if i == 9 - j + k:
                    s += field[i][j]
    diags.append(s)
def answer(a):
    patterns = ['.XXXX','X.XXX','XX.XX','XXX.X','XXXX.']
    for elem in a:
        if len(elem) >= 5:
            for k in range(5):
                for i in range(len(elem) - 4):
                    flag = True
                    for j in range(5):
                        if elem[i + j] != patterns[k][j]:
                            flag = False
                    if flag:
                        return True
    return False

a = rows + columns + maindiags + diags
print('YES' if answer(a) else 'NO')

import os

def f():
    board = []
    for i in range(10):
        board.append(input())
    for i, row in enumerate(board):
        for j, c in enumerate(row):
            if c == '.':
                #horizonal
                d1 = d2 = 0
                b = j - 1
                while b >= 0:
                    if row[b] == 'X':
                        d1 += 1
                        b -= 1
                    else:
                        break
                b = j + 1
                while b <= 9:
                    if row[b] == 'X':
                        d2 += 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return            
                #vertical
                d1 = d2 = 0
                a = i - 1
                while a >= 0:
                    if board[a][j] == 'X':
                        d1 += 1
                        a -= 1
                    else:
                        break
                a = i + 1
                while a <= 9:
                    if board[a][j] == 'X':
                        d2 += 1
                        a += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
                #diagonal
                d1 = d2 = 0
                a = i - 1
                b = j - 1
                while a >= 0 and b >= 0:
                    if board[a][b] == 'X':
                        d1 += 1
                        a -= 1
                        b -= 1
                    else:
                        break
                a = i + 1
                b = j + 1
                while a <= 9 and b <= 9:
                    if board[a][b] == 'X':
                        d2 += 1
                        a += 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
                #another diagonal
                d1 = d2 = 0
                a = i + 1
                b = j - 1
                while a <= 9 and b >= 0:
                    if board[a][b] == 'X':
                        d1 += 1
                        a += 1
                        b -= 1
                    else:
                        break
                a = i - 1
                b = j + 1
                while a >= 0 and b <= 9:
                    if board[a][b] == 'X':
                        d2 += 1
                        a -= 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
    print('NO')

f()

import os

def f():
    board = []
    for i in range(10):
        board.append(input())
    for i, row in enumerate(board):
        for j, c in enumerate(row):
            if c == '.':
                #horizonal
                d1 = d2 = 0
                b = j - 1
                while b >= 0:
                    if row[b] == 'X':
                        d1 += 1
                        b -= 1
                    else:
                        break
                b = j + 1
                while b <= 9:
                    if row[b] == 'X':
                        d2 += 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return            
                #vertical
                d1 = d2 = 0
                a = i - 1
                while a >= 0:
                    if board[a][j] == 'X':
                        d1 += 1
                        a -= 1
                    else:
                        break
                a = i + 1
                while a <= 9:
                    if board[a][j] == 'X':
                        d2 += 1
                        a += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
                #diagonal
                d1 = d2 = 0
                a = i - 1
                b = j - 1
                while a >= 0 and b >= 0:
                    if board[a][b] == 'X':
                        d1 += 1
                        a -= 1
                        b -= 1
                    else:
                        break
                a = i + 1
                b = j + 1
                while a <= 9 and b <= 9:
                    if board[a][b] == 'X':
                        d2 += 1
                        a += 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
                #another diagonal
                d1 = d2 = 0
                a = i + 1
                b = j - 1
                while a <= 9 and b >= 0:
                    if board[a][b] == 'X':
                        d1 += 1
                        a += 1
                        b -= 1
                    else:
                        break
                a = i - 1
                b = j + 1
                while a >= 0 and b <= 9:
                    if board[a][b] == 'X':
                        d2 += 1
                        a -= 1
                        b += 1
                    else:
                        break
                if d1 + d2 >= 4:
                    print('YES')
                    return
    print('NO')

f()

rs = []
for i in range(10):
    length = input()
    rs.append(length)
temp1 = 1
flag1 = 1

def check(i, j, direct,temp,flag):
    if direct == 1:
        if j == 0:
            return 0
        j -= 1
    elif direct == 2:
        if j == 9:
            return 0
        j += 1
    elif direct == 3:
        if i == 0:
            return 0
        i -= 1
    elif direct == 4:
        if i == 9:
            return 0
        i += 1
    elif direct == 5:
        if i == 0 or j == 0:
            return 0
        j -= 1
        i -= 1
    elif direct == 6:
        if i == 9 or j == 0:
            return 0
        j -= 1
        i += 1
    elif direct == 7:
        if i == 0 or j == 9:
            return 0
        j += 1
        i -= 1
    elif direct == 8:
        if i == 9 or j == 9:
            return 0
        j += 1
        i += 1
    if rs[i][j] == 'X':
        temp += 1
        if(temp > 4):
            return 1
        return check(i,j,direct,temp,flag)
    elif rs[i][j] == '.' and flag == 1:
        temp += 1
        flag = 0
        if(temp > 4):
            return 1
        return check(i,j,direct,temp,flag)
    else:
        return 0  

def result():
    for i in range(10):
        for j in range(10):
            if rs[i][j] == 'X':
                for k in range(1,9):
                    if check(i,j,k,temp1,flag1) == 1:
                        return 1
    return 0
if result() == 0:
    print("NO")
else:
    print("YES")


import sys

def check(x):
    t,p = 0,0
    for i in range(5):
        if x[i]=='X':
            t+=1
        elif x[i]=='.':
            p+=1
    if t==4 and p==1:
        return True
    return False


def main():

    x = []
    for i in range(10):
        x.append(sys.stdin.readline().rstrip())

    flag = False

    for i in range(10):
        for j in range(10):
            if j+4<10 and check([x[i][k] for k in range(j,j+5) ]):
                flag = True
            if i+4<10 and check([x[k][j] for k in range(i,i+5) ]):
                flag = True
            if i+4<10 and j+4<10 and check([ x[i+k][j+k] for k in range(5)]):
                flag = True
            if i+4<10 and j-4>=0 and check([ x[i+k][j-k] for k in range(5)]):
                flag = True

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

    
main()


r = [input() for _ in range(10)]
c = []
for i in range(10):
  t = ""
  for j in range(10):
    t += r[j][i]
  c.append(t)
for x in r:
  if any(s in x for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
    print("YES")
    quit()
else:
  for y in c:
    if any(s in y for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
      print("YES")
      quit()
  else:
    for a in range(6):
      z1 = ""
      z2 = ""
      for b in range(10-a):
        z1 += r[a+b][b]
        z2 += r[b][a+b]
      if any(s in z1 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
        print("YES")
        quit()
      if any(s in z2 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
        print("YES")
        quit()
    c = list(zip(*r[::-1]))
    for a in range(6):
      z1 = ""
      z2 = ""
      for b in range(10-a):
        z1 += c[a+b][b]
        z2 += c[b][a+b]
      if any(s in z1 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
        print("YES")
        quit()
      if any(s in z2 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]):
        print("YES")
        quit()
  print("NO")
        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


corr = lambda i, j: 0 <= i < 10 and 0 <= j < 10
def can(b):
    for i in range(10):
        for j in range(10):
            for t in range(4):
                flag = 1
                for k in range(5):
                    ni = i + dx[t] * k
                    nj = j + dy[t] * k
                    if not corr(ni, nj) or b[ni][nj] != 'X':
                        flag = 0
                        break
                if flag:
                    return 1
    return 0

def solve():
    b = [list(i) for i in a]
    for i in range(10):
        for j in range(10):
            if b[i][j] == '.':
                temp = b[i][j]
                b[i][j] = 'X'
                if can(b): return 1
                b[i][j] = temp
    return 0

dx, dy = [0, 1, 1, -1], [1, 0, 1, 1]
a = [input() for i in range(10)]
print('YES' if solve() else 'NO')

l = [input() for _ in range(10)]

for c in range(5):
        t = ['X'] * 5
        t[c] = '.'
        for i in range(10):
                for j in range(6):
                        cnt = 0
                        for k in range(5):
                                if l[i][j + k] == '.':
                                        cnt += 1
                                elif l[i][j + k] == 'O':
                                        cnt += 2
                        if cnt == 1:
                                print('YES')
                                return
                                
        for i in range(6):
                for j in range(10):
                        cnt = 0
                        for k in range(5):
                                if l[i + k][j] == '.':
                                        cnt += 1
                                elif l[i + k][j] == 'O':
                                        cnt += 2
                        if cnt == 1:
                                print('YES')
                                return
                                
        for i in range(6):
                for j in range(6):
                        cnt = 0
                        for k in range(5):
                                if l[i + k][j + k] == '.':
                                        cnt += 1
                                elif l[i + k][j + k] == 'O':
                                        cnt += 2
                        if cnt == 1:
                                print('YES')
                                return
        
        for i in range(4, 10):
                for j in range(6):
                        cnt = 0
                        for k in range(5):
                                if l[i - k][j + k] == '.':
                                        cnt += 1
                                elif l[i - k][j + k] == 'O':
                                        cnt += 2
                        if cnt == 1:
                                print('YES')
                                return
        
print('NO')

A = [list(input()) for i in range(10)]

for i in range(10):
	A[i] += ["O"] * 5
for i in range(5):
	A.insert(0,["O"] * 15)
	A.append(["O"] * 15)
D = [(1,0),(0,1),(1,1),(-1,1)]
flag = False
for i in range(5,15):
	for j in range(10):
		if (A[i][j] == "X" or
			A[i][j + 1] == "X" or
			A[i + 1][j] == "X" or
			A[i + 1][j + 1] == "X" or
			A[i - 1][j + 1] == "X"):
			cnt = [0,0,0,0]
			for k in range(5):
				for n,d in enumerate(D):
					dx = k * d[0]
					dy = k * d[1]
					if A[i + dx][j + dy] == "X":
						cnt[n] += 1
					if A[i + dx][j + dy] == "O":
						cnt[n] = -10
			for c in cnt:
				if c == 4:
					flag = True
					break
		if flag == True:
			break
	if flag == True:
		break
if flag == True:
	print("YES")
else:
	print("NO")





matrix=[None]*10
for i in range(10):
	matrix[i]=input()

for i in range(10):
	for j in range(10):
		if 0<=j and j<=5:
			count_x=0
			has_o=False
			for k in range(5):
				if matrix[i][j+k]=='X':
					count_x+=1
				elif matrix[i][j+k]=='O':
					has_o=True
					break
			if count_x==4 and not has_o:
				print("YES")
				return

			if 0<=i and i<=5:
				count_x=0
				has_o=False
				for k in range(5):
					if matrix[i+k][j+k]=='X':
						count_x+=1
					elif matrix[i+k][j+k]=='O':
						has_o=True
						break
				if count_x==4 and not has_o:
					print("YES")
					return

		if 0<=i and i<=5:
			count_x=0
			has_o=False
			for k in range(5):
				if matrix[i+k][j]=='X':
					count_x+=1
				elif matrix[i+k][j]=='O':
					has_o=True
					break
			if count_x==4 and not has_o:
				print("YES")
				return

			if 4<=j and j<=9:
				count_x=0
				has_o=False
				for k in range(5):
					if matrix[i+k][j-k]=='X':
						count_x+=1
					elif matrix[i+k][j-k]=='O':
						has_o=True
						break
				if count_x==4 and not has_o:
					print("YES")
					return
print("NO")


def is_in_row(field):
    for s in field:
        for i in range(len(s) - 4):
            if s[i:i+5].count('X') == 4 and s[i:i+5].count('.') == 1:
                print('YES')
                return True
    return False

def is_in_col(field):
    for s in [''.join(x) for x in zip(*field)]:
        for i in range(len(s) - 4):
            if s[i:i+5].count('X') == 4 and s[i:i+5].count('.') == 1:
                print('YES')
                return True
    return False

def is_in_diag(field):
    shift = []
    for i in range(len(field)):
        shift.append(field[i][i:])
        shift[-1] += 'O' * (10 - len(shift[-1]))

    for s in [''.join(x) for x in zip(*shift)]:
        for i in range(len(s) - 4):
            if s[i:i+5].count('X') == 4 and s[i:i+5].count('.') == 1:
                print('YES')
                return True
            
    shift = []
    for i in range(len(field)):
        shift.append(field[i][:i][::-1])
        shift[-1] += 'O' * (10 - len(shift[-1]))

    for s in [''.join(x) for x in zip(*shift)]:
        for i in range(len(s) - 4):
            if s[i:i+5].count('X') == 4 and s[i:i+5].count('.') == 1:
                print('YES')
                return True
    return False

field = [input() for _ in range(10)]

if is_in_row(field): return
if is_in_col(field): return
if is_in_diag(field): return
if is_in_diag(list([x[::-1] for x in field])): return
    
print('NO')


def check(a, b):
    if m[a][b] != '.':
        return False
    else:
        cnt = 0
        p = a + 1
        while p < 10 and m[p][b] == 'X':
            p += 1
            cnt += 1
        p = a - 1
        while p >= 0 and m[p][b] == 'X':
            p -= 1
            cnt += 1
        if cnt >= 4:
            return True
        cnt = 0
        p = b + 1
        while p < 10 and m[a][p] == 'X':
            p += 1
            cnt += 1
        p = b - 1
        while p >= 0 and m[a][p] == 'X':
            p -= 1
            cnt += 1
        if cnt >= 4:
            return True
        cnt = 0
        p = 1
        while a + p < 10 and b + p < 10 and m[a + p][b + p] == 'X':
            p += 1
            cnt += 1
        p = -1
        while a + p >= 0 and b + p >= 0 and m[a + p][b + p] == 'X':
            p -= 1
            cnt += 1
        if cnt >= 4:
            return True
        cnt = 0
        p = 1
        while a + p < 10 and b - p >= 0 and m[a + p][b - p] == 'X':
            p += 1
            cnt += 1
        p = -1
        while a + p >= 0 and b - p < 10 and m[a + p][b - p] == 'X':
            p -= 1
            cnt += 1
        if cnt >= 4:
            return True
    return False

m = []
for i in range(10):
    m.append(input())
F = False
for i in range(10):
    for j in range(10):
        if check(i, j):
            F = True
if F:
    print('YES')
else:
    print('NO')

def is_win(matrix):
    variants = ['.XXXX', 'X.XXX', 'XX.XX', 'XXX.X', 'XXXX.']
    for i in matrix:
        for exp in variants:
            if exp in ''.join(i):
                return True
    new_matrix = []
    for i in range(10):
        matrix_part = []
        for j in matrix:
            matrix_part.append(j[i])
        new_matrix.append(matrix_part)
    for i in new_matrix:
        for exp in variants:
            if exp in ''.join(i):
                return True
    lines = [
        [matrix[0][0],matrix[1][1],matrix[2][2], matrix[3][3], matrix[4][4], matrix[5][5], matrix[6][6], matrix[7][7], matrix[8][8], matrix[9][9]],
        [matrix[0][1], matrix[1][2], matrix[2][3], matrix[3][4], matrix[4][5], matrix[5][6], matrix[6][7], matrix[7][8], matrix[8][9]],
        [matrix[0][2], matrix[1][3], matrix[2][4], matrix[3][5],matrix[4][6],matrix[5][7],matrix[6][8],matrix[7][9]],
        [matrix[0][3], matrix[1][4], matrix[2][5], matrix[3][6], matrix[4][7], matrix[5][8], matrix[6][9]],
        [matrix[0][4], matrix[1][5],matrix[2][6],matrix[3][7],matrix[4][8],matrix[5][9]],
        [matrix[0][5], matrix[1][6], matrix[2][7],matrix[3][8],matrix[4][9]],
        [matrix[1][0], matrix[2][1], matrix[3][2], matrix[4][3], matrix[5][4], matrix[6][5], matrix[7][6], matrix[8][7], matrix[9][8]],
        [matrix[2][0], matrix[3][1], matrix[4][2], matrix[5][3],matrix[6][4],matrix[7][5],matrix[8][6],matrix[9][7]],
        [matrix[3][0], matrix[4][1], matrix[5][2], matrix[6][3], matrix[7][4], matrix[8][5], matrix[9][6]],
        [matrix[4][0], matrix[5][1],matrix[6][2],matrix[7][3],matrix[8][4],matrix[9][5]],
        [matrix[5][0], matrix[6][1], matrix[7][2],matrix[8][3],matrix[9][4]],
    ]
    for line in lines:
        for exp in variants:
            if exp in ''.join(line):
                return True
    for i in range(10):
        matrix[i] = matrix[i][::-1]
    lines = [
        [matrix[0][0],matrix[1][1],matrix[2][2], matrix[3][3], matrix[4][4], matrix[5][5], matrix[6][6], matrix[7][7], matrix[8][8], matrix[9][9]],
        [matrix[0][1], matrix[1][2], matrix[2][3], matrix[3][4], matrix[4][5], matrix[5][6], matrix[6][7], matrix[7][8], matrix[8][9]],
        [matrix[0][2], matrix[1][3], matrix[2][4], matrix[3][5],matrix[4][6],matrix[5][7],matrix[6][8],matrix[7][9]],
        [matrix[0][3], matrix[1][4], matrix[2][5], matrix[3][6], matrix[4][7], matrix[5][8], matrix[6][9]],
        [matrix[0][4], matrix[1][5],matrix[2][6],matrix[3][7],matrix[4][8],matrix[5][9]],
        [matrix[0][5], matrix[1][6], matrix[2][7],matrix[3][8],matrix[4][9]],
        [matrix[1][0], matrix[2][1], matrix[3][2], matrix[4][3], matrix[5][4], matrix[6][5], matrix[7][6], matrix[8][7], matrix[9][8]],
        [matrix[2][0], matrix[3][1], matrix[4][2], matrix[5][3],matrix[6][4],matrix[7][5],matrix[8][6],matrix[9][7]],
        [matrix[3][0], matrix[4][1], matrix[5][2], matrix[6][3], matrix[7][4], matrix[8][5], matrix[9][6]],
        [matrix[4][0], matrix[5][1],matrix[6][2],matrix[7][3],matrix[8][4],matrix[9][5]],
        [matrix[5][0], matrix[6][1], matrix[7][2],matrix[8][3],matrix[9][4]],
    ]
    for line in lines:
        for exp in variants:
            if exp in ''.join(line):
                return True
    return False
matrix = []
for i in range(10):
    matrix.append(input())
if is_win(matrix):
    print('YES')
else:
    print('NO')