Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
n = int(input())
c = Counter(map(int, input().split()))
s = set()
for i in c:
    c[i] -= 1
    for j in range(i, 10**6+1, i):
        if c[j]:
            s.add(j)
    c[i] += 1
r = 0
for i in c:
    r += c[i] * (i not in s)
print(r)

Fixed submission:
from collections import*
n = int(input())
c = Counter(map(int, input().split()))
s = set()
for i in c:
    c[i] -= 1
    for j in range(i, 10**6+1, i):
        if c[j]:
            s.add(j)
    c[i] += 1
r = 0
for i in c:
    r += c[i] * (i not in s)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
r = 0
p = 2
while n > 1:
    e = 0
    while n%p == 0:
       e += 1
       n /= p
    i = 1
    while e >= i:
        e -= i
        r += 1
        i += 1
    p += 1
print(r)

Fixed submission:
n = int(input())
r = 0
for p in range(2, int(n**0.5)+1):
    e = 0
    while n%p == 0:
       e += 1
       n /= p
    i = 1
    while e >= i:
        e -= i
        r += 1
        i += 1
if n != 1:
    r += 1
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
d = {1: 0}
q = [1]
for i in q:
    s = set(g[i]) - set(d)
    d.update(dict.fromkeys(s, i))
    q.extend(s)
print('Yes')
for i in range(2, n+1):
    print(d[i])

Fixed submission:
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)
d = {1:0}
q = [1]
for i in q:
    for j in g[i]:
        if j not in d:
            d[j] = i
            q.append(j)
print('Yes')
for i in range(2, n+1):
    print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import *
s = input()
p = 2019
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
    v += int(i)*k
    r += c[v%p]
    c[v%p] += 1
    k *= 10
print(r)

Fixed submission:
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[y-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r)

Buggy python submission (verdict: Runtime Error):
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r) 1

