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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-r, N):
        hold.append(V[i])
    hold.sort()
    return 0 if d >= len(hold) else sum(hold[d:]) 

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = K - l - r
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, max(N-1-r,-1), -1):
        hold.append(V[i])
    hold.sort()
    return 0 if d >= len(hold) else sum(hold[d:]) 

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = max(K - l - r, 0)
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, N-1-r, -1):
        hold.append(V[i])
    hold.sort()
    return 0 if d >= len(hold) else sum(hold[d:]) 

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = max(K - l - r, 0)
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, N-1-r, -1):
        hold.append(V[i])
    hold.sort()
    return sum(hold[d:])

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = max(K - l - r, 0)
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, N-1-r, -1):
        hold.append(V[i])
    hold.sort()
    return sum(hold[d:])

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = K - l - r
        if d > l + r:
            continue
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, N-1-r, -1):
        hold.append(V[i])
    hold.sort()
    return sum(hold[d:])

ret = 0
for l in range(K):
    for r in range(K-l):
        d = K - l - r
        if d > l + r:
            continue
        ret = max(ret, calc(l, r, d))
print(ret)

Fixed submission:
N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)