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

Fixed submission:
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N-1):
		if min(lis) % 10 != 0:
			print get - min(lis)
			break
		lis.remove(min(lis))
	else:
		print 0
else:
	print get

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N):
		lis.remove(min(lis))
		if min(lis) % 10 != 0:
			print get - min(lis)
	else:
		print 0
else:
	print get

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
get = sum(lis)
if sum(lis) % 10 == 0:
	for j in range(0,N)
		lis.remove(min(lis))
		if min(lis) % 10 != 0
			print get - min(lis)
else:
	print get

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
lis = []
for i in range(0,N):
	num = int(raw_input())
	lis.append(num)
if sum(lis) % 10 == 0:
	if min(lis) % 10 != 0:
		print sum(lis)-min(lis)
	else:
		print sum(lis)-min(lis.remove(min(lis)))
else:
	print sum(lis)

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
lis = []
for i in range(0,N):
	lis.append(int(raw_input()))
if sum(lis) % 0 == 0:
	print sum(lis)-min(lis)
else:
	print sum(lis)

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
lis = []
for i in N:
	lis.append(int(raw_input()))
if sum(lis) % 0 == 0:
	print sum(lis)-min(lis)
else:
	print sum(lis)
Problem p02683 (python)

Fixed submission:
b0=input().split()
book=int(b0[0])
pro=int(b0[1])
norma=int(b0[2])

bl=[]
for x in range(book):
  bl.append([int(y) for y in input().split()])
  
mn=-1
for x in range(2**book):
  if book>9:
    k=str(book)+"b"
  else:
    k="0"+str(book)+"b"
  x2=format(x, k)
  m=0
  exl=[0 for i in range(pro)]
  for y in range(book):
    if x2[y]=="1":
      m+=bl[y][0]
      for j in range(pro):
        exl[j]+=bl[y][j+1]
  if min(exl)>=norma and (mn==-1 or mn>m):
    mn=m

print(mn)

Buggy submission (verdict: Runtime Error):
b0=input().split()
book=int(b0[0])
pro=int(b0[1])
norma=int(b0[2])

bl=[]
for x in range(book):
  bl.append([int(y) for y in input().split()])
  
def find(n,exl):
  if n==book:
    if min(exl)<norma:
      return -1
    else:
      return 0
  else:
    if min(exl)>=norma:
      return 0
    else:
      newexl=[]
      for i in range(pro):
        newexl.append(exl[i]+bl[n][i+1])
      if min(newexl)>=norma:
        f0=bl[n][0]
      else:
        re=find(n+1,newexl)
        if re==-1:
          f0=-1
        else:
          f0=re+bl[n][0]
      re2=find(n+1,exl)
      if re2==-1:
        f1=-1
      else:
        f1=re2
      if f0==-1 and f1==-1:
        return -1
      elif f0==-1 or f1==-1:
        return max(f0,f1)
      else:
        return min(f0,f1)
      
print(find(0,[0 for i in range(book)]))
Problem p02853 (python)

Fixed submission:
x, y = map(int, input().split())
 
a = [0, 300000, 200000, 100000, 0]
ans = 0
 
x = min(x, 4)
y = min(y, 4)
 
ans = a[x] + a[y]
if x == 1 and y == 1:
    ans += 400000
 
print(ans)

Buggy submission (verdict: Runtime Error):
, y = map(int, input().split())
 
a = [0, 300000, 200000, 100000, 0]
ans = 0
 
x = min(x, 4)
y = min(y, 4)
 
ans = a[x] + a[y]
if x == 1 and y == 1:
    ans += 400000
 
print(ans)

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

x, y = map(int, input().split())

a = [0, 300000, 200000, 100000, 0]
ans = 0

x = min(x, 4)
y = min(y, 4)

ans = a[x] + a[y]
if x == 1 and y == 1:
    ans += 400000

print(ans)
Problem p02995 (python)

Fixed submission:
from fractions import gcd

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

A = (a-1) // c + (a-1) // d - (a-1) // ((c * d) // gcd(c, d))
B = b // c + b // d - b // ((c * d ) // gcd(c, d))

print (b - B - (a - 1 - A))

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

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

