Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
pf[len(l)-1] = 3
mod = 1000000007
for i in range(len(l)-2, -1, -1):
    dpf[i] = (3 * dpf[i+1]) % mod
#print(dpf)
def dfs(i):
    if i == len(l):
        return 1
    if l[i] == '0':
        return dfs(i+1)
    return (dpf[i+1] + (dfs(i+1) * 2) % mod) % mod
 
print(dfs(0))

Fixed submission:
l = input()
dpf = [0] * (len(l) + 2)
dpf[len(l)-1] = 3
mod = 1000000007
for i in range(len(l)-2, -1, -1):
    dpf[i] = (3 * dpf[i+1]) % mod
#print(dpf)
# def dfs(i):
#     if i == len(l)-1:
#         if l[i] == '1':
#             return 3
#         else:
#             return 1
#     if l[i] == '0':
#         return dfs(i+1)
#     return (dpf[i+1] + (dfs(i+1) * 2) % mod) % mod
#
# print(dfs(0))

dp = [0] * (len(l))
dp[-1] = 1
if l[-1] == '1':
    dp[-1] = 3
for i in range(len(l)-2, -1, -1):
    if l[i] == '0':
        dp[i] = dp[i+1]
    else:
        dp[i] = (dpf[i+1] + (dp[i+1]*2)%mod)%mod
print(dp[0])

Buggy python submission (verdict: Runtime Error):
l = input()
dpf = [0] * (len(l) + 2)
dpf[len(l)-1] = 3
mod = 1000000007
for i in range(len(l)-2, -1, -1):
    dpf[i] = (3 * dpf[i+1]) % mod
#print(dpf)
def dfs(i):
    if i == len(l)-1:
        if l[i] == '1':
            return 3
        else:
            return 1
    if l[i] == '0':
        return dfs(i+1)
    return (dpf[i+1] + (dfs(i+1) * 2) % mod) % mod

print(dfs(0))

Fixed submission:
l = input()
dpf = [0] * (len(l) + 2)
dpf[len(l)-1] = 3
mod = 1000000007
for i in range(len(l)-2, -1, -1):
    dpf[i] = (3 * dpf[i+1]) % mod
#print(dpf)
# def dfs(i):
#     if i == len(l)-1:
#         if l[i] == '1':
#             return 3
#         else:
#             return 1
#     if l[i] == '0':
#         return dfs(i+1)
#     return (dpf[i+1] + (dfs(i+1) * 2) % mod) % mod
#
# print(dfs(0))

dp = [0] * (len(l))
dp[-1] = 1
if l[-1] == '1':
    dp[-1] = 3
for i in range(len(l)-2, -1, -1):
    if l[i] == '0':
        dp[i] = dp[i+1]
    else:
        dp[i] = (dpf[i+1] + (dp[i+1]*2)%mod)%mod
print(dp[0])
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A >= 13:
  print(B)
