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

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
print((x-a)%b)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for c500 in range(a+1):
    for c100 in range(b+1):
        for c50 in range(c+1):
            if c500*500 + c100*100 + c50*50 == x:
                cnt += 1
        
print(cnt)
Problem p03474 (python)

Fixed submission:
import re

a,b = map(int, input().split())
s = input()

regex = '[0-9]{%d}-[0-9]{%d}' %(a,b)
print('Yes' if re.match(regex, s) else 'No')

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

try:
    if '-' not in s: raise 
    sa, sb = map(int, s.split('-'))
#     print(sa, sb)
    if len(sa)==a and len(sb)==b:
        print('Yes')
except ValueError:
    print('No')
Problem p03476 (python)

Fixed submission:
# D
N = 10**5
primes = set([])
is_prime = [True]*(N+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, N+1):
    if is_prime[i]:
        primes.add(i)
        for j in range(2, N//i+1):
            is_prime[j*i] = False
    
# like-2017
cnt = [0]*(int(1e5)+2)
for p in primes:
    if (p+1)//2 in primes:
        cnt[p] = 1
for i in range(1, int(1e5)+2):
    cnt[i] += cnt[i-1]
#print(cnt[:100])
    
Q = int(input())
for _ in range(Q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])

Buggy submission (verdict: Runtime Error):
# D
N = 10**5
primes = set([])
is_prime = [True]*(N+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, N+1):
    if is_prime[i]:
        primes.add(i)
        for j in range(2, N//i+1):
            is_prime[j*i] = False
    
# like-2017
cnt = [0]*(N+2)
for i in range(1, N+2):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
#print(cnt[:100])
    
Q = int(input())
for _ in range(Q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])
Problem p03479 (python)

Fixed submission:
x,y = map(int, input().split())

a = x # A[i]
for i in range(1,70):
            
    if (i==1 and a<y) or a*2 <= y: 
        a *= 2 # A[i+1]
        continue
    else: break

print(i)

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())

a = x # A[i]
for i in range(1,y):
            
    if (i==1 and a<=y) or a*2 <= y: 
        a *= 2 # A[i+1]
        continue
    else: break

print(i)
Problem p03504 (python)

Fixed submission:
# D
N,C = map(int, input().split())
st = [[] for _ in range(C)]
for _ in range(N):
    si,ti,ci = map(int, input().split())
    st[ci-1].append((si,ti))
    
T_MAX = int(1e5)
imos = [0]*(T_MAX+1)
for ch in range(C):
    if st[ch]==[]: continue
    st[ch].sort()
    prev_s, prev_t = st[ch][0]
    for si,ti in st[ch][1:]:
        if si!=prev_t:
            imos[prev_s-1] += 1
            imos[prev_t] -= 1
        else:
            imos[prev_s-1] += 1
            imos[prev_t-1] -= 1
        prev_s,prev_t = si,ti
    else:
        imos[prev_s-1] += 1
        imos[prev_t] -= 1
# print(imos)
ans = 1
wa = 0
for imosi in imos:
    wa += imosi
    ans = max(ans, wa)
print(ans)

Buggy submission (verdict: Runtime Error):
# D
N,C = map(int, input().split())
T_MAX = int(1e5)
t = [0]*(T_MAX+1)
for _ in range(N):
    si,ti,ci = map(int, input().split())
    t[si-1] += 1
    t[ti+1] -= 1
ans = 1
wa = 0
for ti in t:
    wa += ti
    ans = max(ans, wa)
print(ans)
Problem p03575 (python)

Fixed submission:
# C
N,M = map(int, input().split())
graph = [[False]*N for _ in range(N)]
visited = [False]*N

def dfs(cur):
    global visited
    visited[cur] = True
    for nxt in range(N):
        if graph[cur][nxt]==False: continue
        if visited[nxt]==True: continue
        dfs(nxt)


