Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
pat = [0]*(N+1)
for i in range(N+1):
  if i == 0:
    pat[i] = 1
  else:
    before1 = pat[i-1] if i-1 not in a else 0
    before2 = pat[i-2] if i-2 not in a else 0
    pat[i] = before1 + before2
print(pat[-1]%1000000007)

Fixed submission:
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
pat = [0]*(N+1)
for i in range(N+1):
  if i == 0:
    pat[i] = 1
  else:
    element = a[0] if len(a) != 0 else -1
    pat[i] = pat[i-1] + pat[i-2] if i != element  else 0
    if i == element:
      a.pop(0)
print(pat[-1]%1000000007)
Buggy python submission (verdict: Runtime Error):
S = input()

f = int(S[0]+S[1])
s = int(S[2]+S[3])

if f >= 1 and f <= 12 and s >= 1 and s <= 12:
  print('AMBIGUOUS')
elif f >= 1 and f <=12 and (s >= 13 or s == 0):
  print('MMYY')
elif (f >= 13 or f == 0 and s >= 1 and s <= 12:
  print('YYMM')
else:
  print('NA')
  

Fixed submission:
S = input()

f = int(S[0]+S[1])
s = int(S[2]+S[3])

if f >= 1 and f <= 12 and s >= 1 and s <= 12:
  print('AMBIGUOUS')
elif f >= 1 and f <=12 and (s >= 13 or s == 0):
  print('MMYY')
elif (f >= 13 or f == 0) and s >= 1 and s <= 12:
  print('YYMM')
else:
  print('NA')

Buggy python submission (verdict: Runtime Error):
S = input()

f = int(S[0]+S[1])
s = int(S[2]+S[3])

if f >= 1 and f <= 12 and s >= 1 and s <= 12:
  print('AMBIGUOUS')
elif f >= 1 and f <=12 and s => 13:
  print('MMYY')
elif f => 13 and s >= 1 and s <= 12:
  print('YYMM')
else:
  print('NA')

Fixed submission:
S = input()

f = int(S[0]+S[1])
s = int(S[2]+S[3])

if f >= 1 and f <= 12 and s >= 1 and s <= 12:
  print('AMBIGUOUS')
elif f >= 1 and f <=12 and (s >= 13 or s == 0):
  print('MMYY')
elif (f >= 13 or f == 0) and s >= 1 and s <= 12:
  print('YYMM')
else:
  print('NA')
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

inter_A = (A//10)*10 + 10
inter_B = (B//10)*10 + 10
inter_C = (C//10)*10 + 10
inter_D = (D//10)*10 + 10
inter_E = (E//10)*10 + 10

first_A = A + inter_B + inter_C + inter_D + inter_E
first_B = inter_A + B + inter_C + inter_D + inter_E
first_C = inter_A + inter_B + C + inter_D + inter_E
first_D = inter_A + inter_B + inter_C + D + inter_E
first_E = inter_A + inter_B + inter_C + inter_D + E
print(min[first_A, first_B, first_C, first_D, first_E])

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
inter_A = (A//10)*10 if A%10 == 0 else (A//10)*10 + 10
inter_B = (B//10)*10 if B%10 == 0 else (B//10)*10 + 10
inter_C = (C//10)*10 if C%10 == 0 else (C//10)*10 + 10
inter_D = (D//10)*10 if D%10 == 0 else (D//10)*10 + 10
inter_E = (E//10)*10 if E%10 == 0 else (E//10)*10 + 10
 
first_A = A + inter_B + inter_C + inter_D + inter_E
first_B = inter_A + B + inter_C + inter_D + inter_E
first_C = inter_A + inter_B + C + inter_D + inter_E
first_D = inter_A + inter_B + inter_C + D + inter_E
first_E = inter_A + inter_B + inter_C + inter_D + E
print(min([first_A, first_B, first_C, first_D, first_E]))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

for i, q in enumerate(question):
  ans = 0
  for j in range(len(index)):
    if index[j] >= q[0]-1 and index[j]+1 <= q[1]-1:
      ans +=1
  print(ans)
    



Fixed submission:
import bisect

N, Q = map(int, input().split())
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

# i番目の文字以降に存在するACという部分文字列の数
sum_index = [0]*N
sum_ac = 0
for i in range(N-1):
  if S[N-(i+2)]+S[N-(i+1)] == "AC":
    sum_ac += 1
  sum_index[N-(i+2)] = sum_ac

for i, q in enumerate(question):
  ans = sum_index[q[0]-1] - sum_index[q[1]-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

for i, q in enumerate(question):
  ans = 0
  for j in range(len(index)):
    if index[j] >= q[0]-1 and index[j]+1 <= q[1]-1:
      ans +=1
  print(ans)

Fixed submission:
import bisect

N, Q = map(int, input().split())
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

# i番目の文字以降に存在するACという部分文字列の数
sum_index = [0]*N
sum_ac = 0
for i in range(N-1):
  if S[N-(i+2)]+S[N-(i+1)] == "AC":
    sum_ac += 1
  sum_index[N-(i+2)] = sum_ac

for i, q in enumerate(question):
  ans = sum_index[q[0]-1] - sum_index[q[1]-1]
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())
INF = 10** 9
# dp[i][j]: i+1番目までの商品で、j+1本の栄養ドリンクを買い集めるための最小コスト
dp = [[INF for i in range(M)] for j in range(N)]

for i in range(N):
  for j in range(M):
    array = []
    for k in range(min([j+1, B[i]])+1):
      array.append(dp[i-1][j-k] + A[i]*k if j>=k else A[i]*k)
    #dp[i][j] = min([dp[i-1][j], dp[i-1][j-1]+A[i], ... dp[i-1][j-B[i]] + A[i]*B[i]])
    dp[i][j] = min(array) if i > 0 else A[i]*(j+1)

print(dp[N-1][M-1])

Fixed submission:
N, M = map(int, input().split())
array = []
for i in range(N):
  elm = list(map(int, input().split()))
  array.append(elm)

array.sort(key=lambda x: x[0])
ans = 0
cnt = 0
for i in range(N):
  #何本買うか
  buy = min([array[i][1], M-cnt])
  cnt += buy
  ans += array[i][0]*buy

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
X = list(map(int, input().split()))
X.sort()
diff = []
if M != 1:
  for i in range(M-1):
    diff.append(X[i+1]-X[i])
else:
  diff = [0]

sorted_diff = sorted(diff)
sorted_diff.reverse()

ans = sum(sorted_diff)
for i in range(min([N-1,M])):
  ans -= sorted_diff[i]
print(ans)

Fixed submission:
N, M = map(int,input().split())
X = list(map(int, input().split()))
X.sort()
diff = []
if M != 1:
  for i in range(M-1):
    diff.append(X[i+1]-X[i])
else:
  diff = [0]

sorted_diff = sorted(diff)
sorted_diff.reverse()

ans = sum(sorted_diff)
for i in range(min([N,M])-1):
  ans -= sorted_diff[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
return (A*B)//2

Fixed submission:
A, B, C = map(int, input().split())
print((A*B)//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int,input().split()))
dp = [-1]*N

for i in range(N):
    dp[i] = rec_dp(i,dp)

def rec_dp(i,dp):
    if i==0:
        return 0
    elif i==1:
        return abs(h[1]-h[0])
    else:
        onestepmin = dp[i-1] + abs(h[i-1] - h[i])
        twostepmin = dp[i-2] + abs(h[i-2] - h[i])
        return min(onestepmin,twostepmin)


print(dp[N-1])

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [-1]*N

def rec_dp(i,dp):
    if i==0:
        return 0
    elif i==1:
        return abs(h[1]-h[0])
    else:
        onestepmin = dp[i-1] + abs(h[i-1] - h[i])
        twostepmin = dp[i-2] + abs(h[i-2] - h[i])
        return min([onestepmin,twostepmin])

for i in range(N):
    dp[i] = rec_dp(i,dp)

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0]*(N+1) # 足場iにたどり着くまでの最小コスト
for i in range(2,N+1):
  dp[i] = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(1,K+1):
    if i-j > 0:
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])

Fixed submission:
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1]*N
 
def rec_dp(i,K,dp):
    minArray = []
    if i == 0:
        minArray = [0]
    for j in range(K):
        if i - (j+1) >= 0:
            stepMin = dp[i-(j+1)] + abs(h[i] - h[i-(j+1)])
            minArray.append(stepMin)
    return min(minArray)
 
for i in range(N):
    dp[i] = rec_dp(i,K,dp)
 
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1]*N

def rec_dp(i,K,dp):
    minArray = []
    if i == 0:
        minArray = [0]
    for j in range(K):
        if i - (j+1) >= 0:
            stepMin = dp[i-(j+1)] + abs(h[i] - h[i-(j+1)])
            minArray.append(stepMin)
    return min(minArray)

for i in range(N):
    dp[i] = rec_dp(i,K,dp)

print(dp[N-1])

Fixed submission:
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1]*N
 
def rec_dp(i,K,dp):
    minArray = []
    if i == 0:
        minArray = [0]
    for j in range(K):
        if i - (j+1) >= 0:
            stepMin = dp[i-(j+1)] + abs(h[i] - h[i-(j+1)])
            minArray.append(stepMin)
    return min(minArray)
 
for i in range(N):
    dp[i] = rec_dp(i,K,dp)
 
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [0]*N
for i in range(N):
    p[i] = int(inout())

ans = sum(p)-0.5*max(p)
print(ans)

Fixed submission:
N = int(input())
p = [0]*N
for i in range(N):
    p[i] = int(input())

ans = sum(p)-0.5*max(p)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
X, Y = int(input().split())
print(X+Y//2)

Fixed submission:
X, Y = map(int,input().split())
print(X+Y//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N == 1:
    print('Hello World')
elif N == 2:
    print(A+B)

Fixed submission:
N = int(input())


if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input())
    B = int(input())
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N == 1:
    print('Hello World')
if N == 2:
    print(A+B)

Fixed submission:
N = int(input())


if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input())
    B = int(input())
    print(A+B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N == 1:
    print('Hello World')
if N == 2:
    print(A+B)

Fixed submission:
N = int(input())


if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
n = input()
ans = ''
for i in n:
    if n[i] == '1':
        ans += '9'
    elif n[i] == '9':
        n[i] += '1'
    else:
        ans += n[i]
print(ans)

Fixed submission:
n = input()
ans = []
for i in range(len(n)):
    if n[i] == '1':
        ans.append('9')
    elif n[i] == '9':
        ans.append('1')
    else:
        ans.append(n[i])
print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if (abs(b-a) <= d and abs(c-b) <= d) 
	print('Yes')
else if (abs(c-a)<= d)
	print('Yes')
else
	print('No')

Fixed submission:
a,b,c,d = map(int,input().split())
if abs(b-a) <= d and abs(c-b) <= d:
	print('Yes')
elif abs(c-a)<= d:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
a = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == ".":
      a[i][j] = 1
    dh = [-1,0,1,0]
    dw = [0,-1,0,1]
    for k in range(4):
      ii = i + dh[k]
      jj = j + dw[k]
      if 0 <= ii < W and 0 <= jj < H:
        if s[i][j] == "#" and s[ii][jj] == "#":
          a[i][j] = 1
          a[ii][jj] = 1
flag = True
for i in range(H):
  for j in range(W):
    if a[i][j] != 1:
      flag = False
      break
if flag:
  print("Yes")
else:
  print("No")

Fixed submission:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
a = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == ".":
      a[i][j] = 1
    dh = [-1,0,1,0]
    dw = [0,-1,0,1]
    for k in range(4):
      ii = i + dh[k]
      jj = j + dw[k]
      if 0 <= ii < H and 0 <= jj < W:
        if s[i][j] == "#" and s[ii][jj] == "#":
          a[i][j] = 1
          a[ii][jj] = 1
flag = True
for i in range(H):
  for j in range(W):
    if a[i][j] != 1:
      flag = False
      break
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c,x,y = map(int,input().split())
if (a+b <= 2*c) :
  print(a*x+b*y)
if (a+b > 2*c) :
  if (x == y) :
    print(2*c*(x+y))
  if (x > y) :
    print(min(2*c*y + a*(x-y),2*c*(x+y))
  if (x < y) :
    print(min(2*c*x + b*(y-x),2*c*(x+y))


Fixed submission:
a,b,c,x,y = map(int,input().split())
if (a+b <= 2*c) :
  print(a*x+b*y)
if (a+b > 2*c) :
  if (x == y) :
    print(2*c*x)
  if (x > y) :
    print(min([2*c*y + a*(x-y),2*c*x]))
  if (x < y) :
    print(min([2*c*x + b*(y-x),2*c*y]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
X = list(map(int,input().split()))
medIndex=int((n-1)/2)
for i in range(n) :
  Y = X[:]
  Y.pop(i)
  Y.sort()
  print(Y[medIndex])

Fixed submission:
n = int(input())
X = list(map(int,input().split()))
medIndex = int((n-1)/2)
Z = sorted(X[:])
c1 = Z[int(n/2-1)]
c2 = Z[int(n/2)]
for i in range(n) :
  if (X[i] <= c1) :
    print(c2)
  else :
    print(c1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
X = list(map(int,input().split()))
for i in range(n) :
  Y = X[:]
  Y.pop(i)
  Y.sort()
  medIndex = int((n-1)/2)
  print(Y[medIndex])

Fixed submission:
n = int(input())
X = list(map(int,input().split()))
medIndex = int((n-1)/2)
Z = sorted(X[:])
c1 = Z[int(n/2-1)]
c2 = Z[int(n/2)]
for i in range(n) :
  if (X[i] <= c1) :
    print(c2)
  else :
    print(c1)
Buggy python submission (verdict: Runtime Error):
S = list(input())
ic = ""
for i in range(97, 123):
  if (chr(i) not in S):
    ic = chr(i)
    break
if ic != "":
  print("".join(S) + ic)
else:
  h = S[0]
  for i in range(1,len(S)):
    if h < S[i]:
      h = S[i]
    else:
      ii = i
      break
  print(ii)

Fixed submission:
# 写経#2284578
S = input()
alp = "abcdefghijklmnopqrstuvwxyz"
def h(string, least = 'Z'):
  for c in alp:
    if c not in string:
      if c <= least:
        continue
      return string + c
  if string == "":
    return "-1"
  return h(string[:-1], string[-1])
print(h(S))
Buggy python submission (verdict: Runtime Error):
S = list(input())
for i in range(len(S)):
  if S[0] == "K":
    S.insert(0,"A")
for i in range(len(S)):
  if S[i] == "H" and S[i+1] != "A":
    S.insert(i+1,"A")
for i in range(len(S)):
  if S[i] == "B" and S[i+1] != "A":
    S.insert(i+1,"A")
for i in range(len(S)):
  if S[-1] == "R":
if "".join(S) == "AKIHABARA":
  print("YES")
else:
  print("NO")


Fixed submission:
S = list(input())
for i in range(len(S)):
  if S[0] == "K":
    S.insert(0,"A")
for i in range(len(S)):
  if S[i] == "H" and S[i+1] != "A":
    S.insert(i+1,"A")
for i in range(len(S)):
  if S[i] == "B" and S[i+1] != "A":
    S.insert(i+1,"A")
for i in range(len(S)):
  if S[-1] == "R":
    S.append("A")

if "".join(S) == "AKIHABARA":
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
for i in range(1,3501):
  for j in range(max(i-1,1),3501):
    if (4*i*j - N*i -N*j) != 0:
      w = (N*i*j)/(4*i*j - N*i -N*j)
      if w > 0 and w.is_integer():
        print(i,j,int(w))
        sys.exit()

Fixed submission:
import sys
N = int(input())
for i in range(1,3501):
  for j in range(max(i-1,1),3501):
    if (4*i*j - N*i -N*j) != 0:
      w = (N*i*j)/(4*i*j - N*i -N*j)
      if w > 0 and w.is_integer():
        print(i,j,int(w))
        sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys

S = sys.stdin.readline().rstrip()

WS = ["Sunny", "Cloudy", "Rainy"]

i = WS.index(S)
i += 1
if i == 2:
    i = 0

print(WS[i])


Fixed submission:
import sys

S = sys.stdin.readline().rstrip()

WS = ["Sunny", "Cloudy", "Rainy"]

i = WS.index(S)
i += 1
if i == 3:
    i = 0

print(WS[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
C = list(input().strip())
count = 0
j = N - 1
for i in range(N):
  if C[i] == "W":
    if i < j:
      while True:
        if C[j] == "R":
          C[i], C[j] = C[j], C[i]
          count += 1
          break
        else:
          j -= 1
    else:
      break

print(count)

Fixed submission:
N = int(input())
C = list(input().strip())
count = 0
j = N - 1
for i in range(N):
  if C[i] == "W":
    while i < j:
      if C[j] == "R":
        C[i], C[j] = C[j], C[i]
        count += 1
        break
      else:
        j -= 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

hyoten_i = 1
for i, a in enumerate(A):
  hyoten_prev = hyoten_i
  hyoten_i *= a
  if i + 1 > K:
    hyoten_i = hyoten_i / A[i - K]
    print("Yes" if hyoten_i > hyoten_prev else "No")

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

for i, a in enumerate(A):
  if i + 1 > K:
    if a > A[i - K]:
      print("Yes")
    else:
      print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

result = 1
for a in A:
  result *= a
  
if result > 1e18:
  print(-1)
else:
  print(result)

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

if A[0] == 0:
  print(0)
  quit()

result = 1

for a in A:
  result *= a
  if result > 1e18:
    print(-1)
    quit()

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

result = 1
for a in A:
  result *= a
  
if result > 1e18:
  print(-1)
else:
  print(result)

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

if A[0] == 0:
  print(0)
  quit()

result = 1

for a in A:
  result *= a
  if result > 1e18:
    print(-1)
    quit()

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,K = map(int, input().split())

total = 0
count = 0
for a in range(A):
  total += 1
  count += 1
  if count == K:
    print(total)
    quit()
    
for b in range(B):
  count += 1
  if count == K:
    print(total)
    quit()
    
for c in range(C):
  total -= 1
  count += 1
  if count == K:
    print(total)
    quit()

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

if A >= K:
  print(K)
elif A + B >= K > A:
  print(A)
else:
  print(A - (K - A - B))
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B, N = map(int, input().split())

def f(A, B, x):
  return math.floor((A * x) / B) - A * math.floor(x / B)

print(max([f(A, B, x) for x in range(1,min(N + 1, B + 1))]))

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

def f(A, B, x):
  return math.floor((A * x) / B) - A * math.floor(x / B)

x = N if N < B else B - 1
print(f(A, B, x))
Buggy python submission (verdict: Runtime Error):
import math

A = [int(a) for _ in range(3) for a in input().split()]
punched = [False] * 9
num_to_i = {a:i for i, a in enumerate(A)}
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
  if b in num_to_i:
    punched[num_to_i[b]] = True

# 縦
for i in range(3):
  if punched[i] and punched[i+3] and punched[i+6]:
    print("Yes")
    quit()

# 横
for i in range(3):
  if punched[i*3] and punched[i*3+1] and punched[i*3+3]:
    print("Yes")
    quit()

# 斜め
if (punched[0] and punched[4] and punched[8]) or (punched[2] and punched[4] and punched[6]):
  print("Yes")
  quit()
  
print("No")

Fixed submission:
import math
A = list(map(int,"\n".join([input() for i in range(3)]).strip().split()))
N = int(input())
B = [int(input()) for i in range(N)]
size = 3
punched = set()

corrects = []
# 縦の揃い方
corrects += [{i + size*j for i in range(size)} for j in range(size)]
# 横の揃い方
corrects += [{j + size*i for i in range(size)} for j in range(size)]
# 斜めの揃い方
corrects += [{i + size*i for i in range(size)}]
corrects += [{(size - 1 - i) + size*i for i in range(size)}]

def punch(b, A, punched):
    for i in range(len(A)):
        if b == A[i]: punched.add(i)
          
for b in B:
    punch(b, A, punched)
    
for correct in corrects:
    if correct.issubset(punched):
        print("Yes")
        break
else:
  	print("No")
Buggy python submission (verdict: Runtime Error):
from math import factorial

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

def comb(n,r):
  return factorial(n) / factorial(r) / factorial(n - r)

def func(a_p,a_c):
  if a_p == a_c: return 1
  num_steps = a_c - a_p
  r = 0
  result = 0
  for n in range(num_steps,0,-1):
    result += int(comb(n,r))
    r += 1
    if n <= r: break
  return result

a_p = 0
result = 1
for i in range(M):
  a_c = int(input()) - 1
  
  if a_c + 1 == a_p: 
    result *= 0
  result = ((func(a_p,a_c)%1000000007) * (result%1000000007))%1000000007
  a_p = a_c + 2
  
result = ((func(a_p,N)%1000000007) * (result%1000000007))%1000000007
print(result)

Fixed submission:
import sys
sys.setrecursionlimit(int(1e6))
N, M = map(int,input().split())


def func(n):
    """メモ化フィボナッチ"""
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = _fib(n-1)%1000000007 + _fib(n-2)%1000000007
        return memo[n]

    return _fib(n)

a_p = 0
result = 1
for i in range(M):
  a_c = int(input()) - 1
  
  if a_c + 1 == a_p: 
    print(0)
    quit()
  result = ((func(a_c - a_p + 1)%1000000007) * (result%1000000007))%1000000007
  a_p = a_c + 2
  
result = ((func(N - a_p + 1)%1000000007) * (result%1000000007))%1000000007
print(result)

Buggy python submission (verdict: Runtime Error):
from math import factorial

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

def comb(n,r):
  return factorial(n) / factorial(r) / factorial(n - r)

def func(a_p,a_c):
  if a_p == a_c: return 1
  num_steps = a_c - a_p
  r = 0
  result = 0
  for n in range(num_steps,0,-1):
    result += int(comb(n,r))
    r += 1
    if n <= r: break
  return result

a_p = 0
result = 1
for i in range(M):
  a_c = int(input()) - 1
  
  if a_c + 1 == a_p: 
    result *= 0
  result *= func(a_p,a_c)
  a_p = a_c + 2
  
result *= func(a_p,N)
print(result%1000000007)

Fixed submission:
import sys
sys.setrecursionlimit(int(1e6))
N, M = map(int,input().split())


def func(n):
    """メモ化フィボナッチ"""
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = _fib(n-1)%1000000007 + _fib(n-2)%1000000007
        return memo[n]

    return _fib(n)

a_p = 0
result = 1
for i in range(M):
  a_c = int(input()) - 1
  
  if a_c + 1 == a_p: 
    print(0)
    quit()
  result = ((func(a_c - a_p + 1)%1000000007) * (result%1000000007))%1000000007
  a_p = a_c + 2
  
result = ((func(N - a_p + 1)%1000000007) * (result%1000000007))%1000000007
print(result)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
As = sorted(list(map(int,input().split())))
BCs = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

j = 0
for i in range(N):
  if As[i] > BCs[j][1]:
    break
  else:
    As[i] = BCs[j][1]
    BCs[j][0] -= 1
    if BCs[j][0] == 0:
      j += 1

print(sum(As))
    

Fixed submission:
N, M = map(int,input().split())
As = sorted(list(map(int,input().split())))
BCs = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

j = 0
for i in range(N):
  if BCs[j][0] <= 0:
    j += 1
  if j == M or As[i] > BCs[j][1]:
    break
  else:
    As[i] = BCs[j][1]
    BCs[j][0] -= 1


print(sum(As))