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):
bingo=[]
for _ in range(3):
    List=list(map(int,input().split()))
    bingo.append(List)

n=int(input())

for _ in range(n):
    k=int(input())
    i=0
    while i<3:
        j=0
        while j<3:
            if bingo[i][j]==k:
                bingo[i][j]=0
            j+=1
        i+=1


for item in bingo:
    if item[0]==0 and item[1]==0 and item[2]==0:
        print("Yes")
        exit()

i=0
while i<3:
    if bingo[0][i]==0 and bingo[1][i]==0 and bingo[2][i]==0:
        print("Yes")
        exit()
    i+=1


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

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

print("No")

Solution (Python):
def solve():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    bingo = [[False] * 3 for i in range(3)]
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if b == A[i][j]:
                    bingo[i][j] = True
    
    for i in range(3):
        if bingo[i][0] and bingo[i][1] and bingo[i][2]:
            print('Yes')
            exit(0)
        
        if bingo[0][i] and bingo[1][i] and bingo[2][i]:
            print('Yes')
            exit(0)
    
    if bingo[0][0] and bingo[1][1] and bingo [2][2]:
        print('Yes')
        exit(0) 

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

if __name__ == '__main__':
    solve()

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

for i in range(N):
  for j in range(3):
    for k in range(3):
      if b[i] == A[j][k]:
        A[j][k] = 0

ans = "No"

if A[0][0]==0 and A[0][1]==0 and A[0][2]==0:
  ans = "Yes"
if A[1][0]==0 and A[1][1]==0 and A[1][2]==0:
  ans = "Yes"
if A[2][0]==0 and A[2][1]==0 and A[2][2]==0:
  ans = "Yes"
if A[0][0]==0 and A[1][0]==0 and A[2][0]==0:
  ans = "Yes"
if A[0][1]==0 and A[1][1]==0 and A[2][1]==0:
  ans = "Yes"
if A[0][2]==0 and A[1][2]==0 and A[2][2]==0:
  ans = "Yes"
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
  ans = "Yes"
if A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
  ans = "Yes"

print(ans)

Solution (Python):


def main():
    mtrx = []
    for _ in range(3):
        li = list(map(int, input().split()))
        mtrx.append(li)
        
    n = int(input())
    for _ in range(n):
        num = int(input())
        for i in range(3):
            for j in range(3):
                if mtrx[i][j] == num:
                    mtrx[i][j] = -1
                    
    for i in range(3):
        if mtrx[0][i] == -1 and mtrx[1][i] == -1 and mtrx[2][i] == -1:
            print('Yes')
            return
        if mtrx[i][0] == -1 and mtrx[i][1] == -1 and mtrx[i][2] == -1:
            print('Yes')
            return
    
    if mtrx[0][0] == -1 and mtrx[1][1] == -1 and mtrx[2][2] == -1:
        print('Yes')
        return
    if mtrx[2][0] == -1 and mtrx[1][1] == -1 and mtrx[0][2] == -1:
        print('Yes')
        return
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
a = []
for _ 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_)
d = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        for k in b:
            if k == a[i][j]:
                d[i][j] = 1
                break
for i in range(3):
    if d[i][0] == 1 and d[i][1] == 1 and d[i][2] == 1:
        print("Yes")
        sys.exit()
    elif d[0][i] == 1 and d[1][i] == 1 and d[2][i] == 1:
        print("Yes")
        sys.exit()
if d[0][0] == 1 and d[1][1] == 1 and d[2][2] == 1:
    print("Yes")
    sys.exit()
elif d[2][0] == 1 and d[1][1] == 1 and d[0][2] == 1:
    print("Yes")
    sys.exit()
print("No")

Solution (Python):


import sys
import math
import itertools