a = [-1]*M
b = [-1]*M
for i in range(M):
    ai,bi = map(int, input().split())
    a[i],b[i] = ai-1, bi-1
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

ans = 0
for i in range(M):
    graph[a[i]][b[i]] = False # 辺を消す
    graph[b[i]][a[i]] = False
    # print("graph: "+"\n".join(map(str, graph)))
    visited = [False]*N
    dfs(0)
    if not all(visited):
        ans += 1
    graph[a[i]][b[i]] = True # 辺を戻す
    graph[b[i]][a[i]] = True
    
print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFindWithRank:
    # par: 親の番号(はじめ par[i]==i つまりすべての頂点が根)
    def __init__(self, size:int):
        self.par = [-1]*size
        self.rank = [0]*size
        for i in range(size):
            self.par[i] = i
    
    def root(self, x:int)->int:
        """根を求める"""
        if self.par[x] == x: # if root
            return x
        else:
            self.par[x] = self.root(self.par[x]) # 経路圧縮
            return self.par[x]
        
    def isSame(self, x:int, y:int)->bool:
        """x と y が同じ集合に属するか否か"""
        return self.root(x)==self.root(y)
    
    def unite(self, x:int, y:int):
        """x と y の属する集合を併合"""
        root_x = self.root(x)
        root_y = self.root(y)
        if root_x == root_y: return
        
        # 短いほうを長いほうにくっつける
        if self.rank[root_x] < self.rank[root_y]:
            self.par[root_x] = root_y
        else:
            self.par[root_y] = root_x
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[root_x] += 1
                

##### main #####
N,M = map(int, input().split())
a,b = [0]*M, [0]*M
for i in range(M):
    ai,bi = map(int, input().split())
    a[i],b[i] = ai-1, bi-1
    
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if i==j: continue # この辺はパス
        uf.unite(a[j], b[j])
    bridge = False
    for i in range(N):
        if not uf.isSame(0,i):
            bridge = True
    if bridge:
        ans += 1
print(ans)
Problem p03576 (python)

Fixed submission:
# d
N,K = map(int, input().split())
xy = []
for _ in range(N):
    xy.append( tuple(map(int, input().split())) )
xs,ys = map(list, zip(*xy))
xs.sort()
ys.sort()
ans = float('inf')
for l in range(N):
    for r in range(l+1,N):
        for b in range(N):
            for t in range(b+1,N):
                xl,xr = xs[l],xs[r]
                yb,yt = ys[b],ys[t]
                cnt = 0
                for xi,yi in xy:
                    if xl<=xi<=xr and yb<=yi<=yt: 
                        cnt += 1
                if cnt>=K:
                    ans = min(ans, (xr-xl)*(yt-yb))
print(ans)

Buggy submission (verdict: Runtime Error):
# d
N,K = map(int, input().split())
xy = []
for _ in range(N):
    xy.append( tuple(map(int, input().split())) )
xs,ys = map(list, zip(*xy))
xs.sort()
ys.sort()
ans = float('inf')
for l in range(N):
    for r in range(l+1,N):
        for b in range(N):
            for t in range(t+1,N):
                xl,xr = xs[l],xs[r]
                yb,yt = ys[b],ys[t]
                cnt = 0
                for xi,yi in xy:
                    if xl<=xi<=xr and yb<=yi<=yt: 
                        cnt += 1
                if cnt>=K:
                    ans = min(ans, (xr-xl)*(yt-yb))
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
xy = []
for _ in range(N):
    xy.append( tuple(map(int, input().split())) )
xy.sort(key=lambda x:x[0])
ans = float('inf')
for i in range(N-K+1):
    use_x,use_y = xy[i:i+K]
    area = abs(max(use_x)-min(use_x)) * abs(max(use_y)-min(use_y))
    ans = min(ans, area)
print(ans)
Problem p03601 (python)

Fixed submission:
from fractions import gcd
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

