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

Fixed submission:
#PythonだとTLEする
N, K = map(int, input().split())
X = [0] * N
Y = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    X[i] = x
    Y[i] = y

def count(x_min, x_max, y_min, y_max):
    cnt = 0
    for i in range(N):
        if x_min <= X[i] <= x_max and y_min <= Y[i] <= y_max:
            cnt += 1
    return cnt

ans = 10 ** 20
for i in range(N):
    for j in range(N):
        for k in range(N):
            for l in range(N):
                # print ('i, j , k, l = ', i, j, k, l)
                if X[i] < X[j] and Y[k] < Y[l]:
                    if count(X[i], X[j], Y[k], Y[l]) >= K:
                        # print ('A')
                        ans = min(ans, (X[j] - X[i]) * (Y[l] - Y[k]))
print (ans)

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    XY = [tuple(map(int, input().split())) for _ in range(N)]
    XY.sort()
    XY = tuple(XY)

    def count(x_min, x_max, y_min, y_max, i, j):
        OK = 0
        # NG = 0
        a = j - i + 1 - K
        for m in XY[i:j + 1]:
            if y_min <= m[1] <= y_max:
                OK += 1
        if OK >= K:
            return True
        return False

    ans = 10 ** 20
    for i, val in enumerate(A[:N - 1]):
        a = val[0]
        for j in range(i + K - 1, N):
            b = XY[j][0]
            e = b - a
            for k in range(N):
                c = XY[k][1]
                for l in range(N):
                    d = XY[l][1]
                    if c < d:
                        if count(a, b, c, d, i, j):
                            # print ('A')
                            ans = min(ans, e * (d - c))
    print (ans)
    return

if __name__ == '__main__':
    main()
Problem p03578 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

dic = defaultdict(int)
for d in D:
    dic[d] += 1

for t in T:
    if dic[t]:
        dic[t] -= 1
    else:
        print ('NO')
        exit()

print ('YES')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
D = list(map(int, input()))
M = int(input())
T = list(map(int, input().split()))

dic = defaultdict(int)
for d in D:
    dic[d] += 1

for t in T:
    if dic[t]:
        dic[t] -= 1
    else:
        print ('No')
        exit()

print ('Yes')
Problem p03597 (python)

Fixed submission:
N = int(input())
A = int(input())
print (N * N -A)

Buggy submission (verdict: Runtime Error):
import sys
A, B, C, D, E, F = map(int, input().split())


def concentration(water, suger):
    if water * E/100 < suger or water + suger == 0:
        return 0
    return (100 * suger/(water + suger))

lst_w = []
limit_w = (F+A*100-1)//(A*100)
for i in range(limit_w):
    for j in range(limit_w):
        if 100 * (A * i + B * j) <= F:
            lst_w += [100 * (A * i + B * j)]

lst_s = []
limit_s = (F+C-1)//C
for i in range(limit_s):
    for j in range(limit_s):
        if C* i + D * j <= F:
            lst_s += [C * i + D * j]

# print (lst_w)
# print (lst_s)
set_w = set(lst_w)
set_s = set(lst_s)

# print (set_w)
# print (set_s)

ans = 0
ans_total = 0
ans_suger = 0
for water in set_w:
    for suger in set_s:
        if water + suger <= F:
            a = concentration(water, suger)
            if ans < a:
                ans = a
                ans_total = water + suger
                ans_suger = suger
            if ans == 50:
                print (ans_total, ans_suger)
                sys.exit()

if ans = 0:
    print (set_w[1], 0)
else:
    print (ans_total, ans_suger)

# print (ans)
Problem p03623 (python)

Fixed submission:
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print ('A')
else:
  print ('B')

Buggy submission (verdict: Runtime Error):
X, A, B = map(int, input().split())

if min(abs(X - A) < abs(X - B)):
    print ('A')
else:
    print ('B')
Problem p03624 (python)