Fixed submission:
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[y-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
y = 2019
a = [0]*y
k = 1
r = 0
for i in range(len(s))[::-1]:
    j = int(s[i])*k%y
    tmp = [0]*y
    for i in range(2019):
        tmp[(i+j)%y] = a[i]
    tmp[j] += 1
    a = tmp
    r += a[0]
    k *= 10
    k %= y
print(r)



Fixed submission:
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[y-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
vis = {}
def dfs(i):
    if i in vis: return vis[i]
    vis[i] = True
    vis[i] = any(map(dfs, g[i]))
    return vis[i]
print(any(map(dfs, range(n)))-1)

Fixed submission:
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
vis = {}
vs = []
def dfs(i):
    if i in vis:
        if vis[i]:
            del vs[:vs.index(i)]
        return vis[i]
    vis[i] = True
    vs.append(i)
    for j in g[i]:
        if dfs(j):
            return True
    vis[i] = False
    vs.pop()
    return False
for i in range(n):
    if dfs(i):
        break
else:
    print(-1)
    exit()
dist = {v: i for i, v in enumerate(vs)}
vis = set()
ws = []
nxt = 0
for i in vs:
    if dist[i] < nxt:
        continue
    k = -1
    for j in g[i]:
        if j not in dist or dist[j]<dist[i] and j not in vis:
            continue
        if k == -1:
            k = j
            continue
        dj = (dist[j]-dist[i])%len(vs)
        dk = (dist[k]-dist[i])%len(vs) 
        if dj > dk:
            k, j = j, k
    nxt = dist[k]
    vis.add(i)
    ws.append(i)
    if k in vis:
        del ws[:ws.index(k)]
        break
print(len(ws))
for i in ws:
    print(i)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
vis = {}
def dfs(i):
    if i in vis: return vis[i]
    vis[i] = True
    vis[i] = any(map(dfs, g[i]))
    return vis[i]
print(any(map(dfs, range(n)))-1)

Fixed submission:
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
vis = {}
vs = []
def dfs(i):
    if i in vis:
        if vis[i]:
            del vs[:vs.index(i)]
        return vis[i]
    vis[i] = True
    vs.append(i)
    for j in g[i]:
        if dfs(j):
            return True
    vis[i] = False
    vs.pop()
    return False
for i in range(n):
    if dfs(i):
        break
else:
    print(-1)
    exit()
dist = {v: i for i, v in enumerate(vs)}
vis = set()
ws = []
nxt = 0
for i in vs:
    if dist[i] < nxt:
        continue
    k = -1
    for j in g[i]:
        if j not in dist or dist[j]<dist[i] and j not in vis:
            continue
        if k == -1:
            k = j
            continue
        dj = (dist[j]-dist[i])%len(vs)
        dk = (dist[k]-dist[i])%len(vs) 
        if dj > dk:
            k, j = j, k
    nxt = dist[k]
    vis.add(i)
    ws.append(i)
    if k in vis:
        del ws[:ws.index(k)]
        break
print(len(ws))
for i in ws:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
n, m = list(map(int,input().split()))
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n)[::-1]:
    for j in range(m)[::-1]:
        if s[i] == t[j]:
            dp[i][j] += 1 + dp[i+1][j+1] 
            dp[i][j] %= mod
        dp[i][j] += dp[i+1][j] + dp[i][j+1] - dp[i+1][j+1]
        dp[i][j] %= mod
print((dp[0][0]+1)%mod)

Fixed submission:
mod = 10**9+7
n, m = list(map(int,input().split()))
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [0]*(m+1)
for i in range(n)[::-1]:
    old = 0
    for j in range(m)[::-1]:
        tmp = dp[j] + dp[j+1] - old
        tmp %= mod
        if s[i]== t[j]:
            tmp += 1 + old
            tmp %= mod
        dp[j], old = tmp, dp[j]
print((dp[0]+1)%mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
m = sum(i<0 for i in a)
if m%2==0:
    print(sum(map(abs, a)))
else:
    print(sum(map(abs, a)) - min(i for i in a if i>=0)*2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = sum(i<0 for i in a)
if m%2==0:
    print(sum(map(abs, a)))
else:
    print(sum(map(abs, a)) - min(map(abs, a))*2)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = map(int, input().split())
a,b,c = (list(map(int, input().split())) for _ in range(3))
bc = sorted(i+j for i in b for j in c)[::-1][:k]
abc = sorted(i+j for i in sorted(a) for j in bc)[::-1][:k]
for i in abc:
    print(i)

Fixed submission:
from heapq import *
x,y,z,K = map(int, input().split())
m = [sorted(map(int, input().split()))[::-1] for _ in range(3)]
q = [(-sum(i[0] for i in m),(0,0,0))]
r = 0
s = set()
for _ in range(K):
    v,a = heappop(q)
    v = -v
    print(v)
    for p in ((0,0,1),(0,1,0),(1,0,0)):
        p = tuple(i+j for i,j in zip(p,a))
        if not p in s and all(i<j for i,j in zip(p,(x,y,z))):
            s.add(p)
            heappush(q, (-sum(i[j] for i,j in zip(m,p)), p))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
def f(i):
    x = a>>i
    y = b>>i
    r = 0
    if x==y:
        if x&1:
            r^=(y-x+1)%2
        return r
    if x&1:
        r^=(a-x+1)%2
    if y&1:
        r^=(b-y)%2
    return r
print(int(''.join([str(f(i)) for i in range(len(bin(b))-2)])[::-1],2))

Fixed submission:
a,b=map(int,input().split())
r=0
if a%2==1:
    r=a
    a+=1
if a<=b:
    x,y=divmod(b-a+1,2)
    r^=x%2^b*y
print(r)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
def f(i):
    x = a>>i
    y = b>>i
    r = 0
    if x==y:
        if x&1:
            r^=(y-x+1)%2
        return r
    if x&1:
        r^=(a-x+1)%2
    if y&1:
        r^=(b-y)%2
    return r
print(int(''.join([str(f(i)) for i in range(len(bin(b))-2)])[::-1],2))

Fixed submission:
a,b=map(int,input().split())
r=0
if a%2==1:
    r=a
    a+=1
if a<=b:
    x,y=divmod(b-a+1,2)
    r^=x%2^b*y
print(r)
Buggy python submission (verdict: Runtime Error):
from math import *
from collections import *
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
mi = min(a, key=lambda x: c[x])
x = sum(c[i]*c[mi]//gcd(c[i],c[mi]) for i in a if i!=mi)
q, r = divmod(max(0, n-x), c[mi])
n = min(n, x+r)
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(2, n+1):
    for j in a:
        if i >= c[j]:
            dp[i] = max(dp[i], dp[i-c[j]]+1)
d = Counter()
d[mi] += q
while n:
    i = max((i for i in a if n>=c[i]), key=lambda x: dp[n-c[x]])
    d[i] += 1
    n -= c[i]
print(''.join(str(k)*d[k] for k in sorted(d)[::-1]))

Fixed submission:
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(2, n+1):
    for j in a:
        if i >= c[j]:
            dp[i] = max(dp[i], dp[i-c[j]]+1)
r = []
while n:
    i = max((i for i in a if n>=c[i]), key=lambda x: dp[n-c[x]])
    r.append(i)
    n -= c[i]
print(''.join(map(str, r)))

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(2, n+1):
    for j in a:
        if i >= j:
            dp[i] = max(dp[i], dp[i-c[j]]+1)
r = []
while n:
    i = max((i for i in a if n>=c[i]), key=lambda x: dp[n-c[x]])
    r.append(i)
    n -= c[i]
print(''.join(map(str, r)))

Fixed submission:
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(2, n+1):
    for j in a:
        if i >= c[j]:
            dp[i] = max(dp[i], dp[i-c[j]]+1)
r = []
while n:
    i = max((i for i in a if n>=c[i]), key=lambda x: dp[n-c[x]])
    r.append(i)
    n -= c[i]
print(''.join(map(str, r)))

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
dp = {0: 0}
def dfs(n):
    if n < 0:
        return -float('inf')
    if n not in dp:
        dp[n] = max(dfs(n-c[i]) for i in a) + 1      
    return dp[n]
r = []
while n:
    i = max(a, key=lambda x: dfs(n-c[x]))
    r.append(i)
    n -= c[i]
print(''.join(map(str, r)))

Fixed submission:
n, m = map(int,input().split())
a = sorted(map(int,input().split()))[::-1]
c = [0,2,5,5,4,5,6,3,7,6]
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(2, n+1):
    for j in a:
        if i >= c[j]:
            dp[i] = max(dp[i], dp[i-c[j]]+1)
r = []
while n:
    i = max((i for i in a if n>=c[i]), key=lambda x: dp[n-c[x]])
    r.append(i)
    n -= c[i]
print(''.join(map(str, r)))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted(map(int, input().split())) + [10**6]
y = sorted(((i,j) for i in range(m) for j in (i-1,i+1)),
        key=lambda t: abs(x[t[0]]-x[t[1]]))[::-1]
r = 0
v = set()
for _ in range(m-n):
    while True:
        i, j = y.pop()
        if j not in v:
            break
    v |= {i,j}
    r += abs(x[i]-x[j])
print(r)

Fixed submission:
n, m = map(int, input().split())
x = sorted(map(int, input().split()))
d = sorted(abs(x[i]-x[i+1]) for i in range(m-1))
print(sum(d[:max(0, m-n)]))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
dt = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1]
r = v = 0
a = []
s = set()
for i, (d,t) in enumerate(dt, 1):
    if t in s:
        if i <= k:
            a.append(d)
            v += d
    else:
        if i > k:
            v -= a.pop()
            if not a:
                break
        v += d
        s.add(t)
    r = max(r, len(s)**2+v)
print(r)

Fixed submission:
from collections import *
n, k = map(int, input().split())
d, t = zip(*sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1])
c = Counter(t[:k])
x = len(c)
a = [sum(d[:k])]
for i in range(k)[::-1]:
    if c[t[i]] > 1:
        c[t[i]] -= 1
        a.append(a[-1] - d[i])
b = [0]
for i in range(k, n):
    if c[t[i]] <= 0:
        c[t[i]] += 1
        b.append(b[-1] + d[i])
r = 0
for i, (v, w) in enumerate(zip(a, b)):
    r = max(r, v+w+(x+i)**2)
print(r)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
dt = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1]
r = v = 0
a = []
s = set()
for i, (d,t) in enumerate(dt, 1):
    if t in s:
        if i <= k:
            a.append(d)
            v += d
    else:
        if i > k:
            v -= a.pop()
        v += d
        s.add(t)
    r = max(r, len(s)**2+v)
print(r)

Fixed submission:
from collections import *
n, k = map(int, input().split())
d, t = zip(*sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1])
c = Counter(t[:k])
x = len(c)
a = [sum(d[:k])]
for i in range(k)[::-1]:
    if c[t[i]] > 1:
        c[t[i]] -= 1
        a.append(a[-1] - d[i])
