Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split()))
D=list(map(int,input().split()))
like=[]
for i in range(10):
    if not i in D:
        like.append(i)
N=str(n)
ans=[]
for i in range(len(N)):
    for j in range(len(like)):
        if like[j]>=int(N[i]):
            ans.append(like[j])
            break
    else:
        if not like[0]==0:
            ans.append(like[1])
        else:
            ans.append(like[0])
        for i in range(len(N)):
            ans.append(like[0])
        break
    if ans[i]>int(N[i]):
        for i in range(i+1,len(N)):
            ans.append(like[0])
        break

answer=''.join(map(str,ans))
print(int(answer))

Fixed submission:
N,k=map(int,input().split())
D=set(input().split())

for i in range(N,88889):
    for s in str(i):
        if s in D:
            break
    else:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(a, m))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)
  

Fixed submission:
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(range(1, m + 1), n))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)

Buggy python submission (verdict: Runtime Error):
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
num_list = sorted(num_list, reverse=True, key=lambda x: x[3])
ff = list(itertools.combinations_with_replacement(a, m))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)

Fixed submission:
import itertools

n,m,q = input().split()
n = int(n)
m = int(m)
q = int(q)
num_list = []
a = list(range(1, n+1))
for i in range(q):
    num_list.append(list(map(int,input().split())))
ff = list(itertools.combinations_with_replacement(range(1, m + 1), n))
max = 0
for i in range(len(ff)):
  s = 0
  for j in range(q):
    a,b,c,d = num_list[j]
    if ff[i][b-1] - ff[i][a-1] == c:
      s = s + d
  if max < s:
        max = s
print(max)
Buggy python submission (verdict: Runtime Error):
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])

p_list = sorted([int(a) for a in input().split(' ')]).reverse()
q_list = sorted([int(a) for a in input().split(' ')]).reverse()
r_list = sorted([int(a) for a in input().split(' ')]).reverse()

xapples = p_list[0:x+1]
yapples = q_list[0:y+1]
zapples = r_list[0:x+y+1]

apples = sorted(xapples.extend(yapples).extend(zapples)).reverse()[0:x+y+1]
print(sum(apples))


Fixed submission:
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])
 
p_list = sorted([int(a) for a in input().split(' ')])
q_list = sorted([int(a) for a in input().split(' ')])
r_list = sorted([int(a) for a in input().split(' ')])
p_list.reverse()
q_list.reverse()
r_list.reverse()
 
xapples = p_list[0:x]
yapples = q_list[0:y]
zapples = r_list[0:x+y]
 
xapples.extend(yapples)
xapples.extend(zapples)
tmp_apples = sorted(xapples)
tmp_apples.reverse()
apples = tmp_apples[0:x+y]
print(sum(apples))
Buggy python submission (verdict: Runtime Error):
2 2 1
3 5
3 5
2 2 2

Fixed submission:
val = input().split(' ')
a = int(val[0])
b = int(val[1])
m = int(val[2])

alist = [int(a) for a in input().split(' ')]
blist = [int(b) for b in input().split(' ')]

min_price = sorted(alist)[0] + sorted(blist)[0]

for i in range(m):
    discount = [int(m) for m in input().split(' ')]
    price = alist[discount[0] - 1] + blist[discount[1] - 1] - discount[2]
    if price < min_price:
        min_price = price

print(min_price)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s.reverse()
    else:
        t2, f, c = t.split()
        if f == "1":
            s.insert(0, c)
        elif f == "2":
            s.append(c)
print("".join(s))


Fixed submission:
s = input()
q = int(input())

is_reverse = False
front_queue = []
back_queue = []
for i in range(q):
    t = input()
    if t == "1":
        is_reverse = not is_reverse
    else:
        t2, f, c = t.split()
        if (f == "1" and not is_reverse) or (f == "2" and is_reverse):
            front_queue.append(c)
        else:
            back_queue.append(c)

result = ""
if is_reverse:
    result = "".join(reversed(back_queue)) + s[::-1] + "".join(front_queue)
else:
    result = "".join(reversed(front_queue)) + s + "".join(back_queue)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s = s[::-1]
    else:
        t2, f, c = t.split()
        if f == "1":
            s = c + s
        elif f == "2":
            s += c