Fixed submission:
S = list(input())
s = set(S)
S = list(s)
S.sort()
if len(S) == 26:
    print (None)
else:
    tmp = 0
    for i in 'abcdefghijklmnopqrstuvwxyz':
        if tmp >= len(S):
            print (i)
            break
        if i == S[tmp]:
            tmp += 1
        else:
            print (i)
            break

Buggy submission (verdict: Runtime Error):
S = list(input())
s = set(S)
S = list(s)
S.sort()
if len(S) == 26:
    print (None)
else:
    tmp = 0
    for i in 'abcdefghijklmnopqrstuvwxyz':
        if i == S[tmp]:
            tmp += 1
        else:
            print (i)
            break
Problem p03633 (python)

Fixed submission:
N = int(input())

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


T1 = int(input())
ans = T1
for i in range(N-1):
    T2 = int(input())
    ans = T1 * T2 //gcd(T1, T2)
    T1 = ans

print (ans)

# print (gcd(12, 8))

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

N = int(input())

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

print (ans)

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

N = int(input())

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

print (ans)
Problem p03651 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

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

n = A[0]
for i in A:
    n = gcd(n, i)

flag = False
for i in A:
    if i >= K and (i - K) % n == 0:
        flag = True
        break
    else:
        pass

if flag:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

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

N = int(input())
A = list(map(int, input().split()))

M = max(A)

g = A[0]
for a in A:
    g = gcd(g, a)

if K <= M and K % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

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

N = int(input())
A = list(map(int, input().split()))

M = max(A)

g = A[0]
for a in A:
    g = gcd(g, a)

if K <= M and K % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')
Problem p03687 (python)

Fixed submission:
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)

Buggy submission (verdict: Runtime Error):
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

    ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)
Problem p03695 (python)

Fixed submission:
N = int(input())

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

lst = [0] * 9

