Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03718 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)
class FK:
    def __init__(self,n):
        self.table=[[0]*n for i in range(n)]
        self.n=n
    
    def add(self,x,y,f):
        self.table[x][y]=f
        
    def ford(self,s,t,f):
        self.visit[s]=True
        if s==t:
            return f
        for i in range(self.n):
            if (not self.visit[i]) and self.table[s][i]>0:
                df=self.ford(i,t,min(f,self.table[s][i]))
                if df>0:
                    self.table[s][i]-=df
                    self.table[i][s]+=df
                    return df
        return 0
    
    def flow(self,s,t):
        ans=0
        inf=10**20
        while True:
            self.visit=[False]*(self.n)
            df=self.ford(s,t,inf)
            if df==0:
                break
            ans+=df
        return ans

H,W=map(int,input().split())
C=[input() for i in range(H)]
maxflow=FK(W+H+2)
inf=10**20
for i in range(W):
    for j in range(H):
        if C[j][i]=='S':
            sx=i
            sy=j
            maxflow.add(0,i+1,inf)
            maxflow.add(0,W+1+j,inf)
            continue
        if C[j][i]=='T':
            gx=i
            gy=j
            maxflow.add(i+1,W+H+1,inf)
            maxflow.add(W+1+j,W+H+1,inf)
            continue
        if C[j][i]=='o':
            maxflow.add(i+1,W+1+j,1)
            maxflow.add(W+1+j,i+1,1)
#print(maxflow.table)
if gx==sx or gy==sy:
    print('-1')
    sys.exit()
ans=maxflow.flow(0,H+W+1)
print(ans)

Buggy submission (verdict: Runtime Error):
class FK:
    def __init__(self,n):
        self.table=[[0]*n for i in range(n)]
        self.n=n
    
    def add(self,x,y,f):
        self.table[x][y]=f
        
    def ford(self,s,t,f):
        self.visit[s]=True
        if s==t:
            return f
        for i in range(self.n):
            if (not self.visit[i]) and self.table[s][i]>0:
                df=self.ford(i,t,min(f,self.table[s][i]))
                if df>0:
                    self.table[s][i]-=df
                    self.table[i][s]+=df
                    return df
        return 0
    
    def flow(self,s,t):
        ans=0
        inf=10**20
        while True:
            self.visit=[False]*(self.n)
            df=self.ford(s,t,inf)
            if df==0:
                break
            ans+=df
        return ans

H,W=map(int,input().split())
C=[input() for i in range(H)]
maxflow=FK(W+H+2)
inf=10**20
for i in range(W):
    for j in range(H):
        if C[j][i]=='S':
            sx=i
            sy=j
            maxflow.add(0,i+1,inf)
            maxflow.add(0,W+1+j,inf)
            continue
        if C[j][i]=='T':
            gx=i
            gy=j
            maxflow.add(i+1,W+H+1,inf)
            maxflow.add(W+1+j,W+H+1,inf)
            continue
        if C[j][i]=='o':
            maxflow.add(i+1,W+1+j,1)
            maxflow.add(W+1+j,i+1,1)
#print(maxflow.table)
if gx==sx or gy==sy:
    print('-1')
    sys.exit()
ans=maxflow.flow(0,H+W+1)
print(ans)
Problem p03735 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    A.append((c,d))
    C.append(c)
    D.append(d)
A.sort()
#print(A,C,D,si,ti)
if N==1:
    print(0)
    sys.exit()
ans=(max(C)-min(C))*(max(D)-min(D))
cur=max(C)
ma=min(D)
T=10**19
for a,b in A:
    if a>ma:
        T=min(T,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)
print(min(ans,(max(D)-min(C))*T))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N=int(input())
A=[]
C=[]
D=[]
for i in range(N):
    a,b=map(int,input().split())
    c,d=min(a,b),max(a,b)
    A.append((c,d))
    C.append(c)
    D.append(d)