print(s)


Fixed submission:
s = input()
q = int(input())

is_reverse = False
front_queue = []
back_queue = []
for i in range(q):
    t = input()
    if t == "1":
        is_reverse = not is_reverse
    else:
        t2, f, c = t.split()
        if (f == "1" and not is_reverse) or (f == "2" and is_reverse):
            front_queue.append(c)
        else:
            back_queue.append(c)

result = ""
if is_reverse:
    result = "".join(reversed(back_queue)) + s[::-1] + "".join(front_queue)
else:
    result = "".join(reversed(front_queue)) + s + "".join(back_queue)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s = s[::-1]
    else:
        t2, f, c = t.split()
        if f == "1":
            s = c + s
        elif f == "2":
            s += c

print(s)


Fixed submission:
s = input()
q = int(input())

is_reverse = False
front_queue = []
back_queue = []
for i in range(q):
    t = input()
    if t == "1":
        is_reverse = not is_reverse
    else:
        t2, f, c = t.split()
        if (f == "1" and not is_reverse) or (f == "2" and is_reverse):
            front_queue.append(c)
        else:
            back_queue.append(c)

result = ""
if is_reverse:
    result = "".join(reversed(back_queue)) + s[::-1] + "".join(front_queue)
else:
    result = "".join(reversed(front_queue)) + s + "".join(back_queue)
print(result)
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())


for c in range(101):
    if c % 2 ==0:
        C = C-B
        if C <=0:
            ans = 'Yes'
            break
    else:
        A =A-D
        if A <=0:
            ans = 'No'
            break
#     print(A,B,C,D)
print(ans)

            


Fixed submission:
A,B,C,D = map(int,input().split())


for c in range(205):
    if c % 2 ==0:
        C = C-B
        if C <=0:
            ans = 'Yes'
            break
    else:
        A =A-D
        if A <=0:
            ans = 'No'
            break
#     print(A,B,C,D)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R = []
G = []
B = []

count = 0
for s in S:
    if s == "R":
        R.append(count)
    elif s == "G":
        G.append(count)
    elif s == "B":
        B.append(count)
    count += 1

def checker(i,E,F):
    wa =0
    EE = [x for x in E if x > i]
    FF = [x for x in F if x > i]
    for e in EE:
        for f in FF:
            if i>e or i > f:
                pass
            else:
                if f > e and e-i != f-e:
                    wa += 1
                elif e > f and f-i != e-f:
                    wa += 1
    return(wa)

goukei = 0
for i in range(N):
    s = S[i]
    if s == "R":
        goukei += checker(i,G,B)
    elif s == "G":
        goukei += checker(i,R,B)
    elif s == "B":
        goukei += checker(i,R,G)

print(goukei)

Fixed submission:
N = int(input())
S =  input()

nR = 0
nG = 0
nB = 0

for s in S:
    if s == "R":
        nR += 1
    elif s == "G":
        nG += 1
    elif s == "B":
        nB += 1
        
c1pat = nR*nG*nB

mcount = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = j + (j-i)
        if k < N:
#             print(i,j,k)
            if set([S[i],S[j],S[k]]) == set(["R","G","B"]):
                mcount += 1
                
                
print(c1pat - mcount)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

R = []
G = []
B = []

count = 0
for s in S:
    if s == "R":
        R.append(count)
    elif s == "G":
        G.append(count)
    elif s == "B":
        B.append(count)
    count += 1

def checker(i,E,F):
    wa =0
    for e in E:
        for f in F:
            if i>e or i > f:
                pass
            else:
                if f > e and e-i != f-e:
                    wa += 1
                elif e > f and f-i != e-f:
                    wa += 1
    return(wa)

goukei = 0
for i in range(N):
    s = S[i]
    if s == "R":
        goukei += checker(i,G,B)
    elif s == "G":
        goukei += checker(i,R,B)
    elif s == "B":
        goukei += checker(i,R,G)

print(goukei)

Fixed submission:
N = int(input())
S =  input()

nR = 0
nG = 0
nB = 0