b = [0]
for i in range(k, n):
    if c[t[i]] <= 0:
        c[t[i]] += 1
        b.append(b[-1] + d[i])
r = 0
for i, (v, w) in enumerate(zip(a, b)):
    r = max(r, v+w+(x+i)**2)
print(r)
Buggy python submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
a = [0]*(w-1) + [1]
for i in range(w-1):
    a[i] = a[i-1] + a[i-2]
dp = [0]*(w+1)
tmp = [0]*(w+1)
dp[0] = 1
for _ in range(1, h+1):
    for i in range(w):
        tmp[i] = (dp[i]*a[i-1]*a[w-i-2]
            + dp[i+1]*a[i-1]*a[w-i-3]
            + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)
    dp, tmp = tmp, dp
print(dp[k-1])

Fixed submission:
m = 10**9+7
h, w, k = map(int, input().split())
a = [0]*(w-1) + [1]
for i in range(w-1):
    a[i] = a[i-1] + a[i-2]
dp = [0]*w
tmp = [0]*w
dp[0] = 1
for _ in range(1, h+1):
    for i in range(w):
        tmp[i] = dp[i]*a[i-1]*a[w-i-2]
        if i != w-1:
            tmp[i] += dp[i+1]*a[i-1]*a[w-i-3]
        if i != 0:
            tmp[i] += dp[i-1]*a[i-2]*a[w-i-2]
        tmp[i] %= m
    dp, tmp = tmp, dp