else A >= 6:
  print(B//2)
else:
  print(0)

Fixed submission:
A, B = map(int, input().split())
if A >= 13:
  print(B)
elif A >= 6:
  print(B//2)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(M)]
bc.sort(key=lambda x: x[1], reverse=True)
rest = N
for b, c in bc:
  a += [c] * min(rest, b)
  rest -= min(rest, b)
a.sort(reversed=True)
print(sum(a[:N]))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(M)]
bc.sort(key=lambda x: x[1], reverse=True)
rest = N
for b, c in bc:
  a += [c] * min(rest, b)
  rest -= min(rest, b)
a.sort(reverse=True)
print(sum(a[:N]))
Buggy python submission (verdict: Runtime Error):
from math import gcd
N = int(input())
aa = list(map(int, input().split()))
front = [0]*N
back = [0]*N
front[0] = aa[0]
back[-1] = aa[-1]
for i in range(1, N):
    front[i] = gcd(front[i-1], aa[i])
    back[-1-i] = gcd(back[-i], aa[-1-i])
ans = back[1]
for i in range(2, N):
    ans = max(gcd(front[i-2], back[i]), ans)
ans = max(front[-2], ans,)
print(ans)

Fixed submission:
from fractions import gcd
N = int(input())
aa = list(map(int, input().split()))
front = [0]*N
back = [0]*N
front[0] = aa[0]
back[-1] = aa[-1]
for i in range(1, N):
    front[i] = gcd(front[i-1], aa[i])
    back[-1-i] = gcd(back[-i], aa[-1-i])
ans = back[1]
for i in range(2, N):
    ans = max(gcd(front[i-2], back[i]), ans)
ans = max(front[-2], ans,)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
if L[:-1] > L[-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
if sum(L[:-1]) > L[-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
     N= int(input())
    L = list(map(int, input().split()))
    L.sort()
    if sum(L[:-1]) > L[-1]:
      print("Yes")
    else:
      print("No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
if sum(L[:-1]) > L[-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
 = int(input())
L = list(map(int, input().split()))
L.sort()
if sum(L[:-1]) > L[-1]:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
if sum(L[:-1]) > L[-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a, b, c = sort(map(int, input().split()))
print(a*b//2)


Fixed submission:
a, b, c = sorted(map(int, input().split()))
print(a*b//2)
Buggy python submission (verdict: Runtime Error):
def func(a):
    if a % 2 == 0:
        return a//2
    else:
        return 3*a + 1

tab = [False]*1000_001
now = int(input())
ind = 1
while not tab[now]:
    tab[now] = True
    now = func(now)
    ind += 1

print(ind)


Fixed submission:
def func(a):
    if a % 2 == 0:
        return a//2
    else:
        return 3*a + 1

tab = [False]*1000001
now = int(input())
ind = 1
while not tab[now]:
    tab[now] = True
    now = func(now)
    ind += 1

print(ind)
Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())
if N == 1:
  print(P)
  exit()
if N > 40:
  print(1)
  exit()
res = []
for i in range(1,P):
  x = i**N
  if i**N > P:
    break
  if P%x == 0:
    res.append(i)
print(max(res))

Fixed submission:
N, P = map(int, input().split())
if N == 1:
  print(P)
  exit()
if N > 40:
  print(1)
  exit()
res = []
for i in range(1,P+1):
  x = i**N
  if i**N > P:
    break
  if P%x == 0:
    res.append(i)
print(max(res))

Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())
if N == 1:
  print(P)
  exit()
if N > 40:
  print(1)
  exit()
res = []
for i in range(P):
  x = i**N
  if i**N > P:
    break
  if P%x == 0:
    res.append(i)
print(max(res))
  

Fixed submission:
N, P = map(int, input().split())
if N == 1:
  print(P)
  exit()
if N > 40:
  print(1)
  exit()
res = []
for i in range(1,P+1):
  x = i**N
  if i**N > P:
    break
  if P%x == 0:
    res.append(i)
print(max(res))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for _ in range(N)]
if all(list(map(x%2==0, a))):
  print("second")
else:
  print("first")

Fixed submission:
N = int(input())
a = [int(input()) for _ in range(N)]
if all(list(map(lambda x: x%2==0, a))):
  print("second")
else:
  print("first")
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [int(input()) for _ in range(N)]
p.sort()
p[-1] //= 2
print(p.sum())

Fixed submission:
N = int(input())
p = [int(input()) for _ in range(N)]
p.sort()
p[-1] //= 2
print(sum(p))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = 1<<31
for i in range(N-K)+1:
  ans = min(ans, h[i+K-1]-h[i]
print(ans)

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = 1<<31
for i in range(N-K+1):
  ans = min(ans, h[i+K-1]-h[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
pat = [1 for _ in range(N+1)]
mai = [1 for _ in range(N+1)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == n:
    return pat[n]
  
print(cnt_pat(X, N))

Fixed submission:
N, X = map(int, input().split())
pat = [1 for _ in range(N+1)]
mai = [1 for _ in range(N+1)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == mai[n]:
    return pat[n]
  
print(cnt_pat(X, N))

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
pat = [1 for _ in range(N)]
mai = [1 for _ in range(N)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == n:
    return pat[n]
  
print(cnt_pat(X, N))

Fixed submission:
N, X = map(int, input().split())
pat = [1 for _ in range(N+1)]
mai = [1 for _ in range(N+1)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == mai[n]:
    return pat[n]
  
print(cnt_pat(X, N))

Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
pat = [0 for _ in range(N+1)]
mai = [0 for _ in range(N+1)]
pat[1] = 1
mai[1] = 1
for i in range(2, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 1:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == n:
    return pat[n]
  
print(cnt_pat(X, N))

Fixed submission:
N, X = map(int, input().split())
pat = [1 for _ in range(N+1)]
mai = [1 for _ in range(N+1)]
for i in range(1, N+1):
  mai[i] = 2 * mai[i-1] + 3
  pat[i] = 2 * pat[i-1] + 1

def cnt_pat(x, n):
  if n == 0:
    return 1
  if x == 1:
    return 0
  if x <= mai[n] // 2:
    return cnt_pat(x-1, n-1)
  if x == mai[n] // 2 + 1:
    return pat[n-1] + 1
  if x < mai[n]:
    return pat[n-1] + 1 + cnt_pat(x-mai[n]//2-1, n-1)
  if x == mai[n]:
    return pat[n]
  
print(cnt_pat(X, N))
Buggy python submission (verdict: Runtime Error):
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if int(x) <= N and '3' in x and '5' in x and '7' in x:
    cnt += 1
print(cnt)

Fixed submission:
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if '3' in x and '5' in x and '7' in x and int(x) <= N:
    cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if int(x) <= N and 3 in x and 5 in x and 7 in x:
    cnt += 1
print(cnt)

Fixed submission:
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if '3' in x and '5' in x and '7' in x and int(x) <= N:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
li = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    li[p].append([i, y])
ans = [0 for _ in range(M)]
for i in range(1, N+1):
    iy = li[i]
    iy.sort(key=lambda x: x[1])
    for j in range(len(iy)):
        ans[iy[j][0]] = (i, j+1)
for shi in ans:
    print(f'{shi[0]:06}{shi[1]:06}')

Fixed submission:
N, M = map(int, input().split())
li = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    li[p].append([i, y])
ans = [0 for _ in range(M)]
for i in range(1, N+1):
    iy = li[i]
    iy.sort(key=lambda x: x[1])
    for j in range(len(iy)):
        ans[iy[j][0]] = (i, j+1)
for shi in ans:
    print('{:06d}{:06d}'.format(shi[0], shi[1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
if N == 1:
    print('Hello World')
else:
    print(A+B)

Fixed submission:
N = int(input())
if N == 1:
    print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
x = [map(int, input().split()) for _ in range(N)]
x.sort(key=lambda y:y[0], reverse=True)
ans = 0
for (c, t) in x:
    if t <= T:
        ans = c
print(ans)

Fixed submission:
N, T = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
x.sort(key=lambda y:y[0], reverse=True)
ans = 0
for (c, t) in x:
    if t <= T:
        ans = c
if ans == 0:
    print('TLE')
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
pos = [list(map(int, input().split())) for _ in range(N)]
for cx in range(101):
    for cy in range(101):
        minH = 1 << 29
        se = set()
        for x,y,h in pos:
            a = -abs(x-cx)-abs(y-cy)
            if h <= a:
                break
            elif h == 0:
                minH = min(minH, -a)
            else:
                se.add(h-a)
        else:
            if len(se) == 0 and minH == 1:
                print(cx, cy, hh)
            elif len(se) == 1:
                hh = se.pop()
               if hh <= minH:
                   print(cx, cy, hh)

Fixed submission:
N = int(input())
pos = [list(map(int, input().split())) for _ in range(N)]
for cx in range(101):
    for cy in range(101):
        minH = 1 << 30
        se = set()
        for x,y,h in pos:
            a = -abs(x-cx)-abs(y-cy)
            if h == 0 and a == 0:
                break
            elif h == 0:
                minH = min(minH, -a)
            else:
                se.add(h-a)
        else:
            if len(se) == 0 and minH == 1:
                print(cx, cy, minH)
            elif len(se) == 1:
                hh = se.pop()
                if hh <= minH:
                   print(cx, cy, hh)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ans = 1
for i in range(1, M//N+1):
    if M % i == 0 and N * i <= M:
        ans = i
print(ans)

Fixed submission:
N, M = map(int, input().split())
ans = 1
x = 1
while x * x <= M:
    if M % x == 0:
        if x >= N:
            ans = max(ans, M//x)
        if M//x >= N:
            ans = max(ans, x)
    x += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
l = len(S)
right = True
for c in range(26):
    st = set()
    for i in range(l):
        if ord(T[i]) == ord('a') + c:
            st.add(S[i])
    if len(st) > 1:
        right = False
for c in range(26):
    st = set()
    for i in range(l):
        if ord(S[i]) == ord('a') + c:
            st.add(T[i])
    if len(st) > 1:
        right = False
print("Yes" if right else "No")

Fixed submission:
S = input()
T = input()
l = len(S)
right = True
dic = {}
for i in range(l):
    if T[i] not in dic:
        dic[T[i]] = set()
    dic[T[i]].add(S[i])
for key, st in dic.items():
    if len(st) > 1:
        right = False
dic = {}
for i in range(l):
    if S[i] not in dic:
        dic[S[i]] = set()
    dic[S[i]].add(T[i])
for key, st in dic.items():
    if len(st) > 1:
        right = False
print("Yes" if right else "No")
Buggy python submission (verdict: Runtime Error):
A, B = [int(x) for x in innput().split()]
print(max(0, A - B*2))

Fixed submission:
A, B = [int(x) for x in input().split()]
print(max(0, A - B*2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

prev = None
count = 0

for i in S:
  if prev != i:
  	prev = i
    count += 1
print(count)

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

prev = None
count = 0

for i in S:
  if prev != i:
    prev = i
    count += 1
    
print(count)

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

prev = None
for i in S:
  if prev != i:
  	prev = i
    count += 1
print(count)

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

prev = None
count = 0

for i in S:
  if prev != i:
    prev = i
    count += 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
class Queue(object): 

def __init__(self): 
self.queue_list = [] 

def enqueue(self, value): 
self.queue_list.append(value) 

def dequeue(self): 
try: 
value = self.queue_list.pop(0) 
except IndexError: 
value = None 

return value 
N = int(input()) 

pair = [] 
tree = {} 

for _ in range(N-1): 
a, b = list(map(int, input().split(" "))) 
if a in tree.keys(): 
tree[a].append(b) 
else: 
tree[a] = [b] 

if b in tree.keys(): 
tree[b].append(a) 
else: 
tree[b] = [a] 
pair.append([a,b]) 

c = list(map(int, input().split(" "))) 
c.sort(reverse=True) 
c = c[:N+2] 


queue = Queue() 
tree_l = {} 
for key in tree.keys(): 
tree_l[key] = len(tree[key]) 

ans = {} 
max_node = max((v, k) for k, v in tree_l.items())[1] 
ans[max_node] = c[0] 
used = [max_node] 
cnt = 0 

candi = {} 
for i in tree[max_node]: 
candi[i] = tree_l[i] 

for k, v in sorted(candi.items(), key=lambda x: -x[1]): 
queue.enqueue(k) 
used.append(k) 

while True: 
node = queue.dequeue() 
cnt += 1 
ans[node] = c[cnt] 

if cnt == N-1: 
break 

candi = {} 
for i in tree[node]: 
candi[i] = tree_l[i] 
for k, v in sorted(candi.items(), key=lambda x: -x[1]): 
if k not in used: 
queue.enqueue(k) 
used.append(k) 
total = 0 
for a, b in pair: 
if ans[a] > ans[b]: 
total += ans[b] 
else: 
total += ans[a] 

print(total) 
for i in range(1, N, 1): 
print(ans[i], end=" ") 

print(ans[N])

Fixed submission:
class Queue(object):

    def __init__(self):
        self.queue_list = []

    def enqueue(self, value):
        self.queue_list.append(value)

    def dequeue(self):
        try:
            value = self.queue_list.pop(0)
        except IndexError:
            value = None

        return value

N = int(input())

pair = []
tree = {}

for _ in range(N-1):
    a, b = list(map(int, input().split(" "))) 
    if a in tree.keys():
        tree[a].append(b)
    else:
        tree[a] = [b]
        
    if b in tree.keys():
        tree[b].append(a)
    else:
        tree[b] = [a]
    pair.append([a,b])
    
c = list(map(int, input().split(" ")))
c.sort(reverse=True)
c = c[:N+2]


queue = Queue()
tree_l = {}
for key in tree.keys():
    tree_l[key] = len(tree[key])

ans = {}
max_node = max((v, k) for k, v in tree_l.items())[1]
ans[max_node] = c[0]
used = [max_node]
cnt = 0

candi = {}
for i in tree[max_node]:
    candi[i] = tree_l[i]

for k, v in sorted(candi.items(), key=lambda x: -x[1]):
    queue.enqueue(k)
    used.append(k)

while True:
    node = queue.dequeue()
    cnt += 1
    ans[node] = c[cnt]
    
    if cnt == N-1:
        break
    
    candi = {}
    for i in tree[node]:
        candi[i] = tree_l[i]
    for k, v in sorted(candi.items(), key=lambda x: -x[1]):
        if k not in used:
            queue.enqueue(k)
            used.append(k)
total = 0
for a, b in pair:
    if ans[a] > ans[b]:
        total += ans[b]
    else:
        total += ans[a]
        
print(total)
for i in range(1, N, 1):
    print(ans[i], end=" ")

print(ans[N])
Buggy python submission (verdict: Runtime Error):
# A
N = int(input())
K = int(input())

print(N-K+1)

Fixed submission:
N, K = [int(x) for x in input().split()]
print(N-K+1)
Buggy python submission (verdict: Runtime Error):
### C
import math

N = int(input())
A = [int(x) for x in input().split()]

left = [0] * (N+1)
right = [0] *(N+1)

for i in range(N):
    left[i+1] = math.gcd(left[i], A[i])
for i in reversed(range(N)):
    right[i] = math.gcd(right[i+1], A[i])
    
res = 0
for i in range(N):
    l = left[i]
    r = right[i+1]
    res = max(math.gcd(l, r), res)

print(res)

Fixed submission:
### C

def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if b > a:
        a, b = b, a 
    return gcd(b, a%b)

N = int(input())
A = [int(x) for x in input().split()]

left = [0] * (N+1)
right = [0] *(N+1)

for i in range(N):
    left[i+1] = gcd(A[i], left[i])
for i in reversed(range(N)):
    right[i] = gcd(A[i], right[i+1])
    
res = 0
for i in range(N):
    l = left[i]
    r = right[i+1]
    res = max(gcd(l, r), res)

print(res)

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

N = int(input())
A = [int(x) for x in input().split()]

left = [0] * (N+1)
right = [0] *(N+1)

for i in range(N):
    left[i+1] = math.gcd(left[i], A[i])
for i in reversed(range(N)):
    right[i] = math.gcd(right[i+1], A[i])
    
res = 0
for i in range(N):
    l = left[i]
    r = right[i+1]
    res = max(math.gcd(l, r), res)

print(res)

Fixed submission:
### C

def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if b > a:
        a, b = b, a 
    return gcd(b, a%b)

N = int(input())
A = [int(x) for x in input().split()]

left = [0] * (N+1)
right = [0] *(N+1)

for i in range(N):
    left[i+1] = gcd(A[i], left[i])
for i in reversed(range(N)):
    right[i] = gcd(A[i], right[i+1])
    
res = 0
for i in range(N):
    l = left[i]
    r = right[i+1]
    res = max(gcd(l, r), res)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
# D

N = int(input())
A = [int(x) for x in input().split()]

# abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    
tmp = [sum(A)]
for i in reversed(range(0, N-1)):
    A[i] *= -1
    A[i+1] *= -1
    tmp.append(sum(A))
    
print(max(tmp))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1

if abs(min(A)) != min(abs_list):
    A[A.index(min(A))] *= -1
    A[A.index(min(abs_list))] *= -1
    
print(sum(A))

Buggy python submission (verdict: Runtime Error):
# D

N = int(input())
A = [int(x) for x in input().split()]

# abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    
tmp = [A]
for i in reversed(range(0, N-1)):
    A[i] *= -1
    A[i+1] *= -1
    tmp.append(sum(A))
    
print(max(tmp))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1

if abs(min(A)) != min(abs_list):
    A[A.index(min(A))] *= -1
    A[A.index(min(abs_list))] *= -1
    
print(sum(A))
Buggy python submission (verdict: Runtime Error):
H, W = [int(i) for input().split()]
bh, bw = [int(i) for input().split()]

res = (H * W) - ((bh*W) + (bh*H) - (bh*bw))

print(res)

Fixed submission:
H, W = [int(i) for i in input().split()]
bh, bw = [int(i) for i in input().split()]

res = (H * W) - ((bh*W) + (bw*H) - (bh*bw))

print(res)
Buggy python submission (verdict: Runtime Error):
A, B, K = [int(i) for i in input().split()]

res_a = set() 
res_b = set() 
lim = min(A, B)
for i in range(1, lim):
    if A%i == 0:
        res_a.add(i)
    if B%i == 0:
        res_b.add(i)

a_b_union = list(res_a | res_b)

print(a_b_union[K-1])

Fixed submission:
A, B, K = [int(i) for i in input().split()]

res = []
for i in range(1, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        res.append(i)

print(res[::-1][K-1])