for s in S:
    if s == "R":
        nR += 1
    elif s == "G":
        nG += 1
    elif s == "B":
        nB += 1
        
c1pat = nR*nG*nB

mcount = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = j + (j-i)
        if k < N:
#             print(i,j,k)
            if set([S[i],S[j],S[k]]) == set(["R","G","B"]):
                mcount += 1
                
                
print(c1pat - mcount)
Buggy python submission (verdict: Runtime Error):
    from collections import defaultdict as dd
    N,X,Y = map(int,input().split())
     
    pdic = dd(lambda:0)
     
    # count = 0
     
    for i in range(1,N):
        for j in range(i+1,N+1):
            
    #         count += 1
            
            # no shortcut
            d1 = j-i
            # with shortcut
            i2x = abs(X-i)
            y2j = abs(Y-j)
            d2 = i2x + y2j + 1
            
            dist = min(d1,d2)
            pdic[str(dist)] += 1
            
    for n in range(1,N):
        print(pdic[str(n)])
        
    # print("count:",count)

Fixed submission:
from collections import defaultdict as dd
N,X,Y = map(int,input().split())

pdic = dd(lambda:0)

# count = 0

for i in range(1,N):
    for j in range(i+1,N+1):

#         count += 1

        # no shortcut
        d1 = j-i
        # with shortcut
        i2x = abs(X-i)
        y2j = abs(Y-j)
        d2 = i2x + y2j + 1

        dist = min(d1,d2)
        pdic[str(dist)] += 1

for n in range(1,N):
    print(pdic[str(n)])

# print("count:",count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
N,X,Y = map(int,input().split())

pdic = dd(lambda:0)

# count = 0

for i in range(1,N):
    for j in range(i+1,N+1):
        
#         count += 1
        
        # no shortcut
        d1 = j-i
        # with shortcut
        i2x = abs(X-i)
        y2j = abs(Y-j)
        d2 = i2x + y2j + 1
        
        dist = min(d1,d2)
        pdic[str(dist)] += 1
        
for n in range(1,N):
    print(pdic[str(n)])
    
# print("count:",count)

Fixed submission:
from collections import defaultdict as dd
N,X,Y = map(int,input().split())

pdic = dd(lambda:0)

# count = 0

for i in range(1,N):
    for j in range(i+1,N+1):

#         count += 1

        # no shortcut
        d1 = j-i
        # with shortcut
        i2x = abs(X-i)
        y2j = abs(Y-j)
        d2 = i2x + y2j + 1

        dist = min(d1,d2)
        pdic[str(dist)] += 1

for n in range(1,N):
    print(pdic[str(n)])

# print("count:",count)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

hanten = 0

for q in range(Q):
    query = input()
    if query == "1":
        if hanten == 0:
            hanten = 1
        else:
            hanten = 0
    else:
        T,F,C = query.split()
        if F == "1":
            if hanten == 0:
                S = C+S
            else:
                S = S+C
        elif F =="2":
            if hanten == 0:
                S = S + C
            else:
                S = C + S
            
if hanten == 0:
    print(S)
else:
    print(S[::-1])


Fixed submission:
Slist = list(input())
Q = int(input())

hanten = 0
mae = [] # 後で反転
ushiro = []

for q in range(Q):
    query = input()
    if query == "1":
        if hanten == 0:
            hanten = 1
        else:
            hanten = 0
    else:
        T,F,C = query.split()
        if F == "1":
            if hanten == 0:
                mae.append(C)
            else:
                ushiro.append(C)
        elif F =="2":
            if hanten == 0:
                ushiro.append(C)
            else:
                mae.append(C)
# print("hanten:",hanten,"mae:",mae,"ushiro:",ushiro)            
if hanten == 0:
    rmae = mae[::-1]
    goukei = rmae + Slist + ushiro
    print(''.join(goukei))
else:
    goukei =ushiro[::-1] + Slist[::-1] + mae
    print(''.join(goukei))
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
PP = list(map(int,input().split()))


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum
            
print(ksum)
time3 = datetime.now()

       




Fixed submission:
S,T = input().split()
A,B = map(int,input().split())
U = input()
if U ==S:
    print(A-1,B)
else:
    print(A,B-1)