A = (a-1) // c + (a-1) // d - (a-1) // ((c * d) // gcd(c, d))
B = b // c + b // d - b // ((c * d ) // gcd(c, d))

print (b - B - (a - 1 - A))
Problem p03131 (python)

Fixed submission:
K, A, B = map(int, raw_input().split())

if B - A <= 2:
    print K + 1
    exit()

S = 1

M = min(K, A-1)
K -= M
S += M

S += K / 2 * (B - A)
K %= 2
S += K

print S

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

if B - A <= 2:
    print K + 1
    exit()

S = 1

M = min(K, A-1)
K -= M
S += M

S += K / 2 * (B - A)
K %= 2
S += K

print S
Problem p03214 (python)

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

NA = sum(A)
mv = float('inf')
mi = -1

for i in xrange(N):
    v = abs(NA - A[i] * N)
    if v < mv:
        mv = v
        mi = i

print mi

Buggy submission (verdict: Runtime Error):
T, A, B, C, D = map(int, raw_input().split())

if A + C <= T:
    print B + D
elif C <= T:
    print D
elif A <= T:
    print B
else:
    print 0
Problem p03319 (python)

Fixed submission:
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
print (N-2)/(K-1)+1

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
from collections import Counter

K = input()
A = range(1, 10) + range(19, 100, 10)
N = K - len(A)
diff = 100
target = 19
count = 0

while N > 0:
    N -= 1
    A.append(A[-1]+diff)
    count += 1
    if count == target:
        diff *= 10
        target += 9
        count = 0

for i in xrange(K):
    print A[i]
Problem p03320 (python)

Fixed submission:
from fractions import Fraction

def calc(a):
    return sum(map(int, list(str(a))))

def comp(a, b):
    return a * calc(b) <= b * calc(a)

MAX = 10**17
K = input()
A = set()
base = 0
front = 1
ok = True
while base < MAX:
    for i in xrange(1, 999):
        tmp = i * front + base
        if tmp <= MAX:
            A.add(tmp)
    base = base * 10 + 9
    front *= 10

A = sorted(list(A), key=lambda x: -x)
m = A[0]
ans = []

for i in xrange(1, len(A)):
    if comp(A[i], m):
        m = A[i]
        ans.append(A[i])

ans.sort()
for i in xrange(K):
    print ans[i]

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
from collections import Counter

K = input()
A = range(1, 10) + range(19, 100, 10)
N = K - len(A)
diff = 100
target = 19
count = 0

while N > 0:
    N -= 1
    A.append(A[i]+diff)
    count += 1
    if count == target:
        diff *= 10
        target += 9
        count = 0

for i in xrange(K):
    print A[i]
Problem p03419 (python)

Fixed submission:
H, W = map(int, raw_input().split())

if H > W:
    H, W = W, H

if H == 1 and W == 1:
    print 1
elif H == 1:
    print W - 2
else:
    print (H - 2) * (W - 2)

Buggy submission (verdict: Runtime Error):
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"
Problem p03721 (python)

Fixed submission:
A = [0 for _ in xrange(10**5+10)]
N, K = map(int, raw_input().split())
for i in xrange(N):
    a, b = map(int, raw_input().split())
    A[a] += b

k = 0
for i in xrange(10**5+10):
    k += A[i]
    if k >= K:
        print i
        break

Buggy submission (verdict: Runtime Error):
    A = [0 for _ in xrange(10**5+10)]
    N, K = map(int, raw_input().split())
    for i in xrange(N):
        a, b = map(int, raw_input().split())
        A[a] += b
     
    k = 0
    for i in xrange(10**5+10):
        k += A[i]
        if k >= K:
            print i
            break
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,raw_input().split())
print ["NO","YES"][b-a==c-b]

Buggy submission (verdict: Runtime Error):
a,b,c=input(),input(),input()
print ["NO","YES"][b-a==c-b]
Problem p03943 (python)

Fixed submission:
a,b,c = sorted(map(int, raw_input().split()))
print 'Yes' if a+b==c else 'No'