G = gcd(C,D)
for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        sugar = int(G*(max_sugar//G))
        if sugar<min(C,D): continue
        if water+sugar==0: 
            continue
        if density(water, sugar)>density(ans["w"], ans["s"]):
            ans["w"] = water
            ans["s"] = sugar
            #print(water, sugar)
print(ans["w"]+ans["s"], ans["s"])

Buggy submission (verdict: Runtime Error):
# C sugar water
from collections import deque
def noudo(water, sugar):
    if water+sugar==0: return 0
    return 100*sugar/(water+sugar)

A,B,C,D,E,F = map(int, input().split())
q = deque([(0,0)]) # water, sugar
max_noudo = 0
ans = None
while q:
    water,sugar = q.popleft()
    cur = noudo(water, sugar)
    if cur>max_noudo:
        ans = (water, sugar)
        max_noudo = cur
    for dw,ds in [(100*A, 0), (100*B, 0), (0,C), (0,D)]:
        if noudo(water+dw, sugar+ds)>noudo(100, E) or water+dw+sugar+ds>F: continue
        q.append((water+dw, sugar+ds))
        
water, sugar = ans
print(water+sugar, sugar)
Problem p03625 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
cur = A[0]
cnt = 0
ans = []
for ai in A:
    if ai==cur: cnt += 1
    else: 
        cur = ai
        cnt = 1
    if cnt==2 or cnt==4:
        ans.append(cur)
    if len(ans)==2:
        print(ans[0]*ans[1])
        break
else:
    print(0)

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

cnt = [0]*(int(1e9)+1)
for ai in a:
    cnt[ai] += 1

ans = 0
condi = 0
for ai in a[::-1]:
    if cnt[ai] >= 4:
        ans = max(ans, ai*ai)
        break
    else:
        if condi==0:
            condi = ai
        else:
            ans = condi * ai
            break
            
print(ans)
Problem p03633 (python)

Fixed submission:
N = int(input())

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

lcm = 1
for i in range(N):
    t = int(input())
    lcm = t*lcm // gcd(lcm, t)

print(lcm)

Buggy submission (verdict: Runtime Error):
from math import gcd
N = int(input())

ans = int(input())
for _ in range(N-1):
    t = int(input())
    g = gcd(t, ans)
    ans = ans*t//g
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
T = list((int(input()) for i in range(N)))
    
    
def gcd2(a, b):
    if b == 0: return a
    return gcd2(b, a%b)

def lcm2(a, b):
    return int(a*b/gcd2(a, b))

def lcm(l):
    while len(l) > 1:
        tmp = lcm2(l.pop(), l.pop())
        l.append(tmp)
        
    return l[0]

print(lcm(T))
Problem p03854 (python)

Fixed submission:
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
#             print(S)
        else:
            print("NO")
            sys.exit()

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
#             print(S)
        else:
            print("NO")
            sys.exit()
        
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
            
    else:
        print("NO")
        sys.exit()
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
            print(S)
        else:
            print("NO")
            sys.exit()

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
            print(S)
        else:
            print("NO")
            sys.exit()
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
            print(S)
        else:
            print("NO")
            sys.exit()
        
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
            print(S)
        else:
            print("NO")
            sys.exit()
            
    else:
        print("NO")
        sys.exit()
else:
    print("YES")
Problem p03944 (python)

Fixed submission:
W,H,N = map(int, input().split())
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))
# print(s)

for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))

Buggy submission (verdict: Runtime Error):
W,H,N = 5,4,3
s = set([])
for h in range(H):
    for w in range(W):
        s.add((w+0.5, h+0.5))
# print(s)

for _  in range(N):
    x,y,a = map(int, input().split())
    rm = set([])
    if a==1:
        for si in s:
            if si[0]<x: rm.add(si)
    if a==2:
        for si in s:
            if si[0]>x: rm.add(si)
    if a==3:
        for si in s:
            if si[1]<y: rm.add(si)
    if a==4:
        for si in s:
            if si[1]>y: rm.add(si)
    s = s - rm
                