#print(A,C,D,si,ti)
if N==1:
    print(0)
    sys.exit()
ans=(max(C)-min(C))*(max(D)-min(D))
cur=min(D)
ma=min(D)
T=10**19
for a,b in A:
    if a>ma:
        T=min(best,cur-ma)
        break
    T=min(T,cur-a)
    cur=max(cur,b)

print(min(ans,(max(D)-min(C))*T))
Problem p04017 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
#print(F)
dp=[ [N-1] * (N) for i in range(18)]

for i in range(N):
    #dp[0][i]=i
    dp[0][i]=F[i]
for c in range(1,18):
    for i in range(N):
        dp[c][i] = dp[c-1][ dp[c-1][i] ]
#print(dp)

def f(a,b):
    num=0
    t = a
    while True:
        for i in range(18):
            if dp[i][t]>=b:
                s=i
                break
        if s==0:
            num+=1
            break
        num += pow(2, s - 1)
        t = dp[s-1][t]
    print(num)
for a,b in T:
    f(a,b)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
X=[int(i) for i in input().split()]
L=int(input())
Q=int(input())
#T=[[int(i) for i in input().split()] for i in range(Q)]
T=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    T.append((a-1,b-1))
F=[0]*N
for i in range(N):
    F[i]= bisect(X, X[i] + L) -1
#print(F)
dp=[ [N-1] * (N) for i in range(17)]

for i in range(N):
    #dp[0][i]=i
    dp[0][i]=F[i]
for c in range(1,17):
    for i in range(N):
        dp[c][i] = dp[c-1][ dp[c-1][i] ]
#print(dp)

def f(a,b):
    num=0
    t = a
    while True:
        for i in range(17):
            if dp[i][t]>=b:
                s=i
                break
        if s==0:
            num+=1
            break
        num += pow(2, s - 1)
        t = dp[s-1][t]
    print(num)
for a,b in T:
    f(a,b)
Problem p04039 (python)

Fixed submission:
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,100001):
    x=str(i)
    flag=True
    for k in range(len(x)):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
L=[0]*10
for i in range(K):
    L[D[i]]=1
for i in range(N,10000):
    x=str(i)
    flag=True
    for k in range(4):
        y=int(x[k])
        if L[y]==1:
            flag=False
    if flag:
        print(i)
        sys.exit()
Problem p03106 (python)

Fixed submission:
a, b, k = [int(i) for i in input().split()]

x = max(a, b)
y = min(a, b)
gcd = 0
if x % y == 0:
    gcd = y
else:
    while x % y != 0:
        z = x % y
        x = y
        y = z
    else:
        gcd = z

list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])

Buggy submission (verdict: Runtime Error):
import math
a, b, k = [int(i) for i in input().split()]

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])

Buggy submission (verdict: Runtime Error):
a, b, k = [int(i) for i in input().split()]

gcd = math.gcd(a, b)
list_gcd = list()

for i in range(1, int(gcd/2) + 1):
    if gcd % i == 0:
        list_gcd.append(i)

list_gcd.append(gcd)
print(list_gcd[-k])
Problem p03141 (python)

Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
import math


n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print takahashi - aoki

Buggy submission (verdict: Runtime Error):
n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print(takahashi - aoki)
Problem p02971 (python)

Fixed submission:
import copy
N = int(input())
A = []
for _ in range(N):
  A.append(int(input()))
a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Buggy submission (verdict: Runtime Error):
import copy
A = list(map(int, input().split()))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)

Buggy submission (verdict: Runtime Error):
import copy
A = list(map(int, input().split))

a = max(A)
AA = copy.deepcopy(A)
AA.remove(a)
b = max(AA)

for hoge in A:
  if hoge == a:
    print(b)
  else:
    print(a)
Problem p03047 (python)

Fixed submission:
a, b=list(map(int, input().split()))
print(a-b+1)