Buggy submission (verdict: Runtime Error):
print 'No' if sum(map(int, raw_input().split())9 else 'Yes'
Problem p03972 (python)

Fixed submission:
W, H = map(int, raw_input().split())
p = sorted([(i, int(raw_input())) for i in xrange(W)], key=lambda x:-x[1])
q = sorted([(i, int(raw_input())) for i in xrange(H)], key=lambda x:-x[1])
ans = 0
pe, qe, ae = 0, 0, (W+1)*(H+1)-1
while len(p)> 0 or len(q) > 0:
    if len(q) == 0 or (len(p) > 0 and p[-1][1] <= q[-1][1]):
        i, cost = p.pop()
        pe += 1
        ans += cost*(H+1-qe)
    else:
        j, cost = q.pop()
        qe += 1
        ans += cost*(W+1-pe)

print ans

Buggy submission (verdict: Runtime Error):
W, H = map(int, raw_input().split())
p = sorted([(i, int(raw_input())) for i in xrange(W)], key=lambda x:-x[1])
q = sorted([(i, int(raw_input())) for i in xrange(H)], key=lambda x:-x[1])

class UnionFind(object):
    def __init__(self, n):
        self.uf = [-1 for _ in xrange(n)]

    def union(self, x, y):
        x = self.find(x[0] + x[1]*(W+1))
        y = self.find(y[0] + y[1]*(W+1))
        if x == y:
            return False
        if self.uf[x] >= self.uf[y]:
            self.uf[y] += self.uf[x]
            self.uf[x] = y
        else:
            self.uf[x] += self.uf[y]
            self.uf[y] = x
        return True

    def find(self, x):
        leaves = []
        while self.uf[x] >= 0:
            leaves.append(x)
            x = self.uf[x]
        for lf in leaves:
            self.uf[lf] = x
        return x

uf = UnionFind((W+1)*(H+1))
ans = 0
while len(p) > 0 or len(q) > 0:
    if len(q) == 0 or (len(p) > 0 and p[-1][1] <= q[-1][1]):
        i, cost = p.pop()
        for j in xrange(H+1):
            if uf.union((i, j), (i+1, j)):
                ans += cost
    else:
        j, cost = q.pop()
        for i in xrange(W+1):
            if uf.union((i, j), (i, j+1)):
                ans += cost
print ans
Problem p03975 (python)

Fixed submission:
N, A, B=map(int, raw_input().split())
print sum(not(A<=int(raw_input())<B) for _ in range(N))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, K = map(int, raw_input().split())
C = sorted(Counter(raw_input()[0] for _ in xrange(N)).values())
a = C.pop()
b = sum(C)
for i in xrange(a, 0, -1):
    if b/i >= K-1:
        print i
        break
else:
    print 0
Problem p03997 (python)

Fixed submission:
print (input()+input())*input()/2

Buggy submission (verdict: Runtime Error):
    H, W, N = map(int, raw_input().split())
    dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
    dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
    board = {}
     
    for i in xrange(N):
        a, b = map(int, raw_input().split())
        for j in xrange(9):
            x, y = a+dx[j], b+dy[j]
            if x <= 1 or x >= H or y <= 1 or y >= W:
                continue
            if (x, y) in board:
                board[(x, y)] += 1
            else:
                board[(x, y)] = 1
    ans = [0] * 10
    for v in board.values():
        ans[v] += 1
    ans[0] = (H-2)*(W-2)-sum(ans)
    for a in ans:
        print a
Problem p04000 (python)

Fixed submission:
H, W, N = map(int, raw_input().split())
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
board = {}

for i in xrange(N):
    a, b = map(int, raw_input().split())
    for j in xrange(9):
        x, y = a+dx[j], b+dy[j]
        if x <= 1 or x >= H or y <= 1 or y >= W:
            continue
        if (x, y) in board:
            board[(x, y)] += 1
        else:
            board[(x, y)] = 1
ans = [0] * 10
for v in board.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for a in ans:
    print a

Buggy submission (verdict: Runtime Error):
    H, W, N = map(int, raw_input().split())
    dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
    dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
    board = {}
     
    for i in xrange(N):
        a, b = map(int, raw_input().split())
        for j in xrange(9):
            x, y = a+dx[j], b+dy[j]
            if x <= 1 or x >= H or y <= 1 or y >= W:
                continue
            if (x, y) in board:
                board[(x, y)] += 1
            else:
                board[(x, y)] = 1
    ans = [0] * 10
    for v in board.values():
        ans[v] += 1
    ans[0] = (H-2)*(W-2)-sum(ans)
    for a in ans:
        print a
Problem p04011 (python)

Fixed submission:
n, k, x, y = [input() for _ in range(4)]
print x * min(n, k) + y * max(n-k, 0)

Buggy submission (verdict: Runtime Error):
N, A = map(int, raw_input().split())
a = sorted(map(lambda x:int(x)-A, raw_input().split()))
mem = {}

def rec(p, acm):
    if (p, acm) in mem:
        return mem[(p, acm)]
    if p >= N:
        return 0
    if a[p] > 0 and acm > 0:
        return 0
    mem[(p, acm)] = rec(p+1, acm+a[p]) + rec(p+1, acm)
    if acm+a[p] == 0:
        mem[(p, acm)] += 1
    return mem[(p, acm)]

print rec(0, 0)
Problem p04012 (python)

Fixed submission:
from collections import Counter
print 'Yes' if all(a%2-1 for a in Counter(raw_input()).values()) else 'No'

Buggy submission (verdict: Runtime Error):
from collections import Counter
print 'Yes' if all(v % 2 == 0 for v in Counter(raw_input()).values())) else 'No'
Problem p04048 (python)