def main():
    a = [[int(x) for x in sys.stdin.readline().split()] for _ in range(3)]
    n = int(sys.stdin.readline().strip())
    bs = [int(sys.stdin.readline().strip()) for _ in range(n)]

    amap = {a[i][j]: (i, j) for i, j in itertools.product(range(3), range(3))}
    hit = [[False, False, False] for _ in range(3)]

    for b in bs:
        if b in amap:
            i, j = amap[b]
            hit[i][j] = True

    if any(all(hit[i][j] for j in range(3)) for i in range(3)):
        print('Yes')
        return
    if any(all(hit[i][j] for i in range(3)) for j in range(3)):
        print('Yes')
        return
    if ((hit[0][0] and hit[1][1] and hit[2][2])
            or (hit[0][2] and hit[1][1] and hit[2][0])):
        print('Yes')
        return
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):


import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

A = LRI(3)
N = I()
B = [b[0] for b in LRI(N)]

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

flag = False
for i in range(3):
    if A[0][i] == -1 and A[1][i] == -1 and A[2][i] == -1:
        flag = True
    if A[i][0] == -1 and A[i][1] == -1 and A[i][2] == -1:
        flag = True

if A[0][0] == -1 and A[1][1] == -1 and A[2][2] == -1:
        flag = True
if A[0][2] == -1 and A[1][1] == -1 and A[2][0] == -1:
        flag = True

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

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A = [None] * 3
    for i in range(3):
        A[i] = i2nn()
    N = i2n()
    b = set()
    for i in range(N):
        b.add(i2n())
    for i in range(3):
        if len(set(A[i]) & b) == 3:
            print('Yes')
            return
        if len({A[j][i] for j in range(3)} & b) == 3:
            print('Yes')
            return
    if len({A[0][0], A[1][1], A[2][2]} & b) == 3:
        print('Yes')
        return
    if len({A[0][2], A[1][1], A[2][0]} & b) == 3:
        print('Yes')
        return
    print('No')
    return

main()

Solution (Python):
A = []
A.append(map(int, raw_input().split()))
A.append(map(int, raw_input().split()))
A.append(map(int, raw_input().split()))
N = int(raw_input())

for i in range(N):
     b = int(raw_input())
     for j in range(3):
         for k in range(3):
             if A[j][k] == b:
                 A[j][k] = 0

flag = False


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

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

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

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

Solution (Python):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
b_set = set(b)

