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

Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
# N = 6
# A = sorted([int(i) for i in '3 14 159 2 6 53'.split()])
# B = sorted([int(i) for i in '58 9 79 323 84 6'.split()])
# C = sorted([int(i) for i in '2643 383 2 79 50 288'.split()])
res = 0
for b in B:
    res += bisect_left(A, b) * (N -bisect_right(C, b))
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]res = 0
cnt_a = 0
cnt_c = 0
for b in B:
    for ca in range(cnt_a, N):
        if A[ca] >= b:
            cnt_a = ca
            break
        if ca == N-1:
            if A[ca] < b:
                ca = N
                cnt_a = N
                break

    for cc in range(cnt_c, N):
        if C[cc] > b:
            cnt_c = cc
            break
        if cc == N-1:
            if b > C[cc]:
                cc = N
                cnt_c = N
                break
    res += (N - cc) * ca
print(res)
Problem p03607 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 05:13:17 2018

@author: Yuki
"""

import collections

N = int(input())

A = [int(input()) for i in range(N)]

A_dict = collections.Counter(A)

cnt = 0
for val in A_dict.values():
    if val%2==1:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 05:13:17 2018

@author: Yuki
"""

import collections

N = int(input())

A = [int(input()) for i in range(N)]

A_dict = collections.Counter(A)

cnt = 0
for val in A_dict.values:
    if val%2==1:
        cnt += 1
print(cnt)
Problem p03625 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
A_dict = defaultdict(lambda:0)
for a in A:
    A_dict[a] += 1
key1 = 0
key2 = 0
for key in sorted(A_dict.keys(), reverse=True):
    if key2 > 0:
        break

    if A_dict[key] > 3:
        if key1 == 0:
            key1 = key
        if key2 == 0:
            key2 = key
    elif A_dict[key] > 1:
        if key1 > 0:
            key2 = key
        else:
            key1 = key
print(key1*key2)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
A_dict = defaultdict(lambda:0)
for a in A:
    A_dict[a] += 1
key1 = 0
key2 = 0
for key in A_dict.keys():
    if key2 > 0:
        break

    if A_dict[key] > 3:
        if key1 == 0;
            key1 = key
        if key2 == 0;
            key2 = key
    elif A_dict[key] > 1:
        if key1 > 0:
            key2 = key
        else:
            key1 = key
print(key1*key2)
Problem p03659 (python)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
res = []
for i in range(N-1):
    deltas.append(deltas[-1] - 2*A[i])
    res.append(abs(deltas[-1]))