print(dp[k-1])

Buggy python submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
a = [0]*(w-1) + [1]
for i in range(w-1):
    a[i] = a[i-1] + a[i-2]
dp = [0]*(w+1)
tmp = [0]*(w+1)
dp[0] = 1
for _ in range(1, h+1):
    for i in range(w):
        tmp[i] = (dp[i]*a[i-1]*a[w-i-2]
            + dp[i+1]*a[i-1]*a[w-i-3]
            + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)
        tmp[i] %= m
    dp, tmp = tmp, dp
print(dp[k-1])

Fixed submission:
m = 10**9+7
h, w, k = map(int, input().split())
a = [0]*(w-1) + [1]
for i in range(w-1):
    a[i] = a[i-1] + a[i-2]
dp = [0]*w
tmp = [0]*w
dp[0] = 1
for _ in range(1, h+1):
    for i in range(w):
        tmp[i] = dp[i]*a[i-1]*a[w-i-2]
        if i != w-1:
            tmp[i] += dp[i+1]*a[i-1]*a[w-i-3]
        if i != 0:
            tmp[i] += dp[i-1]*a[i-2]*a[w-i-2]
        tmp[i] %= m
    dp, tmp = tmp, dp
print(dp[k-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
for i in range(1, min(m//n, int(m**0.5))+1)[::-1]:
    if m%i == 0:
        print(max(m//i, i)
        break

Fixed submission:
n, m = map(int, input().split())
r = 1
for i in range(1, int(m**0.5)+1)[::-1]:
    if i<=m//n and m%i==0:
        if m//i<=m//n:
            r = max(r, m//i)
        else:
            r = max(r, i)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
for i in range(1, m//n+1)[::-1]:
    if m%i == 0:
        print(i)
        break

Fixed submission:
n, m = map(int, input().split())
r = 1
for i in range(1, int(m**0.5)+1)[::-1]:
    if i<=m//n and m%i==0:
        if m//i<=m//n:
            r = max(r, m//i)
        else:
            r = max(r, i)
print(r)
Buggy python submission (verdict: Runtime Error):
import fractions
N, X = map(int, input().split())
x = map(int, input().split())
r = abs(X-next(x))
for i in x:
    r = fractions.gcd(r, i-X))
print(r)

Fixed submission:
import fractions
N, X = map(int, input().split())
x = map(int, input().split())
r = abs(next(x)-X)
for i in x:
    r = fractions.gcd(r, abs(i-X))
print(r)

Buggy python submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
x = map(int, input().split())
r = next(x)-X
for i in x:
    r = math.gcd(r, i-X)
print(r)

Fixed submission:
import fractions
N, X = map(int, input().split())
x = map(int, input().split())
r = abs(next(x)-X)
for i in x:
    r = fractions.gcd(r, abs(i-X))
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
m = 10**9+7
n = 1
a = ab = abc = 0
for c in input():
    if c == 'A':
        a += n
    elif c == 'B':
        ab += a
    elif c == 'C':
        abc += ab
    else:
        ta, tab = a, ab
        a *= 3
        ab *= 3
        abc *= 3
        a += n
        ab += ta
        abc += tab
        n *= 3
    a %= m
    ab %= m
    abc %= m
print(abc)


Fixed submission:
m = 10**9+7
n = 1
a = ab = abc = 0
for c in input():
    if c == 'A':
        a += n
    elif c == 'B':
        ab += a
    elif c == 'C':
        abc += ab
    else:
        ta, tab = a, ab
        a *= 3
        ab *= 3
        abc *= 3
        a += n
        ab += ta
        abc += tab
        n *= 3
    a %= m
    ab %= m
    abc %= m
    n %= m
print(abc)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

l, r = a[:2]
m = 1
b = [(l,r)]
for i in range(2, n-2):
    r += a[i]
    for j in range(m, i):
        nl, nr = l+a[j], r-a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m += 1
    b.append((l,r))

l, r = a[-2:]
m = n-2
c = [(l,r)]
for i in range(2, n-2)[::-1]:
    l += a[i]
    for j in range(i+1, m+1)[::-1]:
        nl, nr = l-a[j], r+a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m -= 1
    c.append((l,r))

r = 10**9
for i in range(n-3):
    x = max(*b[i], *c[-i-1])
    y = min(*b[i], *c[-i-1])
    r = min(r, x-y)
print(r,flush=True)

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

l, r = a[:2]
m = 1
b = [(l,r)]
for i in range(2, n-2):
    r += a[i]
    for j in range(m, i):
        nl, nr = l+a[j], r-a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m += 1
    b.append((l,r))

l, r = a[-2:]
m = n-2
c = [(l,r)]
for i in range(2, n-2)[::-1]:
    l += a[i]
    for j in range(i+1, m+1)[::-1]:
        nl, nr = l-a[j], r+a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m -= 1
    c.append((l,r))

r = 10**9
for i in range(n-3):
    x = max(b[i]+c[-i-1])
    y = min(b[i]+c[-i-1])
    r = min(r, x-y)
print(r)

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

l, r = a[:2]
m = 1
b = [(l,r)]
for i in range(2, n-2):
    r += a[i]
    for j in range(m, i):
        nl, nr = l+a[j], r-a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m = j
    else:
        m += 1
    b.append((l,r))

l, r = a[-2:]
m = n-2
c = [(l,r)]
for i in range(2, n-2)[::-1]:
    l += a[i]
    for j in range(i+1, m+1)[::-1]:
        nl, nr = l-a[j], r+a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m = j
    else:
        m -= 1
    c.append((l,r))

r = 10**9
for i in range(n-4):
    x = max(*b[i], *c[-i-1])
    y = min(*b[i], *c[-i-1])
    r = min(r, x-y)

print(r)

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

l, r = a[:2]
m = 1
b = [(l,r)]
for i in range(2, n-2):
    r += a[i]
    for j in range(m, i):
        nl, nr = l+a[j], r-a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m += 1
    b.append((l,r))

l, r = a[-2:]
m = n-2
c = [(l,r)]
for i in range(2, n-2)[::-1]:
    l += a[i]
    for j in range(i+1, m+1)[::-1]:
        nl, nr = l-a[j], r+a[j]
        if abs(l-r) < abs(nl-nr): 
            break
        l, r = nl, nr
        m -= 1
    c.append((l,r))

r = 10**9
for i in range(n-3):
    x = max(b[i]+c[-i-1])
    y = min(b[i]+c[-i-1])
    r = min(r, x-y)
print(r)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
i = max(a)
a.remove(i)
k = min(a, key=lambda x: abs(i-x*2))
print(i, j)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
i = max(a)
a.remove(i)
j = min(a, key=lambda x: abs(i/2-x))
print(i, j)
Buggy python submission (verdict: Runtime Error):
def f(m, s, g):
    v, t = {s}, set()
    for i in m:
        for j in v:
            t.update((j+i, j-i))
        v, t = t, set()
    return g in v
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
if f(m[::2][1::], m[0], x) and f(m[1::2], 0, y):
    print('Yes')
else:
    print('No')

Fixed submission:
def f(m, s, g):
    v, t = {s}, set()
    for i in m:
        for j in v:
            t.update((j+i, j-i))
        v, t = t, set()
    return g in v
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
if f(m[::2][1::], m[0], x) and f(m[1::2], 0, y):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a,_b=input()
if a==b:
  print("YES")
else:
  print("No")

Fixed submission:
a,_,b=input()
if a==b:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a,_b=input()
if a==b:
  print("YES")
else:
  print("No")

Fixed submission:
a,_,b=input()
if a==b:
  print("Yes")
else:
  print("No")