f = [[0] * 3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b_set:
            f[i][j] = 1

for i in range(3):
    if all(f[i]):
        print('Yes')
        exit()

for i in zip(*f):
    if all(i):
        print('Yes')
        exit()

if f[0][0] == 1 and f[1][1] == 1 and f[2][2] == 1:
    print('Yes')
    exit()

if f[0][2] == 1 and f[1][1] == 1 and f[2][0] == 1:
    print('Yes')
    exit()

print('No')

Solution (Python):
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
t1 = [0,0,0]
t2 = [0,0,0]
t3 = [0,0,0]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        if a1[i]==b: t1[i]=1
        if a2[i]==b: t2[i]=1
        if a3[i]==b: t3[i]=1

l=[1,1,1]
if t1==l or t2==l or t3==l:
    print('Yes')
    exit(0)
if [t1[0],t2[0],t3[0]]==l or [t1[1],t2[1],t3[1]]==l or [t1[2],t2[2],t3[2]]==l:
    print('Yes')
    exit(0)
if [t1[0],t2[1],t3[2]]==l or [t1[2],t2[1],t3[0]]==l:
    print('Yes')
    exit(0)
print('No')

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

hantei=[False]*9

for b in B:
    for i in range(9):
        if A[i%3][i//3]==b:
            hantei[i]=True
OK=[True, True, True]
flag=0
if hantei[0:3]==OK or hantei[3:6]==OK or hantei[6:9]==OK:
    flag=1
elif hantei[0::3]==OK or hantei[1::3]==OK or hantei[2::3]==OK:
    flag=1
elif hantei[0]==True and hantei[4]==True and hantei[8]==True:
    flag=1
elif hantei[2]==True and hantei[4]==True and hantei[6]==True:
    flag=1
print('Yes' if flag else 'No')

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


A = [LMI() for _ in range(3)]
N = I()
B = [I() for _ in range(N)]

bingo = [[False] * 3 for _ in range(3)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True
if all(bingo[0]) or all(bingo[1]) or all(bingo[2]):
    print('Yes')
elif all(row[0] for row in bingo) or all(row[1] for row in bingo) or all(row[2] for row in bingo):
    print('Yes')
elif bingo[0][0] and bingo[1][1] and bingo[2][2]:
    print('Yes')
elif bingo[0][2] and bingo[1][1] and bingo[2][0]:
    print('Yes')
else:
    print('No')

Solution (Python):

import sys
import math



def check(innum):
	for i in range(3):
		for j in range(3):
			if(a[i][j]==innum):
				a[i][j]=-1
	if(a[0][0]==-1)and(a[1][0]==-1)and(a[2][0]==-1):
		print("Yes")
		sys.exit()
	if(a[0][1]==-1)and(a[1][1]==-1)and(a[2][1]==-1):
		print("Yes")
		sys.exit()
	if(a[0][2]==-1)and(a[1][2]==-1)and(a[2][2]==-1):
		print("Yes")
		sys.exit()
	if(a[0][0]==-1)and(a[0][1]==-1)and(a[0][2]==-1):
		print("Yes")
		sys.exit()
	if(a[1][0]==-1)and(a[1][1]==-1)and(a[1][2]==-1):
		print("Yes")
		sys.exit()
	if(a[2][0]==-1)and(a[2][1]==-1)and(a[2][2]==-1):
		print("Yes")
		sys.exit()
	if(a[0][0]==-1)and(a[1][1]==-1)and(a[2][2]==-1):
		print("Yes")
		sys.exit()
	if(a[0][2]==-1)and(a[1][1]==-1)and(a[2][0]==-1):
		print("Yes")
		sys.exit()




a=[[],[],[]]
tmp = input().split()
a[0] = list(map(lambda a: int(a), tmp))
tmp = input().split()
a[1] = list(map(lambda a: int(a), tmp))
tmp = input().split()
a[2] = list(map(lambda a: int(a), tmp))

n=int(input())

for i in range(n):
	b=int(input())
	check(b)
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())
b=[int(input()) for _ in range(N)]
ans="No"
for i in range(N):
    if b[i] in A1:
        A1[A1.index(b[i])]=0
    elif b[i] in A2:
        A2[A2.index(b[i])]=0
    elif b[i] in A3:
        A3[A3.index(b[i])]=0
for j in range(3):
    if A1[j]==A2[j]==A3[j]==0:
        ans="Yes"
        break
if sum(A1)==0 or sum(A2)==0 or sum(A3)==0:
    ans="Yes"
elif A1[0]==A2[1]==A3[2]==0 or A3[0]==A2[1]==A3[0]==0:
    ans="Yes"
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = [LIST() for i in range(3)]
N = INT()
B = [INT() for i in range(N)]
T = [[False] * 3 for i in range(3)]

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


for i in range(3):
    if T[i][0] == T[i][1] == T[i][2] == True:
        print("Yes")
        exit()
for i in range(3):
    if T[0][i] == T[1][i] == T[2][i] == True:
        print("Yes")
        exit()

if T[0][0] == T[1][1] == T[2][2] == True:
    print("Yes")
    exit()
if T[0][2] == T[1][1] == T[2][0] == True:
    print("Yes")
    exit()

print("No")

Solution (Python):
A=[[int(i) for i in input().split()] for q in range(3)]
n=int(input())

tar=[]
for i in range(n):
    ck=int(input())
    for p in range(9):
        if A[p//3][p%3]==ck:
            tar.append(p)

def check(a,b,c):
    if a in tar and b in tar and c in tar:
        return 1
    else:
        return 0

res=check(0,1,2)+check(3,4,5)+check(6,7,8)+check(0,3,6)+check(1,4,7)+check(2,5,8)+check(0,4,8)+check(2,4,6)
if res==0:
    print("No")
else:
    print("Yes")

Solution (Python):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
bingo = [A1,A2,A3]
N = int(input())
for _ in range(N):
    b = int(input())
    for k in bingo:
        if b in k:
            k[k.index(b)] = 0

clear = False
for k in bingo:
    if sum(k) == 0:
        clear = True
for i in range(3):
    if bingo[0][i] + bingo[1][i] + bingo[2][i] == 0:
        clear = True
if bingo[0][0] + bingo[1][1] + bingo[2][2] == 0:
    clear = True
if bingo[0][2] + bingo[1][1] + bingo[2][0] == 0:
    clear = True

if clear == True:
    print("Yes")
else:
    print("No")

Solution (Python):
A = list(map(int , input().split()))
B = list(map(int , input().split()))
C = list(map(int , input().split()))
N = int(input())
num = []
for i in range(N):
    num.append(int(input()))
bingo = {
    1:0,
    2:0,
    3:0,
    4:0,
    5:0,
    6:0,
    7:0,
    8:0,
    9:0
}
for i in range(len(A)):
    if A[i] in num:
        bingo[i+1] = 1
for i in range(len(B)):
    if B[i] in num:
        bingo[i+4] = 1
for i in range(len(C)):
    if C[i] in num:
        bingo[i+7] = 1
        
if bingo[1] == 1 and bingo[2] == 1 and bingo[3] == 1:
    ans = 'Yes'
elif bingo[4] == 1 and bingo[5] == 1 and bingo[6] == 1:
    ans = 'Yes'
elif bingo[7] == 1 and bingo[8] == 1 and bingo[9] == 1:
    ans = 'Yes'

elif bingo[1] == 1 and bingo[4] == 1 and bingo[7] == 1:
    ans = 'Yes'
elif bingo[2] == 1 and bingo[5] == 1 and bingo[8] == 1:
    ans = 'Yes'
elif bingo[3] == 1 and bingo[6] == 1 and bingo[9] == 1:
    ans = 'Yes'

elif bingo[1] == 1 and bingo[5] == 1 and bingo[9] == 1:
    ans = 'Yes'
elif bingo[3] == 1 and bingo[5] == 1 and bingo[7] == 1:
    ans = 'Yes'

else:
    ans = 'No'
print(ans)

Solution (Python):
from collections import Counter

def row(M, li):
    
    for i in range(3):
        bad = False
        r = Mat[i]
        c = Counter(r)
        for k,v in c.items():
            if li.get(k, 0) < v:
                bad = True
        if not bad:
            return True

    return False

def col(M, li):
    for Col in zip(*M):
        bad = False
        c = Counter(Col)
        for k, v in c.items():
            if li.get(k, 0) < v:
                bad = True

        if not bad:
            return True

    return False

def r_diag(M, li):
    it = []
    for i in range(3):
        it.append(M[i][i])
    c = Counter(it)
    for k,v in c.items():
        if li.get(k, 0) < v:
            return False

    return True

def l_diag(M, li):
    it = []
    for i in range(3):
        it.append(M[i][3-i-1])
    c = Counter(it)
    for k,v in c.items():
        if li.get(k, 0) < v:
            return False

    return True

def solve(M ,li):
    if row(M, li) or col(M, li) or r_diag(M, li) or l_diag(M, li):
        return "Yes"

    return "No"
Mat = []
for i in range(3):
    li = list(map(int, input().split()))
    Mat.append(li)

n = int(input())
li = {}
for i in range(n):
    a = int(input())
    li[a] = li.get(a, 0) + 1

print(solve(Mat, li))

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

for i in b:
    for j in range(3):
        for k in range(3):
            if a[j][k] == i:
                p[j][k] = 1
                
ans = False
for i in range(3):
    w = True
    for j in range(3):       
        if p[i][j] != 1:
            w = False
            break
            
    if w:
        ans = True
        
for i in range(3):
    w = True
    for j in range(3):       
        if p[j][i] != 1:
            w = False
            break
            
    if w:
        ans = True
        
if p[0][0] == 1 and p[1][1] == 1 and p[2][2] == 1:
    ans = True
    
if p[0][2] == 1 and p[1][1] == 1 and p[2][0] == 1:
    ans = True

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

Solution (Python):
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b={int(input()) for _ in range(n)}
FLAG=False
for i in range(3):
  if a[i][0] in b and a[i][1] in b and a[i][2] in b:
    FLAG=True
  if a[0][i] in b and a[1][i] in b and a[2][i] in b:
    FLAG=True
_FLAG=True
for i in range(2):
  if a[i][i] not in b:
    _FLAG=False
if _FLAG:
  FLAG=True
_FLAG=True
for i in range(2):
  if a[i][-1-i] not in b:
    _FLAG=False
if _FLAG:
  FLAG=True
if FLAG:
  print("Yes")
else:
  print("No")

Solution (Python):

import sys
input = sys.stdin.readline

a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

def update_a(bi):
    for i in range(3):
        for j in range(3):
            if a[i][j]==bi:
                a[i][j]=-1
                return

def check_a():
    
    for ai in a:
        if sum(ai)==-3:
             return True
    
    for i in zip(a[0],a[1],a[2]):
        if sum(i)==-3:
             return True

    
    temp = 0
    for i in range(3):
        temp += a[i][i]
        if temp==-3:
            return True

    
    temp = 0
    for i in range(3):
        temp += a[i][2-i]
        if temp==-3:
            return True
    return False

for bi in b:
    update_a(bi)
if check_a():
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
  sheet = []
  for _ in range(3):
    sheet.append(list(input_list()))
  n = int(input())
  numbers = []
  for _ in range(n):
    numbers.append(int(input()))
  
  ans = []
  for i, row in enumerate(sheet):
    a = []
    for j, num in enumerate(row):
      if num in numbers:
        a.append(True)
      else:
        a.append(False)
    ans.append(a)
  
  if ans[0][0] and ans[0][1] and ans[0][2]:
    print('Yes')
    exit()
  if ans[1][0] and ans[1][1] and ans[1][2]:
    print('Yes')
    exit()
  if ans[2][0] and ans[2][1] and ans[2][2]:
    print('Yes')
    exit()
  if ans[0][0] and ans[1][0] and ans[2][0]:
    print('Yes')
    exit()
  if ans[0][1] and ans[1][1] and ans[2][1]:
    print('Yes')
    exit()
  if ans[0][2] and ans[1][2] and ans[2][2]:
    print('Yes')
    exit()
  if ans[0][0] and ans[1][1] and ans[2][2]:
    print('Yes')
    exit()
  if ans[0][2] and ans[1][1] and ans[2][0]:
    print('Yes')
    exit()
  print('No')
  
def input_list():
  return map(int, input().split())

import math
import fractions
main()

Solution (Python):
A=[tuple(map(int, input().split())) for _ in range(3)]
N=int(input())
B=[int(input())for _ in range(N)]
C=[[False]*3 for _ in range(3)]
for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                C[i][j]=True
ans=False
for i in range(3):
    ans|=all(C[i][j] for j in range(3))
    ans|=all(C[j][i] for j in range(3))
ans|=all(C[j][j] for j in range(3))
ans|=all(C[2-j][j] for j in range(3))
print("YNeos"[not ans::2])

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

ans = 'Yes'
for i in range(3):
    cnt = 0
    for j in range(3):
        if a[i][j] != 0:
            break
        else:
            cnt += 1
    if cnt == 3:
        break
        
if cnt == 3:
    print(ans)
    exit()

for i in range(3):
    cnt = 0
    for j in range(3):
        if a[j][i] != 0:
            break
        else:
            cnt += 1
    if cnt == 3:
        break

if cnt == 3:
    print(ans)
    exit()

if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print('Yes')
    exit()

if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    print('Yes')
else:
    print('No')

Solution (Python):

import sys


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 t in b:
    for i in range(3):
        for j in range(3):
            if A[i][j]==t:
                flag[i][j] = True
    
f = False
for i in range(3):
    tate = flag[i][0]
    yoko = flag[0][i]
    for j in range(1,3):
        tate = tate and flag[i][j]
        yoko = yoko and flag[j][i]
    f = f or tate or yoko
    
na1 = flag[0][0] and flag[1][1] and flag[2][2]
na2 = flag[0][2] and flag[1][1] and flag[2][0]

if f or na1 or na2:
    print('Yes')
else:
    print('No')

Solution (Python):
a=[0]*9
u=[0]*9
unchimode=False
a[0],a[1],a[2]=map(int,input().split())
a[3],a[4],a[5]=map(int,input().split())
a[6],a[7],a[8]=map(int,input().split())
n = int(input())
b=[]
for i in range(n):
  hantei = int(input())
  for t in range(9):
    if a[t]==hantei:
      u[t]=1
if u[0]==1 and u[1]==1 and u[2]==1:
  unchimode=True
elif u[3]==1 and u[4]==1 and u[5]==1:
  unchimode=True
elif u[6]==1 and u[7]==1 and u[8]==1:
  unchimode=True
elif u[0]==1 and u[3]==1 and u[6]==1:
  unchimode=True
elif u[1]==1 and u[4]==1 and u[7]==1:
  unchimode=True
elif u[2]==1 and u[5]==1 and u[8]==1:
  unchimode=True
elif u[0]==1 and u[4]==1 and u[8]==1:
  unchimode=True
elif u[2]==1 and u[4]==1 and u[6]==1:
  unchimode=True
if unchimode:
  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 b == A[i][j]:
                A[i][j] = 'x'
f = False
for i in range(3):
    if all(a == 'x' for a in A[i]):
        f = True
if all((A[0][0] == 'x', A[1][1] == 'x', A[2][2] == 'x')):
    f = True
if all((A[0][2] == 'x', A[1][1] == 'x', A[2][0] == 'x')):
    f = True
for j in range(3):
    tmp = []
    for i in range(3):
        tmp.append(A[i][j])
    if all(a == 'x' for a in tmp):
        f = True
print('Yes' if f else 'No')

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

for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==A[j][k]:
                A[j][k]=0

if (A[0][0]==0 and A[0][1]==0 and A[0][2]==0)\
or (A[1][0]==0 and A[1][1]==0 and A[1][2]==0)\
or (A[2][0]==0 and A[2][1]==0 and A[2][2]==0)\
or (A[0][0]==0 and A[1][0]==0 and A[2][0]==0)\
or (A[0][1]==0 and A[1][1]==0 and A[2][1]==0)\
or (A[0][2]==0 and A[1][2]==0 and A[2][2]==0)\
or (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):
    print('Yes')
else:
    print('No')

Solution (Python):
As = []
As.append(list(map(lambda x: int(x), input().split(" "))))
As.append(list(map(lambda x: int(x), input().split(" "))))
As.append(list(map(lambda x: int(x), input().split(" "))))
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if As[i][j] == b:
                As[i][j] = 0

flag = False
for i in range(3):
    if flag:
        break
    temp_flag = True
    for j in range(3):
        if As[i][j] != 0:
            temp_flag = False
    flag = temp_flag
for i in range(3):
    if flag:
        break
    temp_flag = True
    for j in range(3):
        if As[j][i] != 0:
            temp_flag = False
    flag = temp_flag

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

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

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))


def main():
	A = []
	for i in range(3):
		a = getlist()
		A.append(a)
	bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

	N = int(input())
	for k in range(N):
		b = int(input())
		for i in range(3):
			for j in range(3):
				if A[i][j] == b:
					bingo[i][j] = 1
	
	judge = "No"
	for i in range(3):
		if bingo[i][0] == 1 and bingo[i][1] == 1 and bingo[i][2] == 1:
			judge = "Yes"
	for i in range(3):
		if bingo[0][i] == 1 and bingo[1][i] == 1 and bingo[2][i] == 1:
			judge = "Yes"

	if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
		judge = "Yes"
	if bingo[2][0] == 1 and bingo[1][1] == 1 and bingo[0][2] == 1:
		judge = "Yes"

	print(judge)

if __name__ == '__main__':
	main()

Solution (Python):
a_list=[]
a_list+=(list(map(int,input().split())))
a_list+=(list(map(int,input().split())))
a_list+=(list(map(int,input().split())))

N=int(input())

b_list=[False]*9
for i in range(N):
    b=int(input())
    for j,a in enumerate(a_list):
        if a==b:
            b_list[j]=True

kumi=[
    [0,1,2],
    [3,4,5],
    [6,7,8],
    [0,3,6],
    [1,4,7],
    [2,5,8],
    [0,4,8],
    [2,4,6]
]

ans="No"
for k in kumi:
    if b_list[k[0]]*b_list[k[1]]*b_list[k[2]]:
        ans="Yes"

print(ans)

Solution (Python):





da = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for k in range(3):
    for i in range(3):
        for j in range(n):
            if(da[k][i] == b[j]):
                da[k][i] = 0
                break
ju = False
for i in range(3):
    if(da[i][0] == 0 and da[i][1] == 0 and da[i][2] == 0):
        ju = True
    if(da[1][i] == 0 and da[2][i] == 0 and da[0][i] == 0):
        ju = True
if da[0][0] == 0 and da[1][1] == 0 and da[2][2] == 0:
    ju = True
if da[0][2] == 0 and da[1][1] == 0 and da[2][0] == 0:
    ju = True

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

Solution (Python):
ls = []
for i in range(3):
    a = list(map(int,input().split()))
    ls.append(a)
lb = []
n = int(input())
for i in range(n):
    b = int(input())
    lb.append(b)
    
for i in range(n):
    for j in range(3):
        for k in range(3):
            if lb[i] == ls[j][k]:
                ls[j][k] = "
if ls[0][0] == "
    print("Yes")
elif ls[0][1] == "
    print("Yes")
elif ls[0][2] == "
    print("Yes")
elif ls[0][0] == "
    print("Yes")
elif ls[1][0] == "
    print("Yes")
elif ls[2][0] == "
    print("Yes")
elif ls[0][0] == "
    print("Yes")
elif ls[0][2] == "
    print("Yes")
else:
    print("No")

Solution (Python):
def read():
    A = list()
    for i in range(3):
        a = list(map(int, input().strip().split()))
        A.append(a)
    N = int(input().strip())
    B = list()
    for i in range(N):
        b = int(input().strip())
        B.append(b)
    return A, N, B

def solve(A, N, B):
    lines = [
        [(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)]
    ]
    C = [[False for j in range(3)] for i in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    C[i][j] = True
    for line in lines:
        is_bingo = True
        for r, c in line:
            if not C[r][c]:
                is_bingo = False
        if is_bingo:
            return 'Yes'
    return 'No'


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A = [[] for _ in range(3)]
    for i in range(3):
        A[i] = lr()
    N = ir()
    card = [[False, False, False] for _ in range(3)]
    for i in range(N):
        b = ir()
        for j in range(3):
            for k in range(3):
                if A[j][k] == b:
                    card[j][k] = True
    for i in range(3):
        if card[i] == [True, True, True]:
            print('Yes')
            return
    for i in range(3):
        if card[0][i] == True and card[1][i] == True and card[2][i] == True:
            print('Yes')
            return
    if card[0][0] == True and card[1][1] == True and card[2][2] == True:
        print('Yes')
        return
    if card[2][0] == True and card[1][1] == True and card[0][2] == True:
        print('Yes')
        return
    print('No')
resolve()

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = [lr() for _ in range(3)]
N = ir()
bool = [[False] * 3 for _ in range(3)]
for _ in range(N):
    b = ir()
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bool[i][j] = True

answer = False
for i in range(3):
    if sum(bool[i]) == 3:
        answer = True
for j in range(3):
    cur = 0
    for i in range(3):
        if bool[i][j] == True:
            cur += 1
    if cur == 3:
        answer = True

if bool[0][0] + bool[1][1] + bool[2][2] == 3:
    answer = True
if bool[2][0] + bool[1][1] + bool[2][0] == 3:
    answer = True

print('Yes' if answer else 'No')