Problem:
 Score : 200 points    Problem Statement We have a bingo card with a 3\times3 grid. The square at the i -th row from the top and the j -th column from the left contains the number A_{i, j} .  The MC will choose N numbers, b_1, b_2, \cdots, b_N . If our bingo sheet contains some of those numbers, we will mark them on our sheet.  Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.      Constraints  All values in input are integers.  1 \leq A_{i, j} \leq 100  A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))  1 \leq N \leq 10  1 \leq b_i \leq 100  b_i \neq b_j (i \neq j)         Input Input is given from Standard Input in the following format:  A_{1, 1}  A_{1, 2}  A_{1, 3}  A_{2, 1}  A_{2, 2}  A_{2, 3}  A_{3, 1}  A_{3, 2}  A_{3, 3}  N  b_1  \vdots  b_N       Output If we will have a bingo, print Yes ; otherwise, print No .        Sample Input 1 84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30      Sample Output 1 Yes  We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3} , and complete the diagonal from the top-left to the bottom-right.       Sample Input 2 41 7 46
26 89 2
78 92 8
5
6
45
16
57
17      Sample Output 2 No  We will mark nothing.       Sample Input 3 60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34      Sample Output 3 Yes  We will mark all the squares.

Solution (Python):
A = [tuple(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
B = [[False]*3 for i in range(3)]

for x in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == x:
                B[i][j] = True
                break


flag = False
for i in range(3):
    for j in range(3):
        if B[i][j] == False:
            break
        if j == 2:
            flag = True


for j in range(3):
    for i in range(3):
        if B[i][j] == False:
            break
        if i == 2:
            flag = True

for i in range(3):
    if B[i][i] == False:
        break
    if i == 2:
        flag = True
for i in range(3):
    if B[2 - i][i] == False:
        break
    if i == 2:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
a = [list(map(int, input().split())) for i in range(3)]
b = [[0 for i in range(3)] for j in range(3)]
n = int(input())
for _ in range(n):
    c = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == c:
                b[i][j] = 1

if b[0][0] + b[1][1] + b[2][2] == 3:
    print('Yes')
elif b[0][0] + b[0][1] + b[0][2] == 3:
    print('Yes')
elif b[1][0] + b[1][1] + b[1][2] == 3:
    print('Yes')
elif b[2][0] + b[2][1] + b[2][2] == 3:
    print('Yes')

elif b[0][0] + b[1][0] + b[2][0] == 3:
    print('Yes')
elif b[0][1] + b[1][1] + b[2][1] == 3:
    print('Yes')
elif b[0][2] + b[1][2] + b[2][2] == 3:
    print('Yes')

elif b[2][0] + b[1][1] + b[0][2] == 3:
    print('Yes')
else:
    print('No')

Solution (Python):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))

N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    if(A1[j] == b): A1[j] = 0
    if(A2[j] == b): A2[j] = 0
    if(A3[j] == b): A3[j] = 0
      
ans = 0      
if(A1[0]+A1[1]+A1[2] == 0): ans = 1
if(A2[0]+A2[1]+A2[2] == 0): ans = 1
if(A3[0]+A3[1]+A3[2] == 0): ans = 1
if(A1[0]+A2[0]+A3[0] == 0): ans = 1
if(A1[1]+A2[1]+A3[1] == 0): ans = 1
if(A1[2]+A2[2]+A3[2] == 0): ans = 1
if(A1[0]+A2[1]+A3[2] == 0): ans = 1
if(A1[2]+A2[1]+A3[0] == 0): ans = 1  
 
if(ans == 0): print('No')
else: print('Yes')

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
flag = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                flag[i][j] = True
ans = False
for i in range(3):
    if all(flag[i][j] for j in range(3)):
        ans = True
    if all(flag[j][i] for j in range(3)):
        ans = True
if all(flag[i][i] for i in range(3)):
    ans = True
if all(flag[2-i][i] for i in range(3)):
    ans = True