print(min(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
    snk = sum(A[:i])
    arg = sum(A[i:])
    res.append(abs(snk-arg))
print(min(res))
Problem p03681 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
mod = 1000000000 + 7
def func(n):
    r = 1
    for i in range(1, n+1):
        r *= i
        r %= mod

    return r
N, M = map(int, input().split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    print(int((func(A)*func(A-1))%mod))
else:
    print(int(2*func(N)*func(N))%mod)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
mod = 1000000000 + 7
def func(n):
    r = 1
    for i in range(1, n+1):
        r *= i
        r %= mod
    return r

N, M = map(int, input().1split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    res = func(A)
    print(int(res**2/A)%mod)
else:
    print(int(2*func(N)**2)%mod)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
import sys
sys.setrecursionlimit(100001)
def func(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n*func(n-1)

N, M = map(int, input().split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    res = func(A)
    print(int(res**2/A))
else:
    print(int(2*func(N)**2))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
def func(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n*func(n-1)

N, M = map(int, input().split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    res = func(A)
    print(int(res**2/A))
else:
    print(2*func(N))
Problem p02743 (python)

Fixed submission:
import decimal
import math
a, b, c = map(int, input().split())

d = c - a - b

if d > 0 and d * d > 4 * a * b:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
 import decimal
import math
a, b, c = map(int, input().split())

if  decimal.Decimal(math.sqrt(c)) - decimal.Decimal(math.sqrt(a)) + decimal.Decimal(math.sqrt(b)) > 0:
    print("Yes")
else:
    print("No")
Problem p02813 (python)

Fixed submission:
import itertools
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

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

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))
Problem p02861 (python)

Fixed submission:
import math
import itertools

n = int(input())
x, y = [0]*n, [0]*n
for i in range(n):
    a, b = map(int, input().split())
    x[i], y[i] = a, b
l = list(itertools.permutations(range(n)))

tmp = 0
for p in l:
    for j in range(n-1):
        a = p[j]
        b = p[j+1]
        tmp += math.sqrt((x[a]-x[b])**2 + (y[a]-y[b])**2)

print(round(tmp/len(l), 10))

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))

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

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))
Problem p02936 (python)

Fixed submission:
import sys
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数求めたい
from math import ceil, floor, sqrt #小数点切り上げ、切り捨て、平方根求めたい
from copy import deepcopy #参照で影響されないコピーが作られる
from collections import Counter, deque #要素ごとの出現回数を数える。双方向アクセス可能データ型
import heapq
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n,q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
    a,b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(q):
    p,x = map(int, input().split())
    o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
    p = todo.pop(-1)
    ct[p] += o[p]
    seen[p] = True
    for i in g[p]:
        if seen[i]:
            ct[p] += ct[i]
        else:
            todo.append(i)

print(*ct[1:])

Buggy submission (verdict: Runtime Error):
vimport sys 
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def dfs(v, pv):
    # global P

    for nv in G[v]:
        if nv != pv:
            P[nv] += P[v]
            dfs(nv, v)

n,q = map(int, input().split())
G = [[] for _ in range(n)]              # adjacent list
for i in range(n-1):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

P = [0]*n                               # add list
for i in range(q):
    p,x = map(int, input().split())
    P[p-1] += x


dfs(0, 0)
print(*P)
Problem p03061 (python)

Fixed submission:
import fractions

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

def gcd(a,b):
    return fractions.gcd(a,b)

x = [0]
y = [0]

for i in range(n):
    x.append(gcd(x[i], a[i]))
    y.append(gcd(y[i], a[-(i+1)]))

y.reverse()

ans = []
for i in range(n):
    ans.append(gcd(x[i], y[i+1]))

print(max(ans))

Buggy submission (verdict: Runtime Error):
import math

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

def gcd(a,b):
    return math.gcd(a,b)

x = [0]
y = [0]

for i in range(n):
    x.append(gcd(x[i], a[i]))
    y.append(gcd(y[i], a[-(i+1)]))

y.reverse()

ans = []
for i in range(n):
    ans.append(gcd(x[i], y[i+1]))

print(max(ans))
Problem p03164 (python)

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

import numpy as np 

dp = np.full(1000*n+1, w+1, dtype=int)

dp[0] = 0

for i in range(n):
    weight, value = map(int, input().split())
    dp[value:] = np.minimum(dp[value:], dp[:-value] + weight)

print(np.max(np.where(dp <= w)))

Buggy submission (verdict: Runtime Error):
import numpy as np  

n, w = map(int, input().split())
dp = np.full(n*1000+1, float('inf'))
dp[0] = 0

for _ in range(n):
    weight, value = map(int, input().split())
    dp[:value] = np.minimum(dp[:value], dp[:-value] + weight) 

print(dp[-1])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int, input().split())

g = [[] for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]

    tmp = 0
    for j in g[i]:
        tmp = max(tmp, dfs(j) + 1)

    dp[i] = tmp
    return tmp

for i in range(n):
    dfs(i)

print(max(dp))

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

g = [[] for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]

    tmp = 0
    for j in g[i]:
        tmp = max(tmp, dfs(j) + 1)

    dp[i] = tmp
    return tmp

for i in range(n):
    dfs(i)

print(max(dp))

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

g = [[] for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]

    tmp = 0
    for j in g[i]:
        tmp = max(tmp, dfs(j) + 1)

    dp[i] = tmp
    return tmp

for i in range(n):
    dfs(i)

print(max(dp))

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

g = [[] for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]

    tmp = 1e9
    for j in g[i]:
        tmp = min(tmp, dfs(j) + 1)

    dp[i] = tmp
    return tmp

for i in range(n):
    dfs(i)

print(min(dp))
Problem p03281 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1, 2):
  tmp = 0
  for j in range(1, N+1):
    if i % j == 0:
      tmp += 1
  if tmp == 8:
    ans += 1
print(ans)

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

ans = 0
for i in range(1, n+1, 2):
    tmp = 0
    for j in range(1, (n+1)/2):
        if i % j == 0:
            tmp += 1

    if tmp == 4:
        ans += 1

print(ans)

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

ans = 0
for i in range(1, n+1, 2):
    tmp = 0
    for j in range(1, n/2):
        if i % j == 0:
            tmp += 1

    if tmp == 4:
        ans += 1

print(ans)

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

ans = 0
for i in range(1, n+1, 2):
    tmp = 0
    for j in range(1, n/2):
        if i % j == 0:
            tmp += 1

    if tmp == 8:
        ans += 1

print(ans)

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

ans = 0
for i in range(1, n+1):
    tmp = 0
    for j in range(1, i/2+1):
        if i % j == 0:
            tep += 1

    if tmp == 8:
        ans += 1

print(ans)

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

ans = 0
for i in range(1, n+1):
    tmp = 0
    for j in range(1, i/2+1):
        if n % j == 0:
            tep += 1

    if tmp == 8:
        ans += 1

print(ans)
Problem p02702 (python)

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 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
Problem p02902 (python)

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 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)

Buggy 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)
Problem p03062 (python)

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 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)
Problem p03128 (python)

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 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]))

Buggy 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)))

Buggy 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)))
Problem p03148 (python)

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 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)

Buggy 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)
Problem p03241 (python)

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 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
Problem p03262 (python)

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 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)

Buggy 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)
Problem p03312 (python)

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 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)

Buggy 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)
Problem p03382 (python)

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 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)
Problem p03490 (python)

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 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')