Buggy python submission (verdict: Runtime Error):
from collections import deque
import heapq
n, k = map(int, input().split())
v = list(map(int, input().split()))

result = []
for i in range(k):
    for j in range(k-i):
        jue = []
        heapq.heapify(jue)
        for ii in range(i):
            heapq.heappush(jue, v[ii])
        for jj in range(j):
            heapq.heappush(jue, v[-jj-1])
        for le in range(min(k-i-j, len(jue))):
            heapq.heappop(jue)
        result.append(sum(jue))

print(max(result))

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

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print(max(result))

Buggy python submission (verdict: Runtime Error):
from collections import deque
import heapq
n, k = map(int, input().split())
v = list(map(int, input().split()))

result = []
for i in range(k):
    for j in range(k-i):
        jue = []
        heapq.heapify(jue)
        for ii in range(i):
            heapq.heappush(jue, v[ii])
        for jj in range(j):
            heapq.heappush(jue, v[-jj-1])
        for le in range(min(k-i-j, i+j)):
            heapq.heappop(jue)
        result.append(sum(jue))

print(max(result))

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

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print(max(result))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import heapq
import copy
n, k = map(int, input().split())

v = deque(list(map(int, input().split())))
j = []
heapq.heapify(j)

def solve(hep, jue, c, end=k):
    if c==k:
        return sum(hep)
    result = [0]
    if len(jue)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.pop())
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.popleft())
        result.append(solve(x, y, c+1))

    if len(hep)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.append(heapq.heappop(x))
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.appendleft(heapq.heappop(x))
        result.append(solve(x, y, c+1))

    return max(result)


print(solve(j, v, 0))

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

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print(max(result))

Buggy python submission (verdict: Runtime Error):
from collections import deque
import heapq
n, k = map(int, input().split())

v = deque(list(map(int, input().split())))
j = []
heapq.heapify(j)

def solve(hep, jue, c, end=k):
    if c==k:
        return sum(hep)
    result = [0]
    if len(jue)!=0:
        x, y = hep.copy(), jue.copy()
        heapq.heappush(x, y.pop())
        result.append(solve(x, y, c+1))

        x, y = hep.copy(), jue.copy()
        heapq.heappush(x, y.popleft())
        result.append(solve(x, y, c+1))


    if len(hep)!=0:
        x, y = hep.copy(), jue.copy()
        y.append(heapq.heappop(x))
        result.append(solve(x, y, c+1))

        x, y = hep.copy(), jue.copy()
        y.appendleft(heapq.heappop(x))
        result.append(solve(x, y, c+1))

    return max(result)


print(solve(j, v, 0))

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

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print(max(result))