if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
a = [[int(i) for i in input().split()] for _ in range(3)]
c=[[False]*3 for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                c[i][j] = True
ok = False
for i in range(3):
    d = True
    for j in range(3):
        if c[i][j] == False:
            d = False
    if d:
        ok = True

for i in range(3):
    d = True
    for j in range(3):
        if c[j][i] == False:
            d = False
    if d:
        ok = True
d = True
for j in range(3):
    if c[j][j] == False:
        d = False
if d:
    ok = True

d = True
for j in range(3):
    if c[j][2-j] == False:
        d = False
if d:
    ok = True
print("Yes"if ok else"No")

Solution (Python):
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

N = int(input())
ans = "No"
for i in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if a[y][x] == b:
                a[y][x] = 0

    for j in range(3):
        if sum(a[j]) == 0:
            ans = "Yes"
            break
    for j in range(3):
        s = 0
        for k in range(3):
            s += a[k][j]
        if s == 0:
            ans = "Yes"
            break
    if (a[0][0]+a[1][1]+a[2][2]) == 0 or (a[0][2]+a[1][1]+a[2][0]) == 0:
        ans = "Yes"
        break
    if ans == "Yes":
        break
print(ans)

Solution (Python):
a11, a12, a13 = map(int,input().split())
a21, a22, a23 = map(int,input().split())
a31, a32, a33 = map(int,input().split())
N = int(input())
blist = [int(input()) for i in range(N)]

if a11 in blist and a21 in blist and a31 in blist:
    print('Yes')
    exit(0)

if a12 in blist and a22 in blist and a32 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a23 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a12 in blist and a13 in blist:
    print('Yes')
    exit(0)

if a21 in blist and a22 in blist and a23 in blist:
    print('Yes')
    exit(0)

if a31 in blist and a32 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a11 in blist and a22 in blist and a33 in blist:
    print('Yes')
    exit(0)

if a13 in blist and a22 in blist and a31 in blist:
    print('Yes')
    exit(0)

print('No')

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A = []
    for _ in range(3):
        A.extend(LI())
    N = I()
    for _ in range(N):
        b = I()
        for i, a in enumerate(A):
            if a == b:
                A[i] = -1
    nums = set()
    for i, a in enumerate(A):
        if a == -1:
            nums.add(i)
    bingo = False
    if 0 in nums and 1 in nums and 2 in nums:
        bingo = True
    if 3 in nums and 4 in nums and 5 in nums:
        bingo = True
    if 6 in nums and 7 in nums and 8 in nums:
        bingo = True
    if 0 in nums and 3 in nums and 6 in nums:
        bingo = True
    if 1 in nums and 4 in nums and 7 in nums:
        bingo = True
    if 2 in nums and 5 in nums and 8 in nums:
        bingo = True
    if 0 in nums and 4 in nums and 8 in nums:
        bingo = True
    if 2 in nums and 4 in nums and 6 in nums:
        bingo = True
    if bingo:
        print("Yes")
    else:
        print("No")


main()

Solution (Python):
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
bingo = [[False] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True

flag = False

if bingo[0][0] == bingo[1][1] == bingo[2][2] == True:
    flag = True
if bingo[0][2] == bingo[1][1] == bingo[2][0] == True:
    flag = True
for i in range(3):
    tmp = True
    for j in range(3):
        if not bingo[i][j]:
            tmp = False
    flag |= tmp
for i in range(3):
    tmp = True
    for j in range(3):
        if not bingo[j][i]:
            tmp = False
    flag |= tmp

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
ans = 'No'
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[i][j] in b:
            cnt += 1
    if cnt == 3:
        ans = 'Yes'
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[j][i] in b:
            cnt += 1
    if cnt == 3:
        ans = 'Yes'
if a[0][0] in b and a[1][1] in b and a[2][2] in b:
    ans = 'Yes'
if a[0][2] in b and a[1][1] in b and a[2][0] in b:
    ans = 'Yes'
print(ans)

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    punches = [[False for i in range(3)] for i in range(3)]
    for step in range(N):
        for i in range(3):
            for j in range(3):
                if A[i][j] == b[step]:
                    punches[i][j] = True
    for i in range(3):
        hasFalse = False
        for j in range(3):
            if not punches[i][j]:
                hasFalse = True
                break
        if not hasFalse:
            print("Yes")
            return
    for i in range(3):
        hasFalse = False
        for j in range(3):
            if not punches[j][i]:
                hasFalse = True
                break
        if not hasFalse:
            print("Yes")
            return
    if punches[0][0] and punches[1][1] and punches[2][2]:
        print("Yes")
        return
    if punches[0][2] and punches[1][1] and punches[2][0]:
        print("Yes")
        return
    print("No")
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  
    N = int(next(tokens))  
    b = [int(next(tokens)) for _ in range(N)]  
    solve(A, N, b)

if __name__ == '__main__':
    main()

Solution (Python):
A = [[0 for _ in range(3)] for _ in range(3)]
for i in range(3):
    a1, a2, a3 = map(int, input().split())
    A[i] = [a1, a2, a3]
N = int(input())
board = [[False for _ in range(3)] for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                board[i][j] = True

for i in range(3):
    if board[i][0] and board[i][1] and board[i][2]:
        print('Yes')
        exit(0)

for j in range(3):
    if board[0][j] and board[1][j] and board[2][j]:
        print('Yes')
        exit(0)


if board[0][0] and board[1][1] and board[2][2]:
    print('Yes')
    exit(0)
if board[0][2] and board[1][1] and board[2][0]:
    print('Yes')
    exit(0)
print('No')

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

F = [[0]*3 for i in range(3)]
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        F[i][j] = 1
ans = 0
for i in range(3):
  f = 1
  for j in range(3):
    if F[i][j] != 1:
      f = 0
  if f ==1:
    ans = 1
for j in range(3):
  f = 1
  for i in range(3):
    if F[i][j] != 1:
      f = 0
  if f == 1:
    ans = 1
if F[0][0] and F[1][1] and F[2][2]:
  ans = 1
if F[0][2] and F[1][1] and F[2][0]:
  ans = 1
print("Yes" if ans else "No")

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    
    
    

    
    
    grid = [[int(x) for x in sys.stdin.readline().split()]
            for _ in range(3)]  
    N = [int(x) for x in sys.stdin.readline().split()][0]  
    v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]

    for b in v_list:
        for i in range(3):
            for j in range(3):
                if grid[i][j] == b:
                    grid[i][j] = True

    
    for i in range(3):
        if grid[i][0] == True and grid[i][1] == True and grid[i][2] == True:
            print('Yes')
            return

            
    for j in range(3):
        if grid[0][j] == True and grid[1][j] == True and grid[2][j] == True:
            print('Yes')
            return

    if grid[0][0] == True and grid[1][1] == True and grid[2][2] == True:
        print('Yes')
        return

    if grid[0][2] == True and grid[1][1] == True and grid[2][0] == True:
        print('Yes')
        return

    print('No')


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """41 7 46
26 89 2
78 92 8
5
6
45
16
57
17"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34"""
        output = """Yes"""
        self.assertIO(input, output)

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [int(input()) for i in range(N)]

bingo = [[0,0,0],[0,0,0],[0,0,0]]


for i in range(N):
    b = B[i]
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                bingo[i][j] = 1

ans = False
for i in range(3):
    if bingo[i] == [1,1,1]:
        ans = True
        break
    elif bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
        ans = True
        break
    elif bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
        ans = True
        break
    elif bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
        ans = True
        break
print('Yes' if ans else 'No')

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
items = [
    [(0, 0), (0, 1), (0, 2)],
    [(1, 0), (1, 1), (1, 2)],
    [(2, 0), (2, 1), (2, 2)],
    [(0, 0), (1, 0), (2, 0)],
    [(0, 1), (1, 1), (2, 1)],
    [(0, 2), (1, 2), (2, 2)],
    [(0, 0), (1, 1), (2, 2)],
    [(0, 2), (1, 1), (2, 0)]
]

is_bingo = False
for item in items:
    is_bingo = \
        a[item[0][0]][item[0][1]] in b and \
        a[item[1][0]][item[1][1]] in b and \
        a[item[2][0]][item[2][1]] in b
    if is_bingo:
        print("Yes")
        exit(0)
print("No")

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
f = [[0] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                f[i][j] = 1
res = "No"
if f[0][0] == 1 and f[0][1] == 1 and f[0][2] == 1:
    res = "Yes"
if f[1][0] == 1 and f[1][1] == 1 and f[1][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[2][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][0] == 1 and f[2][0] == 1:
    res = "Yes"
if f[0][1] == 1 and f[1][1] == 1 and f[2][1] == 1:
    res = "Yes"
if f[0][2] == 1 and f[1][2] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[1][1] == 1 and f[0][2] == 1:
    res = "Yes"

print(res)

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
flag = [[False]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            flag[i][j] = True
ans = False

for a in flag:
    if all(a):
        ans = True

for i in range(3):
    tmp = 0
    for j in range(3):
        if flag[j][i]:
            tmp += 1
    if tmp == 3:
        ans = True


if flag[0][0] and flag[1][1] and flag[2][2]:
    ans = True
if flag[0][2] and flag[1][1] and flag[2][0]:
    ans = True

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
    grid = []
    for i in range(3):
        grid.append(list(map(int,input().split())))

    n = int(input())
    nums = set()
    for i in range(n):
        b = int(input())
        nums.add(b)

    for i in range(3):
        found = True
        for j in range(3):
            if grid[i][j] not in nums:
                found = False
                break

        if found:
            print('Yes')
            return

    for i in range(3):
        found = True
        for j in range(3):
            if grid[j][i] not in nums:
                found = False
                break

        if found:
            print('Yes')
            return

    found = True
    for i in range(3):
        if grid[i][i] not in nums:
            found = False
            break

    if found:
        print('Yes')
        return

    found = True
    for i in range(3):
        if grid[i][3-i-1] not in nums:
            found = False
            break

    if found:
        print('Yes')
        return

    print('No')

main()

Solution (Python):
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
ans = [[False]*3 for i in range(3)]
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if b == A[j][k]:
        ans[j][k] = True
if ans[0][0] and ans[0][1] and ans[0][2]:
  print("Yes")
elif ans[1][0] and ans[1][1] and ans[1][2]:
  print("Yes")
elif ans[2][0] and ans[2][1] and ans[2][2]:
  print("Yes")
elif ans[0][0] and ans[1][0] and ans[2][0]:
  print("Yes")
elif ans[0][1] and ans[1][1] and ans[2][1]:
  print("Yes")
elif ans[0][2] and ans[1][2] and ans[2][2]:
  print("Yes")
elif ans[0][0] and ans[1][1] and ans[2][2]:
  print("Yes")
elif ans[0][2] and ans[1][1] and ans[2][0]:
  print("Yes")
else:
  print("No")

Solution (Python):
h = [list(map(int,input().split())) for i in range(3)]
a = []
for i in h:
  a.append(i[0])
  a.append(i[1])
  a.append(i[2])
b = [0 for i in range(9)]
for i in range(int(input())):
  n = int(input())
  if n in a:
    b[a.index(n)] = 1
if b[0]==b[1]==b[2]==1 or b[3]==b[4]==b[5]==1 or b[6]==b[7]==b[8]==1 or b[0]==b[3]==b[6]==1 or b[1]==b[4]==b[7]==1 or b[2]==b[5]==b[8]==1 or b[0]==b[4]==b[8]==1 or b[2]==b[4]==b[6]==1:
  print("Yes")
else:
  print("No")

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
B = [[0 for _ in range(3)] for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            B[i][j] = 1
c = 0
for i in range(3):       
    if B[i][0] == B[i][1] == B[i][2] == 1:
        c = 1
    if B[0][i] == B[1][i] == B[2][i] == 1:
        c = 1
if B[0][0] == B[1][1] == B[2][2] == 1:
    c = 1
if B[0][2] == B[1][1] == B[2][0] == 1:
    c = 1
if c == 1:
    print("Yes")
else:
    print("No")

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = -1
for i in range(3):
    if a[i].count(-1) == 3:
        print('Yes')
        exit()
for j in range(3):
    if a[0][j] == a[1][j] == a[2][j] == -1:
        print('Yes')
        exit()
if a[0][0] == a[1][1] == a[2][2] == -1:
    print('Yes')
    exit()
if a[0][2] == a[1][1] == a[2][0] == -1:
    print('Yes')
    exit()
print('No')

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [0] * N
for i in range(N):
    B[i] = int(input())


def f(A,n):
    for i in range(3):
        for j in range(3):
            if A[i][j] == n:
                A[i][j] = 0
    return A

for b in B:
    A = f(A,b)
ret = "No"
for i in range(3):
    if sum(A[i]) == 0:
        ret = "Yes"

for i in range(3):
    t = A[0][i] + A[1][i] + A[2][i]
    if t == 0:
        ret = "Yes"

if A[0][0] + A[1][1] + A[2][2] == 0:
    ret = "Yes"

if A[0][2] + A[1][1] + A[2][0] == 0:
    ret ="Yes"

print(ret)

Solution (Python):
import math
nums= [list(map(int,input().split(" "))) for _ in range(3)]
ans = "No"
N = int(input())
bs = [int(input()) for _ in range(N)]
for b in bs:
    for i in range(3):
        for j in range(3):
            if nums[i][j] == b:
                nums[i][j] = -1


for i in range(3):
    if nums[i][0] == nums[i][1] == nums[i][2] == -1:
        ans ="Yes"

for i in range(3):
    if nums[0][i] == nums[1][i] == nums[2][i] == -1:
        ans ="Yes"
for i in range(3):
    if nums[0][0] == nums[1][1] == nums[2][2] == -1:
        ans ="Yes"

for i in range(3):
    if nums[0][2] == nums[1][1] == nums[2][0] == -1:
        ans ="Yes"
print(ans)

Solution (Python):
Ass = [tuple(map(int, input().split())) for _ in range(3)]
N = int(input())
Bs = [int(input()) for _ in range(N)]

isFoundss = [[0]*(3) for _ in range(3)]
for B in Bs:
    for i in range(3):
        for j in range(3):
            if Ass[i][j] == B:
                isFoundss[i][j] = 1


ans = 'No'
for i in range(3):
    for j in range(3):
        if isFoundss[i][j] == 0:
            break
    else:
        ans = 'Yes'

for j in range(3):
    for i in range(3):
        if isFoundss[i][j] == 0:
            break
    else:
        ans = 'Yes'

for i in range(3):
    if isFoundss[i][i] == 0:
        break
else:
    ans = 'Yes'

for i in range(3):
    if isFoundss[i][2-i] == 0:
        break
else:
    ans = 'Yes'

print(ans)

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]


ans = False
for a in A:
    ans |= set(a) <= set(B)
    
for i in range(3):
    ans |= set([A[0][i], A[1][i], A[2][i]]) <= set(B)
    
ans |= set([A[0][0], A[1][1], A[2][2]]) <= set(B)
ans |= set([A[0][2], A[1][1], A[2][0]]) <= set(B)
    
print("Yes" if ans else "No")

Solution (Python):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0
flag = False
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0 or A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
  flag = True
  
for i in range(3):
  tate = True
  yoko = True
  for j in range(3):
    if A[i][j] != 0:
      yoko = False
    if A[j][i] != 0:
      tate = False
  flag = flag or tate or yoko
print("Yes" if flag else "No")

Solution (Python):
import sys

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = None
for i in range(3):
    if a[i][0] == a[i][1] == a[i][2] == None or a[0][i] == a[1][i] == a[2][i]:
        print("Yes")
        sys.exit(0)
if a[0][0] == a[1][1] == a[2][2] == None or a[2][0] == a[1][1] == a[0][2] == None:
    print("Yes")
else:
    print("No")

Solution (Python):
A = []
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

N = int(input())
B = []
for i in range(N):
    b = int(input())
    B.append(b)

T = []
for i in range(3):
    T.append([False]*3)

for bi in B:
    for i in range(3):
        for j in range(3):
            if bi == A[i][j]:
                T[i][j] = True




ans = False
for i in range(3):
    if all(T[i]):
        ans = True

for i in range(3):
    if T[0][i] and T[1][i] and T[2][i]:
        ans = True

if T[0][0] and T[1][1] and T[2][2]:
    ans = True

if T[0][2] and T[1][1] and T[2][0]:
    ans = True

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

table = [False]*9

aaa1 = get_nums_l()
aaa2 = get_nums_l()
aaa3 = get_nums_l()
aaa = aaa1 + aaa2 + aaa3
n = int(input())
bbb = get_nums_n(n)

for b in bbb:
    for i,a in enumerate(aaa):
        if a == b:
            table[i] = True

check = [
    (0,3,6),
    (1,4,7),
    (2,5,8),
    (0,1,2),
    (3,4,5),
    (6,7,8),
    (0,4,8),
    (2,4,6)
]

for ch in check:
    for c in ch:
        if not table[c]:
            break
    else:
        print("Yes")
        exit()
print("No")

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

As = []
for _ in range(3):
    As.append(list(map(int, input().split())))
N = int(input())

s = set()
for n in range(N):
    b = int(input())
    s.add(b)

table = [[0] * 3 for _ in range(3)]
for h in range(3):
    for w in range(3):
        a = As[h][w]
        table[h][w] = (a in s)




ans = False
for h in range(3):
    if table[h][0] == table[h][1] == table[h][2] == True: ans = True
for w in range(3):
    if table[0][w] == table[1][w] == table[2][w] == True: ans = True
if table[0][0] == table[1][1] == table[2][2] == True: ans = True
if table[0][2] == table[1][1] == table[2][0] == True: ans = True

if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    grid = []
    for _ in range(3):
        grid.append(list(map(int, input().split())))
    N = int(input())
    B = []
    for _ in range(N):
        B.append(int(input()))

    check = [[0] * 3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if grid[i][j] == b:
                    check[i][j] = 1

    ok = 0
    for i in range(3):
        if sum(check[i]) == 3:
            ok = 1
    for j in range(3):
        flg = 0
        for i in range(3):
            flg += check[i][j]
        if flg == 3:
            ok = 1
    if check[0][0] == check[1][1] == check[2][2] == 1:
        ok = 1
    if check[0][2] == check[1][1] == check[2][0] == 1:
        ok = 1
    if ok:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Solution (Python):
A = list()
for i in range(3):
    A.append(list(map(int, input().split())))

n = int(input())
bs = [int(input()) for i in range(n)]

bingo = [[False for i in range(3)] for j in range(3)]

def hit(b):
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                return (i, j)
    return None
for b in bs:
    ret = hit(b)                
    if ret is None:
        continue
    else:
        bingo[ret[0]][ret[1]] = True

def detect():
    for i in range(3):
        if all(bingo[i]):
            return True
    
    for j in range(3):
        if all([bingo[i][j] for i in range(3)]):
            return True
    
    if bingo[0][0] and bingo[1][1] and bingo[2][2]:
        return True

    if bingo[2][0] and bingo[1][1] and bingo[0][2]:
        return True

    return False

if detect():
    print('Yes')
else:
    print('No')

Solution (Python):
a=list(map(int," ".join([input() for i in range(3)]).split()))
n=int(input())
b=[int(input())for i in range(n)]
for i in b:
    if i in a:
        p=a.index(i)
        a[p]="*"
p=0
for i in range(3):
    if a[i]==a[i+3]==a[i+6]=="*":
        p+=1
for i in range(3):
    if a[3*i]==a[3*i+1]==a[3*i+2]=="*":
        p+=1
if a[0]==a[4]==a[8]=="*" or a[2]==a[4]==a[6]=="*":
    p+=1
print("Yes") if p>0 else print("No")

Solution (Python):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

a = []
for i in range(3):
    a.append(LI())

ll = [[0]*3 for i in range(3)]

n = I()
for i in range(n):
    b = I()
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                ll[j][k]=1

for i in range(3):
    if ll[i]==[1,1,1]:
        print("Yes")
        exit()
for i in range(3):
    if ll[0][i]==1 and ll[1][i]==1 and ll[2][i]==1:
        print("Yes")
        exit()

if ll[0][0]==1 and ll[1][1]==1 and ll[2][2]==1:
    print("Yes")
    exit()
if ll[0][2]==1 and ll[1][1]==1 and ll[2][0]==1:
    print("Yes")
    exit()

print("No")

Solution (Python):
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for i in range(n):
        x = int(input())
        for j in range(3):
                for k in range(3):
                        if a[j][k]==x: a[j][k] = 0
ans = dcnt1 = dcnt2 = 0
for i in range(3):
        vcnt = hcnt = 0
        for j in range(3):
                if a[i][j]==0: vcnt += 1
                if a[j][i]==0: hcnt += 1

        if a[i][i]==0: dcnt1 += 1
        if a[2-i][i]==0: dcnt2 += 1
        if vcnt==3 or hcnt==3: ans = 1
if dcnt1==3 or dcnt2==3: ans = 1

if ans: print("Yes")
else: print("No")

Solution (Python):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [[False]*3 for i in range(3)]

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                B[j][k] = True

flag = False

for i in range(3):
    if B[i][0] and B[i][1] and B[i][2]:
        flag = True
        break
    if B[0][i] and B[1][i] and B[2][i]:
        flag = True
        break

if B[0][0] and B[1][1] and B[2][2]:
    flag = True

if B[0][2] and B[1][1] and B[2][0]:
    flag = True

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
A = [[0, 0, 0] for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                A[j][k] = 1

ans = 0
for i in range(3):
    if sum(A[i]) == 3:
        ans = 1

for i in range(3):
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 3:
        ans = 1

s = 0
for i in range(3):
    s += A[i][i]
if s == 3:
    ans = 1

s = 0
for i in range(3):
    s += A[i][2 - i]
if s == 3:
    ans = 1

if ans:
    print("Yes")
else:
    print("No")