Fixed submission:
def calc(a, b):
    if a <= 0 or b <= 0:
        return 0
    if a == b:
        return a
    a, b = min(a, b), max(a, b)
    x = max(1, b / (2 * a))
    return calc(b-x*a, a) + 2 * a * x

N, X = map(int, raw_input().split())
print calc(X, N-X) + N

Buggy submission (verdict: Runtime Error):
def calc(a, b):
    if a <= 0 or b <= 0:
        return 0
    if a == b:
        return a
    a, b = min(a, b), max(a, b)
    return calc(b-a, a) + 2 * a

N, X = map(int, raw_input().split())
print calc(X, N-X) + N
Problem p02618 (python)

Fixed submission:
d = int(input())  # 365
c = list(map(int, input().split()))

# 最低限のポイントを確認？
for i in range(d):
    p = list(map(int, input().split()))
    print(p.index(max(p)) + 1)

Buggy submission (verdict: Runtime Error):
import numpy


d = int(input())
c = numpy.array(list(map(int, input().split())))
s = []
for i in range(d):
    s.append(list(map(int, input().split())))

result = []
past = numpy.array([0] * 26)
ans = 0
for i in range(d):
    past += 1
    t = int(input())
    past[t-1] = 0
    ans += sum(past * -c) + s[i][t-1]
    print(ans)
Problem p02678 (python)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 8)

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

aisles = [[] for _ in range(n)]
visited = [1] + [0] * (n - 1)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    aisles[a].append(b)
    aisles[b].append(a)

q = deque([0])

while q:
    v = q.pop()
    for nex in aisles[v]:
        if visited[nex] != 0:
            continue
        visited[nex] = v + 1
        q.appendleft(nex)

print("Yes")
for point in visited[1:]:
    print(point)

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

aisles = [[] for _ in range(n)]
michi = [0] * n
num = [float('INF')] * n
loads = []
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if b < a:
        a, b = b, a
    if a == 0:
        loads.append(b)
    aisles[a].append(b)
    aisles[b].append(a)

if len(loads) == 0:
    print("No")
    exit()


def ap(ll, nm, nu):
    for l in ll:
        if num[l] > nu:
            michi[l] = nm
            num[l] = nu
            ap(aisles[l], l, nu + 1)


ap(loads, 0, 1)

print("Yes")
for mi in michi[1:]:
    print(mi + 1)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = [0 for _ in range(n)]
f[0] = 1

v = [1]
s = 0
idx = 0
loop = 0
last = 1
for i in range(k):
    vi = a[last - 1]
    if not f[vi - 1]:
        f[vi - 1] = 1
        last = vi
        s += 1
        v.append(vi)
    else:
        s += 1
        idx = v.index(vi)
        loop = s - idx
        break
else:
    print(vi)
    exit()
remain = k - s
print(v[idx:][remain % loop])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = [0 for _ in range(n)]
f[0] = 1