Buggy python submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
C = B - A

if C == 1:
    kabe = int(min(N-B,A-1))
    print(kabe + 1)
elif C % 2 == 0:
    print(int(C / 2))
else:
    NB = N-B
    A1 = A-1
    if NB < A1:
        NA = N-A
        zan = int((NA-NB-1)/2)
        print(int(NB+1+zan))
    else:
        zan = int(((B-1)-A1-1)/2)
        print(int(A1+1+zan)
    

Fixed submission:
N,A,B = map(int,input().split())

C = B-A

if C % 2 == 0:
    print(C//2)
else:
    a = min(A-1, N-B) + 1 + (B-A-1)//2
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
'''連徐法を利用した別バージョン'''
A,B = map(int, input().split())

M = max(A,B)//2
# print(M)
CoP = set([1])

for i in range(1,M):
    Co_flg = 1
#     print(i+1, A % (i+1), B % (i+1))
    while Co_flg:
        
        if A % (i+1) == 0 and B % (i+1) == 0:
            CoP.add(i+1)
            A = A /(i+1)
            B = B /(i+1)
#             print(A,B)
        else:
            Co_flg = 0

# print(CoP)
print(len(CoP))

Fixed submission:
A,B = map(int, input().split())

#解法の大まかな流れ
#　AとBの素因数をそれぞれ計算し、And集合の長さを出す

#　数Nの素因数の算出方法
#  基本的には、Nを小さい数から順に割れるだけ割っていく（除算法）
#    割る数は素数だけでいい
# 課題：1～Aまでそれぞれ割って判定では計算量が足りない　A <= 10^12なので
# アイディア①：素数一覧表を作成して、一覧表に入っている数字だけで、割れるか判定
#  ⇒ 素数一覧表の作成の方が高コストになる可能性高い
# アイディア②： eratosthenesの篩の応用


def Soinsu(N):
    soinsu = set([1]) 
    if N > 1:
        # 偶数チェック（ここで引っ掛けられると割る数のカウントアップを倍にできるので)
        div2_flg = 1
        while div2_flg:
            if N % 2 == 0:
                soinsu.add(2)
                N = N/2
            else:
                div2_flg = 0
#         print("after 2: ",N)
        for i in range(3,int(N)+1,2):
#             print("i: ",i, " N: ",N)
        
            div_flg = 1
            while div_flg:
#                 print("   N: ",N)
                if N % i == 0:
                    soinsu.add(i)
                    N = N/i
                else:
                    div_flg = 0
            # 割る数の上限はN**(1/2)であることを適用
            if i**2 > N:
                break
        # 自分自身も入れる：これを入れないと片方がもう一方の素因数である場合を逃す
        soinsu.add(N)
        
    return(soinsu)
            
soi_A = Soinsu(A)
soi_B = Soinsu(B)
# print(soi_A)
# print(soi_B)
print(len(soi_A & soi_B))
Buggy python submission (verdict: Runtime Error):
    S = input()
    if S == "Sunny":
      print("Cloudy")
    elif S == "Cloudy":
      print("Rainy")
    elif S == "Rainy":
      print("Sunny")

Fixed submission:
S = input()
if S == "Sunny":
	print("Cloudy")
elif S == "Cloudy":
	print("Rainy")
elif S == "Rainy":
	print("Sunny")
Buggy python submission (verdict: Runtime Error):
S = input()

kisu = ['R', 'U', 'D']
gusu = ['L', 'U', 'D']

hard = 0

for i in range(len(S)):
    moji = S[i]
    if i % 2 == 0:
        if moji not in gusu:
            hard = 1
            break
    elif i % 2 == 1:
        if moji not in kisu:
            hard = 1
            break
if hard == 0:
    print("Yes")
elif:
    print("No")
            

Fixed submission:
S = input()

kisu = ['R', 'U', 'D']
gusu = ['L', 'U', 'D']

hard = 0
#S = "RDULULDURURLRDULRLR"

for i in range(len(S)):
    moji = S[i]
    if i % 2 == 1:
#        print("{} th : {} is in  Kisu(R,U,D)".format(i,moji))
        if moji not in gusu:
            hard = 1
            break
    if i % 2 == 0:
#        print("{} th : {} is in Gusu(L,U,D)".format(i,moji))
        if moji not in kisu:
            hard = 1
            break
if hard == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N,K,Q = map(int, input().split())
score_lst = [0] * N

for i in range(Q):
    Ai = input()
    score_lst[Ai - 1] += 1

def_socre = K - Q
for j in score_lst:
    if def_socre + j > 0:
        print("Yes")
    else:
        print("No")


Fixed submission:
N,K,Q = map(int, input().split())
score_lst = [0] * N

for i in range(Q):
    Ai = int(input())
    score_lst[Ai - 1] += 1

def_socre = K - Q
for j in score_lst:
    if def_socre + j > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
S = input()
ot = S[:2]
tf = S[2:]

isotMM = 0
istfMM = 0

if 0 < int(ot) and int(ot) < 13:
    isotMM = 1
if 0 < int(tf) and int(tf) < 13:
    istfMM = 1
    
if isotMM == 1:
    if istfMM == 1:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if istfMM == 1:
        print('YYMM')
    else:
        print(NA)

Fixed submission:
S = input()
ot = S[:2]
tf = S[2:]

isotMM = 0
istfMM = 0

if 0 < int(ot) and int(ot) < 13:
    isotMM = 1
if 0 < int(tf) and int(tf) < 13:
    istfMM = 1
    
if isotMM == 1:
    if istfMM == 1:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if istfMM == 1:
        print('YYMM')
    else:
        print("NA")
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal

N,K = map(int,input().split())

prob = Decimal(0)
for i in range(1,N+1):

    for j in range(18):
        if i*2**j >= K:
            prob += Decimal(1/2**j)
            break

print(prob/N)

Fixed submission:
N,K = map(int,input().split())

csum = 0
for i in range(1,N+1):
    c = 0
    flag = 1
    while flag:
        if i*2**c >= K:
            csum += 1/2**c
            flag = 0
        else:
            c += 1
print(csum/N)

Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal

N,K = map(int,input().split())

prob = Decimal(0)
for i in range(1,N+1):

    for j in range(20):
        if i*2**j >= K:
            prob += Decimal(1/2**j)
            break

print(prob/N)

Fixed submission:
N,K = map(int,input().split())

csum = 0
for i in range(1,N+1):
    c = 0
    flag = 1
    while flag:
        if i*2**c >= K:
            csum += 1/2**c
            flag = 0
        else:
            c += 1
print(csum/N)
Buggy python submission (verdict: Runtime Error):
s=  list(intput())
k  = int(s[-1])
if k in [2,4,7,9,5]:
  
  print('hon')
elif k in [0,1,6,8]:
  print('pon')
else:
  print('bon')   

Fixed submission:
s=  list(input())
k  = int(s[-1])
if k in [2,4,7,9,5]:
    print('hon')
elif k in [0,1,6,8]:
    print('pon')
else:
    print('bon')
Buggy python submission (verdict: Runtime Error):
import copy
import functools
import math

N = int(input())
A = sorted(list(map(int,input().split())))

C = []
for k in range(N):
    B = copy.copy(A)
    del B[k]
    C.append(functools.reduce(math.gcd, B))

print(max(C))

Fixed submission:
A, B, T = map(int,input().split())

ans = T // A * B

print(ans)
Buggy python submission (verdict: Runtime Error):
S = str(input())
f = []
l = []
ans = 'Yes'
for i in range((len(S)-1)/2):
    f.append(S[i])
    l.append(S[-i-1])
if f == l 

Fixed submission:
S = str(input())
f = []
l = []
ans = 'Yes'
for i in range(int((len(S)-1)/2)):
    f.append(S[i])
    l.append(S[-i-1])
for i in range(len(f)):
    if f[i] != l[-i-1]:
        ans = 'No'
print(ans)
Buggy python submission (verdict: Runtime Error):
A = []
B = set()
ans = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
for i in range(N):
    B.add(int(input()))

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

#ゴミコードだなぁ……

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

Fixed submission:
A = []
B = set()
ans = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
for i in range(N):
    B.add(int(input()))

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

#ゴミコードだなぁ……

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