for i in range(N):
    lst[min(a[i]//400, 8)] += 1

count = lst[:8].count(0)

kind_max = min(8-count+lst[8], 100)
kind_min = max(8-count,1)

print (kind_min, kind_max)

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

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

lst = [0] * 9

for i in range(N):
    lst[min(a[i]//400, 8)] += 1

count = lst[:8].count(0)

kind_max = min(8-count+lst[8])
kind_min = max(8-count,1)

print (kind_min, kind_max)
Problem p03746 (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)
    G[B].append(A)

check = [0] * (N + 1)
check[1] = 1
ans1 = [1]
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans1.append(next_)
           break

# print (ans1)

ans2 = []
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans2.append(next_)
           break

# print (ans2)

print (len(ans1) + len(ans2))
print (*ans2[::-1], end ='')
if len(ans1):
    print (' ', end = '')
else:
    print ()
print (*ans1)

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].append(B)
    G[B].append(A)

check = [0] * (N + 1)
check[1] = 1
ans1 = [1]
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans1.append(next_)
           break

# print (ans1)

ans2 = []
stack = [1]
while stack:
    tmp = stack.pop()
    for next_ in G[tmp]:
        if check[next_] == 1:
            continue
        else:
           stack.append(next_)
           check[next_] = 1
           ans2.append(next_)
           break

# print (ans2)

print (len(ans1) + len(ans2))
print (*ans2[::-1], *ans1)
Problem p03759 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

if (b - a == c - b):
    print ('YES')
else:
    print ('NO')

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

# 前計算
for i in range(n - 1):
    x[i] = x[i + 1] - x[i]

for i in range(m - 1):
    y[i] = y[i + 1] - y[i]

N = [n - 1]
for i in range(n - 3, 0, -2):
    N.append(N[-1] + i)
    # N.append((N[i] + (n - 1 - 2 * (i + 1))) % MOD)

M = [m - 1]
for i in range(m - 3, 0, -2):
    M.append(M[-1] + i)
    # M.append((M[i] + (m - 1- 2 * (i + 1))) % MOD)

if N[0] % 2 == 0:
    N += N[::-1]
elif N[0] != 1:
    N += N[1::-1]

if M[0] % 2 == 0:
    M += M[::-1]
elif M[0] != 1:
    M += M[1::-1]

# print (x)
# print (y)
# print (N)
# print (M)

if len(x) - 1 > len(N):
    while True:
        pass

if len(y) - 1 > len(M):
    while True:
        pass


X_sum = 0
for i in range(n - 1):
    X_sum += x[i] * N[i]
    X_sum %= MOD

Y_sum = 0
for i in range(m - 1):
    Y_sum += y[i] * M[i]
    Y_sum %= MOD

print ((X_sum * Y_sum) % MOD)
Problem p03815 (python)

Fixed submission:
x = int(input())
ans = (x//11) * 2
if x%11 == 0:
    ans = ans
elif x%11 <= 6:
    ans += 1
else:
    ans += 2

print (ans)

Buggy submission (verdict: Runtime Error):
x = int(input())
ans = (x//11) * 2
if x%11 <= 6:
    ans += 1
elif x% == 0:
    ans = ans
else:
    ans += 2

print (ans)
Problem p03836 (python)

Fixed submission:
sx, sy, tx, ty = map(int, input().split())

x = tx - sx
y = ty - sy

s = 'U'*y + 'R'*x +'U' + 'L'* (x+1) + 'D'*(y+1) + 'R'
s += 'R'*x + 'U'*y +'R' + 'D'* (y+1) + 'L'*(x+1) + 'U'
print(s)

Buggy submission (verdict: Runtime Error):
K, S = map(int, input().split())

count = 0
for x in range(0,K+1):
    for y in range(0,K+1):
        a = S-x-y
        if a <= K and a>= 0:
            count += 1
print (count)
Problem p03854 (python)

Fixed submission:
import numpy as np
import sys
sys.setrecursionlimit(10 **9)
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')

Buggy submission (verdict: Runtime Error):
import numpy as np
S = str(input())
A = ['dream', 'dreamer', 'erase', 'eraseer']

N = len(S)
i = 0

def check(i): #i最初の文字
    flag0 = False
    flag1 = False
    flag2 = False
    flag3 = False
    flag4 = False
    flag5 = False
    if S[i:] == 'dream' or S[i:] == 'dreamer' or S[i:] == 'erase' or S[i:] == 'eraser':
        flag1 = True
    if S[i:i+7] == 'dreamer':
        flag2 = check(i+7)
    if S[i:i+5] == 'dream':
        flag3 =  check(i+5)
    if S[i:i+6] == 'eraser':
        flag4 =  check(i+6)
    if S[i:i+5] == 'erase':
        flag5 = check(i+5)
    return flag0 or flag1 or flag2 or flag3 or flag4 or flag5

if check(0):
    print ('YES')
else:
    print ('NO')
Problem p04011 (python)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

ans = X * min(K, N) + Y * max(N-K, 0)

print (ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, A = map(int, input().split())
x = list(map(int, input().split()))

X = max(x)
if X < A:
    X = A

def check(j, k, s):
    if dp[j][k][s] != -1:
        return dp[j][k][s]
    if j == 0 and k == 0 and s == 0:
        dp[j][k][s] = 1
        return 1
    if j >= 1 and s < x[j-1]:
        a = check(j-1, k ,s)
        dp[j][k][s] = a
        return a
    if j >= 1 and k >= 1 and s >= x[j-1]:
        a = check(j-1, k, s) + check(j-1, k-1, s-x[j-1])
        dp[j][k][s] = a
        return a
    dp[j][k][s] = 0
    return 0
        
dp = [[[-1] * (N*X+1) for _ in range(N+1)] for _ in range(N + 1)]
dp = np.array(dp)
# print (dp)
# for j in range(N+1):
#     for k in range(N+1):
#         for s in range(N*X + 1):
#             print (j, k, s)
#             dp[j][k][s] = check(j, k, s)

ans = 0
for k in range(1, N+1):
    ans += check(N, k, k * A)
    # ans += dp[N][k][k * A]

print (ans)
Problem p04014 (python)

Fixed submission:
import math
import sys
sys.setrecursionlimit(10**5)
n = int(input())
s = int(input())

if n < s:
    print (-1)
    exit()

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(int(math.sqrt(n))+1, 0, -1):
    b = (n-s)//p + 1
    if b != 1 and f(b, n) == s:
        print (b)
        exit()
print (-1)

# for i in range(2, 100):
#     print (i, f(i,100))

Buggy submission (verdict: Runtime Error):
import math
import sys
sys.setrecursionlimit(10**5)
n = int(input())
s = int(input())

if n < s:
    print (-1)
    exit()

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(int(math.sqrt(n))+1, 0, -1):
    b = (n-s)//p + 1
    if f(b, n) == s:
        print (b)
        exit()
print (-1)

# for i in range(2, 100):
#     print (i, f(i,100))

Buggy submission (verdict: Runtime Error):
import math
import sys
sys.setrecursionlimit(10**5)
n = int(input())
s = int(input())

if n < s:
    print (-1)
    exit()

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(1, int(math.sqrt(n))+2):
    b = (n-s)//p + 1
    if f(b, n) == s:
        print (b)
        exit()
print (-1)

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

if n < s:
    print (-1)
    exit()

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(1, int(math.sqrt(n))+2):
    b = (n-s)//p + 1
    if f(b, n) == s:
        print (b)
        exit()
print (-1)

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

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if s == n:
    print (n+1)
    exit()

if n == 1:
    print (-1)
    exit()

for i in range(2, int(math.sqrt(n))+2):
    if f(i, n) == s:
        print (i)
        exit()

for p in range(1, int(math.sqrt(n))+2):
    b = (n-s)//p + 1
    if f(b, n) == s:
        print (b)
        exit()
print (-1)
Problem p04047 (python)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    ans += L[2 * i]

print (ans)

Buggy submission (verdict: Runtime Error):
#座標平面に落とし込んで再帰関数で無理やり計算
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5)
N, X = map(int, input().split())
if 2 * X > N: #対称性
    X = N - X

#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
    tmp = [-1]
    for j in range(N+1):
        if i <= j:
            tmp.append(0) #到達していないマス
        else:
            tmp.append(-1) #壁(範囲外)
    tmp.append(-1)
    tmp.reverse()
    dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))


#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
    if x == X and y == 1 and dp[x][y] == 1: #一周回ってもとの座標に戻ってきた時
        # print ('D')
        return total
    if m == 0: #右に動く時
        tmp = 0
        while dp[x-1][y+1] == 0: #右に進める時
            dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
            tmp += 1
            x -= 1
            y += 1
        if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
            # print ('1-B')
            return moving(x, y, total + tmp, 1)
        if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
            tmp += 1
            # print ('1-C')
            return moving(x-1, y+1, total + tmp, 2)
    
    if m == 1: #左下へ動く時
        tmp = 0
        while dp[x+1][y] == 0: #左下に進める時
            dp[x+1][y] = 1
            tmp += 1
            x += 1
        if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
            # print ('2-C')
            return moving(x, y, total + tmp, 2)
        if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
            tmp += 1
            # print ('2-C')
            return moving(x+1, y, total + tmp, 2)
    
    if m == 2: #左上に動く時
        tmp = 0
        while dp[x][y-1] == 0: #左上に進める時
            dp[x][y-1] = 1
            tmp += 1
            y -= 1
        if dp[x][y-1] == -1: #左上が壁の時-->右に進む
            # print ('3-A')
            return moving(x, y, total + tmp, 0)
        if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
            tmp += 1
            # print ('3-B')
            return moving(x, y-1, total + tmp, 1)

X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp))
Problem p03026 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

n = int(input())

graph = [[] for i in range(n)]
edge_cnt = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    edge_cnt[a-1] += 1
    edge_cnt[b-1] += 1


c = list(map(int, input().split()))
c.sort()

v = 0
for i in range(n):
    if edge_cnt[i] == 1:
        v = i
        break

nodes = [0] * n
total_score = -c[-1]


def dfs(v):
    global total_score
    if nodes[v] > 0:
        return
    nodes[v] = c.pop()
    total_score += nodes[v]
    for nv in graph[v]:
        if nodes[nv] > 0:
            continue
        dfs(nv)


dfs(v)
print(total_score)
print(*nodes, sep=' ')

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

graph = [[] for i in range(n)]
edge_cnt = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    edge_cnt[a-1] += 1
    edge_cnt[b-1] += 1


c = list(map(int, input().split()))
c.sort()

v = 0
for i in range(n):
    if edge_cnt[i] == 1:
        v = i
        break

nodes = [0] * n
total_score = -c[-1]


def dfs(v):
    global total_score
    if nodes[v] > 0:
        return
    nodes[v] = c.pop()
    total_score += nodes[v]
    for nv in graph[v]:
        if nodes[nv] > 0:
            continue
        dfs(nv)


dfs(v)
print(total_score)
print(*nodes, sep=' ')
Problem p03032 (python)

Fixed submission:
import heapq

n, k = map(int, input().split())
vs = list(map(int, input().split()))

max_v = -float('inf')
for a in range(min(k, n)+1):
    total = 0
    minus = []
    for i in range(a):
        total += vs[i]
        if vs[i] < 0:
            heapq.heappush(minus, vs[i])
    max_v = max(max_v, total)
    for b in range(min(k-a, n-a)+1):
        c = k - a - b
        if c < 0:
            break
        h = minus[:]
        t = total
        for i in range(b):
            t += vs[n-1-i]
            if vs[n-1-i] < 0:
                heapq.heappush(h, vs[n-1-i])
        for i in range(c):
            if h:
                v = heapq.heappop(h)
                t -= v
            else:
                break
        max_v = max(max_v, t)

print(max_v)

Buggy submission (verdict: Runtime Error):
import heapq

n,k = map(int, input().split())
vs = list(map(int, input().split()))

max_v = -float('inf')
for a in range(max(k,n)):
    total = 0
    minus = []
    for i in range(a):
        total += vs[i]
        if vs[i] < 0:
            heapq.heappush(minus, vs[i])
    for b in range(max(k-a,n-a)):
        c = k - a - b
        if c < 0:
            break
        h = minus[:]
        t = total
        for i in range(b):
            t += vs[n-1-i]
            if vs[n-1-i] < 0:
                heapq.heappush(h, vs[n-1-i])
        for i in range(c):
            if h:
                v = heapq.heappop(h)
                t -= v
        max_v = max(max_v, t)

print(max_v)
Problem p03050 (python)

Fixed submission:
import unittest


def solve(n):
    used = set()
    total = 0
    for i in range(1, int(n ** 0.5)+1):
        if n % i > 0:
            continue
        d = n // i
        cand = [i-1, d-1]
        for c in cand:
            if c not in used and c > 0 and n % c == n // c:
                total += c
                used.add(c)

    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)

Buggy submission (verdict: Runtime Error):
import unittest


def solve_small(n):
    total = 0
    for m in range(1, n):
        if n // m == n % m:
            total += m
    return total


def solve(n):
    conds = set()
    conds.add(n-1)
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            conds.add(i-1)
            conds.add(n // i - 1)
    total = 0
    for m in list(conds):
        if n // m == n % m:
            total += m
    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)
Problem p03071 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(max(a,b) + max(max(a,b)-1, min(a,b))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(max(a,b) + max(max(a,b), min(a,b))