v = [0]
s = 0
idx = 0
loop = 0
last = 0

for _ in range(k):
    vi = a[last] - 1
    if not f[vi]:
        f[vi] = 1
        last = vi
        s += 1
        v.append(vi)
    else:
        s += 1
        idx = v.index(vi)
        loop = s - idx
        break

remain = k - s

print(v[idx:][remain % loop] + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = [0 for _ in range(n)]
f[0] = 1

v = [0]
s = 0
idx = 0
loop = 0
last = 0

for i in range(k):
    vi = a[last] - 1
    if not f[vi]:
        f[vi] = 1
        last = vi
        s += 1
        v.append(vi)
    else:
        s += 1
        idx = v.index(vi)
        loop = s - idx
        break

remain = k - s
print(v[idx:][remain % loop] + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = [0 for _ in range(n)]
f[0] = 1

v = [1]
s = 0
idx = 0
loop = 0
last = 1
for i in range(k):
    vi = a[last - 1]
    if not f[vi - 1]:
        f[vi - 1] = 1
        last = vi
        s += 1
        v.append(vi)
    else:
        s += 1
        idx = v.index(vi)
        loop = s - idx
        break
remain = k - s
print(v[idx:][remain % loop])
Problem p02702 (python)

Fixed submission:
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2019)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = int(degit) * pow(10, idx, 2019)
    m = (m + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2017)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(s[::-1]):
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2017)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in s[::-1]:
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
mod = [1] + [0 for _ in range(2017)]
ml = [0 for _ in range(l + 1)]
ans = 0

tmp = 0
for idx, degit in enumerate(reversed(s)):
    m = (int(degit) * (10 ** idx) + tmp) % 2019
    tmp = m
    ans += mod[m]
    mod[m] += 1

print(ans)
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")


ans = r * g * b

for i in range(n):
    for j in range(i + 1, n):
        if 2 * j - i > n - 1:
            continue
        if s[i] == s[j] or s[i] == s[2 * j - i] or s[j] == s[2 * j - i]:
            pass
        else:
            ans -= 1
print(ans)

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

r = []
g = []
b = []

for i, c in enumerate(s):
    if c == "R":
        r.append(i)
    elif c == "G":
        g.append(i)
    else:
        b.append(i)


ans = 0
for ri in r:
    for gi in g:
        for bi in b:
            arr = [ri, gi, bi]
            arr.sort()
            if arr[0] + arr[2] == 2 * arr[1]:
                pass
            else:
                ans += 1

print(ans)
Problem p02755 (python)

Fixed submission:
a, b = map(int, input().split())
for i in range(1010):
    tax8 = int(i * 0.08)
    tax10 = int(i * 0.1)

    if a == tax8 and b == tax10:
        print(i)
        exit()

print(-1)

Buggy submission (verdict: Runtime Error):
for i in range(1010):
    tax8 = int(i * 0.08)
    tax10 = int(i * 0.1)

    if a == tax8 and b == tax10:
        print(i)
        exit()

print(-1)
Problem p02957 (python)

Fixed submission:
a, b = map(int, input().split())
if (a + b) % 2 == 0:
    print((a + b) // 2)
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
# OLE?
a = input()
b = input()
Problem p02969 (python)

Fixed submission:
r = int(input())
print(3 * r * r)

Buggy submission (verdict: Runtime Error):
import math
n, d = map(int, input().split())
 
print(math.ceil(n / (d * 2 + 1)), end=" ")
Problem p03032 (python)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        if left + right > n:
            break
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(min(k - left - right, left + right)):
            if 0 <= hold[i]:
                break
            total -= hold[i]
        M = max(M, total)

print(M)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        if left + right > n:
            break
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(k - left - right):
            if 0 <= hold[i]:
                break
            total -= hold[i]
        M = max(M, total)

print(M)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        if left + right > n:
            break
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(min(k - left - right)):
            if 0 <= hold[i]:
                break
            total -= hold[i]
        M = max(M, total)

print(M)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
k = min(n, k)
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(k - left - right):
            if i > len(hold):
                break
            if 0 <= hold[i]:
                break
            if hold[i] < 0:
                total -= hold[i]

        M = max(M, total)

print(M)