Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    a = LI()
    if n == 1:
        while m > 0:
            a[0] = a[0] // 2
            m -= 1
        print(a[0])
        return
    a.sort()
    a.reverse()
    while m > 0:
        while a[0] >= a[1]:
            a[0] = a[0] // 2
            m -= 1

        a.sort()
        a.reverse()
    print(sum(a))


main()


Fixed submission:
#!/usr/bin/env python3
import sys
import heapq


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    a = LI()
    heap = []
    for i in range(n):
        heapq.heappush(heap, a[i] * -1)

    while m > 0:
        min_ = heapq.heappop(heap) * -1
        min_ = (min_ // 2) * -1
        heapq.heappush(heap, min_)
        m -= 1
    print(sum(heap) * -1)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
N,M = [int(X) for X  in input().split()]
A = [int(X) for X  in input().split()]
for i in range(M):
  A[A.index(max(A))] /=2

ans = 0
for i in A:
  ans += math.floor(i)
print(ans)

Fixed submission:
#!/usr/bin/env python3
import sys
import heapq


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    a = LI()
    heap = []
    for i in range(n):
        heapq.heappush(heap, a[i] * -1)

    while m > 0:
        min_ = heapq.heappop(heap) * -1
        min_ = (min_ // 2) * -1
        heapq.heappush(heap, min_)
        m -= 1
    print(sum(heap) * -1)


main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    words = []
    starts_with_B = 0
    end_with_A = 0
    contain_AB = 0
    starts_with_B_and_end_with_A = 0
    for i in range(N):
        word = input()
        words.append(word)
        contain_AB += len(word) - len(word.replace("AB", "_"))

        if word[0] == "B" and word[-1] == "A":
            starts_with_B_and_end_with_A += 1
        elif word[0] == "B":
            starts_with_B += 1
        elif word[-1] == "A":
            end_with_A += 1

    if starts_with_B_and_end_with_A == 0:
        print(contain_AB + min(starts_with_B, end_with_A))
        return

    min_A_or_B = min(starts_with_B, end_with_A)
    amari = abs(starts_with_B - end_with_A)
    contain_AB += min_A_or_B

    if amari == 0:
        print(contain_AB)

    if amari >= starts_with_B_and_end_with_A:
        print(contain_AB + starts_with_B_and_end_with_A)
    else:
        available = starts_with_B_and_end_with_A // amari
        contain_AB += available * amari
        starts_with_B_and_end_with_A = starts_with_B % amari
        print(contain_AB + starts_with_B_and_end_with_A)


main()


Fixed submission:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    words = []
    starts_with_B = 0
    end_with_A = 0
    contain_AB = 0
    starts_with_B_and_end_with_A = 0
    for i in range(N):
        word = input()
        words.append(word)
        contain_AB += len(word) - len(word.replace("AB", "_"))

        if word[0] == "B" and word[-1] == "A":
            starts_with_B_and_end_with_A += 1
        elif word[0] == "B":
            starts_with_B += 1
        elif word[-1] == "A":
            end_with_A += 1

    if starts_with_B_and_end_with_A == 0:
        print(contain_AB + min(starts_with_B, end_with_A))
        return
    if starts_with_B + end_with_A == 0:
        print(contain_AB + starts_with_B_and_end_with_A - 1)
        return
    print(contain_AB + starts_with_B_and_end_with_A +
          min(starts_with_B, end_with_A))


main()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    MAX_COST = 10**9
    num_steps,k = map(int,input().split())

    steps = list(map(int,input().split()))

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        for ki in range(1,min(k,si)+1):
            min_cost[si] = min(min_cost[si - ki] + abs(steps[si-ki] - steps[si]),min_cost[si])        

    print(min_cost[-1])
    
resolve()

Fixed submission:
def resolve():
    MAX_COST = 10**9
    num_steps,k = map(int,input().split())

    steps = list(map(int,input().split()))

    min_cost = [MAX_COST for i in range(num_steps)]
    min_cost[0] = 0
    min_cost[1] = abs(steps[1] - steps[0])
    
    for si in range(2,num_steps):
        for ki in range(1,min(k,si)+1):
            min_cost[si] = min(min_cost[si - ki] + abs(steps[si-ki] - steps[si]),min_cost[si])        

    print(min_cost[-1])
    
resolve()
Buggy python submission (verdict: Runtime Error):
a,b=[int(x) for x in input().split()]
    print("Even" if a %2 ==0 or b%2==0 else "Odd")

Fixed submission:
a,b=[int(x) for x in input().split()]
print("Even" if a %2 ==0 or b%2==0 else "Odd")
Buggy python submission (verdict: Runtime Error):
a,b= input().split()
target = int(a+b)
print("Yes" if math.pow(target,1/2).is_integer() else "No")

Fixed submission:
import math
a,b= input().split()
target = int(a+b)
print("Yes" if math.pow(target,1/2).is_integer() else "No")
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = map(int, input().split())
    targets = list(map(str, input().split()))
    targets_dict = {}

    for i in range(N):
        if targets[i] not in targets_dict:
            targets_dict[targets[i]] = 1
        else:
            targets_dict[targets[i]] += 1

    need_reduce = len(targets_dict) - K

    if need_reduce <= 0:
        print(0)
    else:
        ans = 0
        for _ in range(need_reduce):
            min_kv = min(targets_dict.items(), key=lambda x: x[1])
            ans += min_kv[1]
            del targets_dict[min_kv[0]]

        print(ans)
        
resolve()

Fixed submission:
def resolve():
    N, K = map(int, input().split())
    targets = list(map(str, input().split()))
    targets_dict = {}

    for i in range(N):
        if targets[i] not in targets_dict:
            targets_dict[targets[i]] = 1
        else:
            targets_dict[targets[i]] += 1

    need_reduce = len(targets_dict) - K

    if need_reduce <= 0:
        print(0)
    else:
        ans = 0
        targets_dict = sorted(targets_dict.items(), key=lambda x: x[1])
        for i in range(need_reduce):
            ans += targets_dict[i][1]
        print(ans)
       
resolve()
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
M = K + len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
mod = int(1e9) + 7 # <-- input modulo
maxf = 200000           # <-- input factional limitation

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
  
SS = 0
bas = 1
for i in range(M, len(S)-1, -1):
  SS += (bas * invf[i] * invf[M-i]) % mod
  bas *= 25
  bas %= mod
  SS %= mod
print(SS*fact[M]%mod)

Fixed submission:
K = int(input())
S = input()
M = K + len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
mod = int(1e9) + 7 # <-- input modulo
maxf = 2000010           # <-- input factional limitation

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
  
SS = 0
bas = 1
for i in range(M, len(S)-1, -1):
  SS += (bas * invf[i] * invf[M-i]) % mod
  bas *= 25
  bas %= mod
  SS %= mod
print(SS*fact[M]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
X = 1
if 0 in A:
  print(0)
else:
  flg = True
  for i in range(N):
    X *= A[i]
    if X > int(1e18):
      flg = False
  if flg:
    print(X)
  else:
    print(-1)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = 1
if 0 in A:
  print(0)
else:
  flg = True
  for i in range(N):
    X *= A[i]
    if X > int(1e18):
      flg = False
      break
  if flg:
    print(X)
  else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
AX = [A[i][0] for i in range(N)]
BX = [A[i][1] for i in range(N)]
AX.sort()
BX.sort()
if N % 2 == 1:
  L = AX[(N-1)//2]
  R = BX[(N-1)//2]
  print(R-L+1)
else:
  L = AX[N//2] + AX[N//2+1]
  R = BX[N//2] + BX[N//2+1]
  print(R-L+1)


Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
AX = [A[i][0] for i in range(N)]
BX = [A[i][1] for i in range(N)]
AX.sort()
BX.sort()
if N % 2 == 1:
  L = AX[(N-1)//2]
  R = BX[(N-1)//2]
  print(R-L+1)
else:
  L = AX[N//2-1] + AX[N//2]
  R = BX[N//2-1] + BX[N//2]
  print(R-L+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
  X = [[i, L[i]] for i in F]
  for j in F:
    L[j] *= 2
    L[j] %= mod
  for j in X:
    if A[i] + j[0] <= S:
      L[A[i]+j[0]] += j[1]
      L[A[i]+j[0]] %= mod
      F.add(A[i]+j[0])
print(L[S])

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
  X = [[i, L[i]] for i in F]
  for j in F:
    L[j] *= 2
    L[j] %= mod
  for j in X:
    if A[i] + j[0] <= S:
      L[A[i]+j[0]] += j[1]
      L[A[i]+j[0]] %= mod
      F.add(A[i]+j[0])
print(L[S])
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = {i: [] for i in range(N)}
A = list(map(int, input().split()))
for i in range(N):
  D[i].append(A[i]-1)
for i in range(N):
  print(len(D[i]))

Fixed submission:
N = int(input())
D = {i: [] for i in range(N)}
A = list(map(int, input().split()))
for i in range(N-1):
  D[A[i]-1].append(i)
for i in range(N):
  print(len(D[i]))
Buggy python submission (verdict: Runtime Error):
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[i][j]][k]
print(S)

Fixed submission:
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[j][k]-1][i]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
d = 2 ** (H - 1)
mcut = 1008
for i in range(d):
  L = [0 for _ in range(H)]
  for j in range(1, H):
    L[j] = L[j-1] + i % 2
    i //= 2
  C = [0 for _ in range(L[H-1]+1)]
  cutp, cutq = True, True
  cut = L[H-1]
  for m in range(W):
    for l in range(H):
      C[L[l]] += int(S[l][m])
    if cutq:
      cutq = False
      if max(C) > K:
        cutp = False
        break
    else:
      if max(C) > K:
        cut += 1
        C = [0 for _ in range(L[H-1]+1)]
        for l in range(H):
          C[L[l]] += int(S[l][m])
    if cutp == False:
      break
  if cutp:
    if cut < mcut:
      mcut = cut
print(mcut)

Fixed submission:
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
d = 2 ** (H - 1)
mcut = 1008
for i in range(d):
  L = [0 for _ in range(H)]
  for j in range(1, H):
    L[j] = L[j-1] + i % 2
    i //= 2
  C = [0 for _ in range(L[H-1]+1)]
  cutp, cutq = True, True
  cut = L[H-1]
  for m in range(W):
    for l in range(H):
      C[L[l]] += int(S[l][m])
    if cutq:
      cutq = False
      if max(C) > K:
        cutp = False
        break
    else:
      if max(C) > K:
        cut += 1
        C = [0 for _ in range(L[H-1]+1)]
        for l in range(H):
          C[L[l]] += int(S[l][m])
    if cutp == False:
      break
  if cutp:
    if cut < mcut:
      mcut = cut
print(mcut)
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
D = {0: [[-1, -1]], S: []}
for i in range(N):
    L = [[j, D[j]] for j in D]
    L.sort(reverse=True)
    for jn, j in enumerate(L):
        if j[0]+A[i] <= S:
            for kn, k in enumerate(j[1]):
                if j[0]+A[i] in D:
                    D[j[0]+A[i]].append([(j[0]>0)*k[0]+(j[0]==0)*i, i])
                else:
                    D[j[0]+A[i]] = [[(j[0]>0)*k[0]+(j[0]==0)*i, i]]
p = 0
for i in D[S]:
    p += (i[0] + 1) * (N - i[1]) % mod
    p %= mod
print(p)

Fixed submission:
N, S = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
L = [0 for _ in range(S+1)]
p = 0
F = {0}
for i in range(N):
    L[0] += 1
    X = [[j, L[j]] for j in F]
    for j in X:
        if j[0] + A[i] <= S:
            L[j[0]+A[i]] += j[1]
            L[j[0]+A[i]] %= mod
            F.add(j[0]+A[i])
    p += L[S]
    p %= mod

print(p)

Buggy python submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(map(int, input().split()))
D = {0: [[-1, -1]]}
for i in range(N):
    L = [[j, D[j]] for j in D]
    L.sort(reverse=True)
    for jn, j in enumerate(L):
        if j[0]+A[i] <= S:
            for kn, k in enumerate(j[1]):
                if j[0]+A[i] in D:
                    D[j[0]+A[i]].append([(j[0]>0)*k[0]+(j[0]==0)*i, i])
                else:
                    D[j[0]+A[i]] = [[(j[0]>0)*k[0]+(j[0]==0)*i, i]]
p = 0
for i in D[S]:
    p += (i[0] + 1) * (N - i[1])
print(p)

Fixed submission:
N, S = map(int, input().split())
mod = 998244353
A = list(map(int, input().split()))
L = [0 for _ in range(S+1)]
p = 0
F = {0}
for i in range(N):
    L[0] += 1
    X = [[j, L[j]] for j in F]
    for j in X:
        if j[0] + A[i] <= S:
            L[j[0]+A[i]] += j[1]
            L[j[0]+A[i]] %= mod
            F.add(j[0]+A[i])
    p += L[S]
    p %= mod

print(p)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

S = [input() for _ in range(H)]
p = [[0, 0, 0, 0]]
if S[0][0] == '#':
  p[3] = 1
for m in range(H+W-2):
  n = len(p)
  for i in range(n):
    x = p[i]
    if x[0] < H - 1:
      if x[3] == 1 and S[x[0]+1][x[1]] == '.':
        p.append([x[0]+1, x[1], x[2], 0])
      elif x[3] == 0 and S[x[0]+1][x[1]] == '#':
        p.append([x[0]+1, x[1], x[2]+1, 1])
      else:
        p.append([x[0]+1, x[1], x[2], x[3]])
    if x[1] < W - 1:
      if x[3] == 1 and S[x[0]][x[1]+1] == '.':
        p.append([x[0], x[1]+1, x[2], 0])
      elif x[3] == 0 and S[x[0]][x[1]+1] == '#':
        p.append([x[0], x[1]+1, x[2]+1, 1])
      else:
        p.append([x[0], x[1]+1, x[2], x[3]])
  p = p[n:]
print(min(p[i][2] for i in range(len(p))))

Fixed submission:
H, W = map(int, input().split())

S = [input() for _ in range(H)]
X = [[[int(1e9), 0] for i in range(W)] for j in range(H)]
p = [[0, 0]]
if S[0][0] == '#':
  X[0][0][0], X[0][0][1] = 1, 1
else:
  X[0][0][0], X[0][0][1] = 0, 0
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      X[i][j][1] = 1
for m in range(H+W-2):
  n = len(p)
  for i in range(n):
    x = p[i][:]
    if x[0] < H - 1:
      p.append([x[0]+1, x[1]])
    if x[0] == 0 and x[1] < W - 1:
      p.append([x[0], x[1]+1])
  p = p[n:]
  n = len(p)
  for i in range(n):
    x = p[i][:]
    if x[0] > 0 and x[1] > 0:
      X[x[0]][x[1]][0] = min(X[x[0]-1][x[1]][0] + (1-X[x[0]-1][x[1]][1])*X[x[0]][x[1]][1], X[x[0]][x[1]-1][0] + (1-X[x[0]][x[1]-1][1])*X[x[0]][x[1]][1])
    elif x[0] == 0 and x[1] > 0:
      X[x[0]][x[1]][0] = X[x[0]][x[1]-1][0] + (1-X[x[0]][x[1]-1][1])*X[x[0]][x[1]][1]
    elif x[0] > 0 and x[1] == 0:
      X[x[0]][x[1]][0] = X[x[0]-1][x[1]][0] + (1-X[x[0]-1][x[1]][1])*X[x[0]][x[1]][1]
print(X[H-1][W-1][0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()

S = [int(A[i])-1 for i in range(N)]

oddness = 0
for i in range(N):
  m, n = N-1, i
  if S[i] % 2 != 0:
    parity = 1
    while m != 0:
      if m % 2 == 0 and n % 2 == 1:
        parity = 0
        break
      m //= 2
      n //= 2
    oddness += parity
    oddness %= 2

if oddness == 1:
  print(1)
else:
  if 1 in S:
    print(0)
  else:
    S = [S[i]//2 for i in range(N)]
    oddness = 0
    for i in range(N):
      m, n = N-1, i
      if S[i] % 2 != 0:
        parity = 1
        while m != 0:
          if m % 2 == 0 and n % 2 == 1:
            parity = 0
            break
          m //= 2
          n //= 2
        oddness += parity
        oddness %= 2
    if oddness == 1:
      print(2)
    else:
      print(0)


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

S = [int(A[i])-1 for i in range(N)]
Lucas = [0 for i in range(N)]
D = {0: 1}
base, m = 1, N - 1
while m != 0:
  if m % 2 == 1:
    L = [i for i in D]
    for i in L:
      D[i+base] = 1
  m //= 2
  base *= 2
for i in D:
  Lucas[i] = 1
oddness = 0
for i in range(N):
  if S[i] % 2 != 0:
    oddness += Lucas[i]
    oddness %= 2

if oddness == 1:
  print(1)
else:
  if 1 in S:
    print(0)
  else:
    S = [S[i]//2 for i in range(N)]
    oddness = 0
    for i in range(N):
      if S[i] % 2 != 0:
        oddness += Lucas[i]
        oddness %= 2
    if oddness == 1:
      print(2)
    else:
      print(0)
Buggy python submission (verdict: Runtime Error):
S = int(input())
if S == "AAA" or S == "BBB":
  print("No")
else:
  print("Yes")

Fixed submission:
S = input()
if S == "AAA" or S == "BBB":
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
sign = 1
for i in range(Q):
  T = list(map(str, input().split()))
  if T[0] == "1":
    sign *= -1
  else:
    F = int(T[1]) * 2 - 3
    if sign * F == 1:
      S = S[:] + T[2]
    else:
      S = T[2] + S[:]
if sign == 1:
  print(S)
else:
  N = len(S)
  for i in range(N):
    print(S[N-i-1], end = '')
  print()

Fixed submission:
S = input()
N = len(S)
Q = int(input())
sign = 1
L = ["" for i in range(N + 2 * Q)]
for i in range(N):
  L[i+Q] = S[i]
x, y = Q - 1, N + Q
for i in range(Q):
  T = list(map(str, input().split()))
  if T[0] == "1":
    sign *= -1
  else:
    F = int(T[1]) * 2 - 3
    if sign * F == 1:
      L[y] = T[2]
      y += 1
    else:
      L[x] = T[2]
      x -= 1
newS = ""
for i in range(N+2*Q):
  newS = newS[:] + L[i]
if sign == 1:
  print(newS)
else:
  M = len(newS)
  for i in range(M):
    print(newS[M-i-1], end = '')
  print()
Buggy python submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [[0 for i in range(3)] for j in range(3)]
for i in range(N):
  a = int(input())
  for m in range(3):
    for n in range(3):
      if a == A[m][n]:
        B[m][n] = 1
p = 'No'
for i in range(3):
  cnt1 = 0
  cnt2 = 0
  for j in range(3):
    if B[i][j] == 1:
      cnt1 += 1
    if B[j][i] == 1:
      cnt2 += 1
  if cnt1 == 3 or cnt2 == 3:
    p = 'Yes'
    break
cnt3, cnt4 = 0, 0
for i in range(3):
  if B[i][i] == 1:
    cnt3 += 1
  if B[i][3-i] == 1:
    cnt4 += 1
if cnt3 == 3 or cnt4 == 3:
  p = 'Yes'
print(p)

Fixed submission:
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [[0 for i in range(3)] for j in range(3)]
for i in range(N):
  a = int(input())
  for m in range(3):
    for n in range(3):
      if a == A[m][n]:
        B[m][n] = 1
p = 'No'
for i in range(3):
  cnt1 = 0
  cnt2 = 0
  for j in range(3):
    if B[i][j] == 1:
      cnt1 += 1
    if B[j][i] == 1:
      cnt2 += 1
  if cnt1 == 3 or cnt2 == 3:
    p = 'Yes'
    break
cnt3, cnt4 = 0, 0
for i in range(3):
  if B[i][i] == 1:
    cnt3 += 1
  if B[i][2-i] == 1:
    cnt4 += 1
if cnt3 == 3 or cnt4 == 3:
  p = 'Yes'
print(p)
Buggy python submission (verdict: Runtime Error):
N = input()
K = int(input())
def Anger(n, k):
  d = int(n[0])
  if k == 1:
    S = d + 9 * (len(n) - 1)
    return S
  else:
    S = (d - 1) * (9 ** (k-1))
    for j in range(k-1):
      S *= len(n) - j - 1
      S //= j + 1
    T = 9 ** k
    for j in range(k):
      T *= len(n) - j - 1
      T //= j + 1
    return S + T + Anger(n[1:], k - 1)
    
print(Anger(N, K))

Fixed submission:
N = input()
K = int(input())
def Anger(n, k):
  d = int(n[0])
  if len(n) < k:
    return 0
  else:
    if k == 1:
      if d == 0 and len(n) != 1:
        return Anger(n[1:], k)
      elif d == 0 and len(n) == 1:
        return 0
      else:
        if len(n) != 1:
          S = d + 9 * (len(n) - 1)
          return S
        else:
          return d
    else:
      if d == 0:
        return Anger(n[1:], k)
      else:
        S = (d - 1) * (9 ** (k-1))
        for j in range(k-1):
          S *= len(n) - j - 1
          S //= j + 1
        T = 9 ** k
        for j in range(k):
          T *= len(n) - j - 1
          T //= j + 1
        return S + T + Anger(n[1:], k - 1)
    
print(Anger(N, K))
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
limit = H + max(A[i][0] for i in range(N))
dp = [int(1e18) for _ in range(limit+1)]
dp[0] = 0
for i in range(1, limit+1):
  for j in range(N):
    if A[j][0] > i:
      dp[i] = min(dp[i], A[j][1])
    else:
      dp[i] = min(dp[i], dp[i-A[j][0]]+A[j][1])
M = min(dp[i] for i in range(H, limit+1))
print(dp[H])

Fixed submission:
H, N = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
limit = H + max(A[i][0] for i in range(N))
dp = [int(1e18) for _ in range(limit+1)]
dp[0] = 0
for i in range(1, limit+1):
  for j in range(N):
    if A[j][0] > i:
      dp[i] = min(dp[i], A[j][1])
    else:
      dp[i] = min(dp[i], dp[i-A[j][0]]+A[j][1])
M = min(dp[i] for i in range(H, limit+1))
print(dp[H])