print(len(s))
Problem p03964 (python)

Fixed submission:
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max((t-1)//nt+1, (a-1)//na+1)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Buggy submission (verdict: Runtime Error):
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max(-(-t//nt), -(-a//na)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Buggy submission (verdict: Runtime Error):
from math import ceil
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    r = 1
    if nt<t:
        r *= ceil(t/nt)
    if na*r<a:
        r *= ceil(a/na)
    na = r*na
    nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)

Buggy submission (verdict: Runtime Error):
from math import ceil
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    r = 1
    if nt<t:
        r *= ceil(t/nt)
    if na<a:
        r *= ceil(a/na)
    na = r*na
    nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)
Problem p03264 (python)

Fixed submission:
#おそらく上は偶数の処理がおかしい
k = int(input())        
#奇数の場合
if (k%2) == 1:
    o = (k-1) * (k+1) / 8
    #eはoと同じ数値
    print(int(2*o))
#偶数の場合 
else:
    o = k * (k+2) / 8
    e = k * (k-2) / 8
    print(int(o+e))

Buggy submission (verdict: Runtime Error):
k = int(input())        
    if (k%2) == 0:
        o = (k*(k+1))/2
        e = (k*(k-1))/2
        print(o+e)
    else:
        o = (k*(k-1))/2
        e = (k*(k-1))/2
        print(o+e)

Buggy submission (verdict: Runtime Error):
k = int(input())
print((k+1) * (K // 2) / 2)
Problem p02804 (python)

Fixed submission:
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
a = sorted(map(int, input().split()))

factorialNumInverse = [None] * (n + 1)
naturalNumInverse = [None] * (n + 1)
fact = [None] * (n + 1)

def inverseofNumber():
    naturalNumInverse[0] = naturalNumInverse[1] = 1
    for i in range(2, n + 1):
        naturalNumInverse[i] = (naturalNumInverse[MOD % i] * (MOD - MOD // i) % MOD)

def inverseofFactorial():
    factorialNumInverse[0] = factorialNumInverse[1] = 1
    for i in range(2, n + 1):
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % MOD

def factorial():
    fact[0] = 1
    for i in range(1, n + 1):
        fact[i] = (fact[i - 1] * i) % MOD

inverseofNumber()
inverseofFactorial()
factorial()

def nCk(n, k):
    ans = ((fact[n] * factorialNumInverse[k]) % MOD * factorialNumInverse[n - k]) % MOD
    return ans

def calcSum(a):
    ret = 0
    for i in range(k - 1, n):
        ret += (nCk(i, k - 1) * a[i]) % MOD
        ret %= MOD
    return ret

print((calcSum(a) - calcSum(a[::-1])) % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
MAX = 10 ** 5 + 100

n, k = map(int, input().split())
a = sorted(map(int, input().split()))

def nCr(n, r):
    return (fac[n] * modInverse[fac[r]] % MOD * modInverse[fac[n - r]] % MOD) % MOD

def modularInverse(n):
    dp = [0] * (n + 1)
    dp[0] = dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = dp[MOD % i] * (MOD - MOD // i) % MOD
    return dp

fac = [1, 1]
for i in range(2, MAX + 1):
    fac.append((fac[-1] * i) % MOD)
modInverse = modularInverse(MAX)

ret = 0
for i in range(n - k + 2):
    for j in range(i + k - 1, n):
        diff = a[j] - a[i]
        between = max(0, j - i - 1)
        choose = max(0, k - 2)
        ret += (nCr(between, choose) * diff) % MOD
        ret %= MOD
print(ret)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
MAX = 10 ** 5

n, k = map(int, input().split())
a = sorted(map(int, input().split()))

def nCr(n, r):
    return (fac[n] * modInverse[fac[r]] % MOD * modInverse[fac[n - r]] % MOD) % MOD

def modularInverse(n):
    dp = [0] * (n + 1)
    dp[0] = dp[1] = 1
    for i in range(2, n + 1):
        dp[i] = dp[MOD % i] * (MOD - MOD // i) % MOD
    return dp

fac = [1, 1]
for i in range(2, MAX + 1):
    fac.append((fac[-1] * i) % MOD)
modInverse = modularInverse(MAX)

ret = 0
for i in range(n - k + 2):
    for j in range(i + k - 1, n):
        diff = a[j] - a[i]
        between = max(0, j - i - 1)
        choose = max(0, k - 2)
        ret += (nCr(between, choose) * diff) % MOD
        ret %= MOD
print(ret)
Problem p02843 (python)

Fixed submission:
has = int(input())
dp = [False] * (has + 1)
dp[0] = True
for i in range(100, has + 1):
    for p in range(100, 106):
        if i - p >= 0:
            dp[i] |= dp[i - p]
print(1 if dp[has] else 0)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

money = [0,1,2,3,4,5]
n = int(input())
p = 0
lm = n//100
need = n - (lm*100)
@lru_cache(None)
def dfs( cur,limit):
    global p,need
    if not p:
        for i in range(6):
            now = cur+money[i]
            if limit+1 == lm:
                if now == need:
                    p =1
                    break
            elif limit+1<=lm:
                dfs(now,limit+1)
if n>=100:
    dfs(0,0)
    print(1 if p else 0)
else:
    print(0)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

MOD = 1000000007

def dfs(par, v, val):
    for child in edges[v]:
        if child != par:
            ways[child] = max(0, val)
            val -= 1
            dfs(v, child, nColors - 2)

nVertices, nColors = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nVertices - 1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

ways = [0] * (nVertices + 1)
ways[1] = nColors
dfs(0, 1, nColors - 1)
ret = 1
for w in ways[1:]:
    ret = (ret * w) % MOD
print(ret)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007

def dfs(par, v, val):
    for child in edges[v]:
        if child != par:
            ways[child] = max(0, val)
            val -= 1
            dfs(v, child, nColors - 2)

nVertices, nColors = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nVertices - 1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

ways = [0] * (nVertices + 1)
ways[1] = nColors
dfs(0, 1, nColors - 1)
ret = 1
for w in ways[1:]:
    ret = (ret * w) % MOD
print(ret)
Problem p03006 (python)

Fixed submission:
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        key = (p, q)
        d.setdefault(key, 0)
        d[key] += 1
print(n - (max(d.values()) if d  else 0))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float('inf')
for i in range(n - 1):
    for j in range(i + 1, n):
        p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
        if p == 0 and q == 0:
            continue
        key = (p, q)
        d.setdefault(key, 0)
        d[key] += 1
print(n - max(d.values()))
Problem p03061 (python)

Fixed submission:
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
    fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
    ret = max(ret, curGcd)
print(ret)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
    fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
    ret = max(ret, curGcd)
print(ret)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight = [0] * n
fromRight[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
    fromRight[i] = gcd(fromRight[i + 1], a[i])
ret = 0
for i in range(n):
    if i == 0:
        curGcd = fromRight[i + 1]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i])
    ret = max(ret, curGcd)
print(ret)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight = [0] * n
fromRight[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
    fromRight[i] = gcd(fromRight[i + 1], a[i])
ret = 0
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i])
    ret = max(ret, curGcd)
print(ret)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight = [0] * n
fromRight[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
    fromRight[i] = gcd(fromRight[i + 1], a[i])
ret = 0
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i])
    ret = max(ret, curGcd)
print(ret)
Problem p03128 (python)

Fixed submission:
NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

nSticks, n = map(int, input().split())
a = list(map(int, input().split()))

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit)
for sticks in range(2, nSticks + 1):
    for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

nSticks, n = map(int, input().split())
a = list(map(int, input().split()))

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = digit
for sticks in range(2, nSticks + 1):
    for digit in a:
        if dp[sticks - NUM[digit]] > 0 and sticks - NUM[digit] >= 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])