Buggy submission (verdict: Runtime Error):
a, b=list(map(int, input().split))
print(a-b+1)
Problem p03339 (python)

Fixed submission:
n = int(input())
s = list(input())
 
c = 0
for i in range(1,n):
  if s[i] == "E":
    c+=1
 
min = c
 
 
for i in range(n-1):
  if s[i] == s[i+1]:
    if s[i] == "W":
      c+=1
    else:
      c-=1
  if c < min:
    min = c
 
print(min)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())

c = 0
for i in s:
  if i == "E":
    c+=1

min = c


for i in range(n):
  if s[i] == s[i+1]:
    if s[i] == "W":
      c+=1
    else:
      c-=1
  if c < min:
    min = c

temp = 0
for i in range(n-1):
  if s[i] == "W":
    temp += 1
  
if temp < min:
  min = temp 

print(min)
Problem p03457 (python)

Fixed submission:
N = int(input())
tmp = [0,0,0]
data = [0,0,0]
flag = True
for i in range(N):
  tmp = list(map(int,(input()).split()))
  if (tmp[0] - data[0])%2 == (tmp[1] + tmp[2] - data[1] - data[2]) % 2 + 1 or (tmp[1] - data[1] + tmp[2] - data[2] > tmp[0] - data[0]):
    flag = False
    break
  else:
    data = tmp

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

Buggy submission (verdict: Runtime Error):
N = int(input())
tmp = [0,0,0]
data=list(map(int,(input()).split()))
flag = True
for i in range(N):
  tmp = list(map(int,(input()).split()))
  if (tmp[0] - data[0])%2 == (tmp[1] + tmp[2] - data[1] - data[2]) % 2 + 1:
    flag = False
    break
  else:
    data = tmp

if flag:
  print("Yes")
else:
  print("No")
Problem p03852 (python)

Fixed submission:
print("vowel" if input() in ["a","e","i","o","u"] else "consonant")

Buggy submission (verdict: Runtime Error):
print(['vowel','consonant'][['a','e','i','o','u'].in(input())])
Problem p03005 (python)

Fixed submission:
(lambda n,k: print(0 if k==1 else n-k))(*list(map(int,input().split())))

Buggy submission (verdict: Runtime Error):
(lambda n,k: print(0 if k==1 else n-k))(*map(int,input().split())
Problem p03007 (python)

Fixed submission:
n,a=int(input()),sorted(list(map(int,input().split())))
mn,mx=a[0],a[-1]
for i in a[1:-1]:
  if i<0:mx-=i
  else:mn-=i
print(mx-mn)
mn,mx=a[0],a[-1]
for i in a[1:-1]:
  if i<0:print(mx,i);mx-=i
  else:print(mn,i);mn-=i
print(mx,mn)

Buggy submission (verdict: Runtime Error):
(lambda __g, __y, __operator, __print: [[(a.sort(), [(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [(lambda __after: [__after() for __g['mx'] in [(__operator.isub(__g['mx'], i))]][0] if (i < 0) else [__after() for __g['mn'] in [(__operator.isub(__g['mn'], i))]][0])(lambda: __this()) for __g['i'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(a[1:-1]), lambda: (__print((mx - mn)), [(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [(lambda __after: (__print(((str(mx) + ' ') + str(i))), [__after() for __g['mx'] in [(__operator.isub(__g['mx'], i))]][0])[1] if (i < 0) else (__print(((str(mn) + ' ') + str(i))), [__after() for __g['mn'] in [(__operator.isub(__g['mn'], i))]][0])[1])(lambda: __this()) for __g['i'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(a[1:-1]), lambda: (__print(((str(mx) + ' ') + str(mn))), None)[1], []) for (__g['mn'], __g['mx']) in [((a[0], a[-1]))]][0])[1], []) for (__g['mn'], __g['mx']) in [((a[0], a[-1]))]][0])[1] for __g['a'] in [(list(map(int, input().split())))]][0] for __g['n'] in [(int(input()))]][0])(globals(), (lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), __import__('operator', level=0), __import__('builtins', level=0).__dict__['print'])
Problem p03008 (python)

Fixed submission:
def solve(n,a,b):
    dp=[0]*(n+1)
    for w in range(n+1): dp[w]=max(w,dp[w-a[0]]+b[0]if w-a[0]>=0 else w,dp[w-a[1]]+b[1]if w-a[1]>=0 else w,dp[w-a[2]]+b[2]if w-a[2]>=0 else w)
    return dp[-1]
N,A,B=int(input()),list(map(int, input().split())),list(map(int, input().split()))
print(solve(solve(N,A,B),B,A))

Buggy submission (verdict: Runtime Error):
(lambda __g, __y, __print: [[(__print(solve(solve(N, A, B), B, A)), None)[1] for (__g['N'], __g['A'], __g['B']) in [((int(input()), list(map(int, input().split())), list(map(int, input().split()))))]][0] for __g['solve'], solve.__name__ in [(lambda n, a, b: (lambda __l: [[(lambda __items, __after, __sentinel: __y(lambda __this: lambda: (lambda __i: [[__this() for __l['dp'][__l['w']] in [(max(__l['w'], ((__l['dp'][(__l['w'] - __l['a'][0])] + __l['b'][0]) if ((__l['w'] - __l['a'][0]) >= 0) else __l['w']), ((__l['dp'][(__l['w'] - __l['a'][1])] + __l['b'][1]) if ((__l['w'] - __l['a'][1]) >= 0) else __l['w']), ((__l['dp'][(__l['w'] - __l['a'][2])] + __l['b'][2]) if ((__l['w'] - __l['a'][2]) >= 0) else __l['w'])))]][0] for __l['w'] in [(__i)]][0] if __i is not __sentinel else __after())(next(__items, __sentinel)))())(iter(range((__l['n'] + 1))), lambda: __l['dp'][-1], []) for __l['dp'] in [(([0] * (__l['n'] + 1)))]][0] for __l['n'], __l['a'], __l['b'] in [(n, a, b)]][0])({}), 'solve')]][0])(globals(), (lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), __import__('builtins', level=0).__dict__['print'])
Problem p02975 (python)

Fixed submission:
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==2 and l.count(sl[1])==2*n//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and l.count(sl[1])==(2*n)//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and l.count(sl[1])==2*n//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l3 = list(map(int,input().split()))
l = set(l3)
l2 = list(l)
if n % 3 != 0:
    print("No")
elif len(l) != 3:
  if len(l)==1 and l2[0]==0:
    print("Yes")
  elif len(l)==2:
    if l3.count(l[0])>l3.count(l[1]):
      if l[0]==l[0]^l[1] and l[1]==l[0]^l[0]:
          print("Yes")
      else:
          print("No")
    elif l3.count(l[1])>l3.count(l[0]):
      if l[1]==l[1]^l[0] and l[0]==l[1]^l[1]:
          print("Yes")
      else:
          print("No")
          
    print("Yes")
  else:
    print("No")
else:
    if (l2[0] ^ l2[1] == l2[2]) and (l2[1] ^ l2[2] == l2[0]) and (l2[2] ^ l2[0] == l2[1]):
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l = set(map(int,input().split()))
l2 = list(l)
if n % 3 != 0:
    print("No")
elif len(l) != 3:
  if len(l)==1 and l2[0]==0:
    print("Yes")
  elif len(l)==2 and ((l2[0]^l2[1]==l2[1] and l2[1]^l2[1]==l2[0]) or　(l2[0]^l2[1]==l2[0] and l2[1]^l2[1]==l2[0]) or (l2[1]^l2[0]==l2[0] and l2[0]^l2[0]==l2[1]) or (l2[1]^l2[0]==l2[1] and l2[0]^l2[0]==l2[1])):
    print("Yes")
  else:
    print("No")
else:
    if (l2[0] ^ l2[1] == l2[2]) and (l2[1] ^ l2[2] == l2[0]) and (l2[2] ^ l2[0] == l2[1]):
        print("Yes")
    else:
        print("No")
Problem p02963 (python)

Fixed submission:
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
if y3 > 10 ** 9:
    x2 += 1
    y3 = -(-s // x2)
y2 = x2 * y3 - s
print(x1, y1, x2, y2, x3, y3)

Buggy submission (verdict: Runtime Error):
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
y2 = x2 * y3 - s
if y3 > 10 ** 9:
    a
print(x1, y1, x2, y2, x3, y3)

Buggy submission (verdict: Runtime Error):
s = int(input())

x1 = 0
y1 = 0
x2 = int(s ** 0.5)
y3 = -(-s // x2)
x3 = 1
y2 = x2 * y3 - s
if x2 * y3 - x3 * y2 != s or x2 > 10 ** 9 or y3 > 10 ** 9:
    a
print(x1, y1, x2, y2, x3, y3)
Problem p03026 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
c = list(map(int, input().split()))
c.sort(reverse=True)

num = 0
def point(x, prev, turn=0):
    global num
    if turn > n:
        return
    dp[x] = c[num]
    num += 1
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
    e.append((a - 1, b - 1))
c = list(map(int, input().split()))
c.sort(reverse=True)

def point(x, prev, turn=0):
    if turn > n:
        return
    dp[x] = c[n - dp.count(0)]
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))

Buggy submission (verdict: Runtime Error):
n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
    e.append((a - 1, b - 1))
c = list(map(int, input().split()))
c.sort(reverse=True)

def point(x, prev, turn=0):
    if turn > n:
        return
    dp[x] = c[n - dp.count(0)]
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

ans = 0
for i in range(n):
    dp = [0] * n
    point(i, -1)

    m = 0
    for a, b in e:
        m += min(dp[a], dp[b])
    if m > ans:
        ans = m
        d = dp

print(ans)
print(" ".join(map(str, d)))
Problem p03061 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

ans = 1
if n == 2:
    print(max(a))
else:
    l = [0] * (n + 1)
    r = [0] * (n + 1)
    for i in range(1, n):
        l[i] = gcd(l[i - 1], a[i - 1])
        r[n - i] = gcd(r[n - i + 1], a[-i])
    for i in range(n):
        m = gcd(l[i], r[i + 1])
        ans = max(ans, m)
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())).sort(reverse=True)

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n // 10):
        b = a[:i] + a[i + 1:]
        element = gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = gcd(element, b[j])
            ans = max(ans, element)
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n):
        b = a[:i] + a[i + 1:]
        element = gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = gcd(element, b[i])
            ans = max(ans, element)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n):
        b = a[:i] + a[i + 1:]
        element = math.gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = math.gcd(element, b[i])
            ans = max(ans, element)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

ans = 1
for i in range(n):
    b = a[:i] + a[i + 1:]
    ans = max(ans, gcd_list(b))

print(ans)
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
sr = s[::-1]

ans = s.count(".")
num = ans
for i in range(n):
    if s[i] == ".":
        num -= 1
    else:
        num += 1
    ans = min(num, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

if s == "." * n:
    print(0)
else:
    black = s.index("#")
    white = [i for i, x in enumerate(s) if x == "."]
    wb = [i for i, x in enumerate(s[black:]) if x == "."]
    bw = [i for i, x in enumerate(s[:white[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

if s == "." * n:
    print(0)
else:
    black = [i for i, x in enumerate(s) if x == "#"]
    wb = [i for i, x in enumerate(s[black[0]:]) if x == "."]
    bw = [i for i, x in enumerate(s[:wb[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))
Problem p03128 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break
print("".join(map(str, num)))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if dp[k - match[j - 1]] == dp[k] - 1:
            num.append(j)
            k -= match[j - 1]
            break
print("".join(map(str, num)))