qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
l = []
for i in range(n):
    d = {}
    d["index"] = i+1
    d["city"], d["score"] = input().split()
    l.append(d)
results = []
for city in citys:
    sorted_scores = sorted([l[i]["score"] for i in range(n) if l[i]["city"] == city], reverse=True)
    for score in sorted_scores:
        candidate = [l[i]["index"] for i in range(n) if (l[i]["city"] == city)&(l[i]["score"] == score)][0]
        results.append(candidate)
print(*results, sep="\n")

Fixed code:
n = int(input())
l = []
for i in range(n):
    d = {}
    d["index"] = i+1
    d["city"], d["score"] = input().split()
    d["score"] = int(d["score"])
    l.append(d)
results = []
citys = list(set([l[i]["city"] for i in range(n)]))
citys.sort()
for city in citys:
    sorted_scores = sorted([l[i]["score"] for i in range(n) if l[i]["city"] == city], reverse=True)
    for score in sorted_scores:
        candidate = [l[i]["index"] for i in range(n) if (l[i]["city"] == city)&(l[i]["score"] == score)][0]
        results.append(candidate)
print(*results, sep="\n")
Buggy code:
n = int(input())
review = []
for i in range(n):
    s, p = input().split()
    review.append([s, int(p), i + 1])
rev_sorted = sorted(review, key = lambda x: (x[0], x[1]), reverse = (False, True))
for i in rev_sorted:
    print(i[2])

Fixed code:
n = int(input())
review = []
for i in range(n):
    s, p = input().split()
    review.append([s, int(p), i + 1])
rev_sorted1 = sorted(review, key = lambda x: x[1] , reverse = True)
rev_sorted2 = sorted(rev_sorted1, key = lambda x: x[0], reverse = False)
for i in rev_sorted2:
    print(i[2])
Buggy code:
#128 b
n=int(input())
res=[]
for i in range(n):
    a,b=list(input().split())
    b=-1*int(b)
    res.append([a,b,i+1])
res=sorted(res)
for i in n:
    print(x[2])


Fixed code:
#128 b
n=int(input())
res=[]
for i in range(n):
    a,b=list(input().split())
    b=-1*int(b)
    res.append([a,b,i+1])
res=sorted(res)
for x in res:
    print(x[2])
Buggy code:
n=int(input())
sp=[]
for i in range(n):
    a=list(map(str,input().split()))
    a.append(i+1)
    sp.append(a)

sp=sorted(sp,key=lambda x:int(x[1]),reverse=True)


for i in range(len(sp)):
    print(sp[i][2])

Fixed code:
n=int(input())
sp=[]
for i in range(n):
    a=list(map(str,input().split()))
    a.append(i+1)
    sp.append(a)

sp=sorted(sp,key=lambda x:int(x[1]),reverse=True)
sp=sorted(sp,key=lambda x:x[0])

for i in range(len(sp)):
    print(sp[i][2])
Buggy code:
n = int(input())
a = []
for i in range(1, n+1):
    s,p = map(str,input().split())
    a.append((s,int(p),i))
a.sort()
print(a)
ans = [a[0][2]]
k = 0
for i in range(1,n):
    if a[i-1][0] == a[i][0]:
        ans.insert(k,a[i][2])
    else:
        k = i
        ans.append(a[i][2])

for i in range(n):
    print(ans[i])





Fixed code:
n = int(input())
a = []
for i in range(1, n+1):
    s,p = map(str,input().split())
    a.append((s,int(p),i))
a.sort()
ans = [a[0][2]]
k = 0
for i in range(1,n):
    if a[i-1][0] == a[i][0]:
        ans.insert(k,a[i][2])
    else:
        k = i
        ans.append(a[i][2])

for i in range(n):
    print(ans[i])
Buggy code:
from operator import itemgetter
n = int(input())
l = []
for i in range(n):
    pair = input().split()
    l.append([pair[0], pair[1]])
l2 = l[:]
print(l)
# point rev. sort
sub = sorted(l2, key=itemgetter(1), reverse=True)
# name sort
l_sorted = sorted(sub, key=itemgetter(0))
print(l_sorted)
for i in range(n):
    for j in range(n):
        if (l[j] == l_sorted[i]):
            print(j+1)


Fixed code:
from operator import itemgetter
n = int(input())
l = []
for i in range(n):
    pair = input().split()
    l.append([pair[0], int(pair[1])])
l2 = l[:]
# point rev. sort
sub = sorted(l2, key=itemgetter(1), reverse=True)
# name sort
l_sorted = sorted(sub, key=itemgetter(0))
for i in range(n):
    for j in range(n):
        if (l[j] == l_sorted[i]):
            print(j+1)
Buggy code:
N = int(input())

X=[]
for i in range(N):
    X.append([str(j) for j in input().split()])

sort1=sorted(X, key=lambda x:x[1], reverse=True)
sort2=sorted(sort1, key=lambda x:x[0])
print(sort2)

for j in range(N):
    print(X.index(sort2[j])+1)

Fixed code:
N = int(input())

X=[]
for i in range(N):
    S, P = input().split()
    X.append([S,int(P)])

sort1=sorted(X, key=lambda x:x[1], reverse=True)
sort2=sorted(sort1, key=lambda x:x[0])

for j in range(N):
    print(X.index(sort2[j])+1)
Buggy code:
N = int(input())
x = [list(map(str,input().split())) for _ in range(N)]
x_new=[]
for i in range(N):
  x_new.append([i+1,x[i][0],int(x[i][1])])
   
x_new.sort(reverse=True,key=lambda x: x[2])
x_new.sort(key=lambda x: x[1])

for j in range(N):
  x_new[j].append(j+1)
x_new.sort(key=lambda x:x[0])
for u in range(N):
  print(x_new[u][3])

Fixed code:
N = int(input())
x = [list(map(str,input().split())) for _ in range(N)]
x_new=[]
for i in range(N):
  x_new.append([i+1,x[i][0],int(x[i][1])])
   
x_new.sort(key=lambda x: x[2],reverse=True)
x_new.sort(key=lambda x: x[1])

for j in x_new:
  print(j[0])
Buggy code:
n = int(input())
res = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    res.append([i+1, s, p])

res = sorted(res, key=lambda x: (x[1], x[2]), reverse=True)
for r in res:
    print(r[0])

Fixed code:
n = int(input())
res = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    res.append([i+1, s, p])

res = sorted(res, key=lambda x:x[2], reverse=True)
res = sorted(res, key=lambda x:x[1], reverse=False)
for r in res:
    print(r[0])
Buggy code:
n = int(input())

s = [list(map(str, input().split())) for _ in range(n)]
for row in s:
    row[1] = int(row[1])
ss = sorted(s)
print(ss)
ins = 0
ans = list()
tmp = 0
for i in ss:
    if i[0] == tmp:
        ans.insert(ins,i)
    else:
        ins = len(ans)
        ans.append(i)
        tmp = i[0]
print(ans)


Fixed code:
n = int(input())

s = [list(map(str, input().split())) for _ in range(n)]
for row in s:
    row[1] = int(row[1])
ss = sorted(s)
ins = 0
ans = list()
tmp = 0
for i in ss:
    if i[0] == tmp:
        ans.insert(ins,i)
    else:
        ins = len(ans)
        ans.append(i)
        tmp = i[0]
for j in ans:
    print(s.index(j)+1)
Buggy code:
N = int(input())
SP = []
for i in range(N):
  S,P = map(int,input().split())
  P = int(P)
  SP.append(S,P,i+1)
SP.sort()
for a,b,c in SP:
  print(c)

Fixed code:
N = int(input())
SP = []
for i in range(N):
  S,P = input().split()
  P = int(P)
  SP.append((S,-P,i+1))
SP.sort()
for a,b,c in SP:
  print(c)
Buggy code:
n = int(input())
lis = []
for i in range(n):
    s,p = input().split()
    lis.append((s,int(p),i))
from operator import itemgetter
lis = sorted(lis,key=itemgetter(0))
lis = sorted(lis,key=itemgetter(1),reverse=True)
for i in range(n):
    print(lis[i][2])

Fixed code:
n = int(input())
lis = []
for i in range(1,n+1):
    s,p = input().split()
    lis.append((s,int(p),i))
from operator import itemgetter
lis = sorted(lis,key=itemgetter(1),reverse=True)
lis = sorted(lis,key=itemgetter(0))
for i in range(n):
    print(lis[i][2])
Buggy code:
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    row = input().split()
    row[1] = - int(row[1])
    row.append(i+1)
    sp.append(row)

sp.sort(key=itemgetter(0, 1))
for index in sp:
    print(index[2])
print(sp)



Fixed code:
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    row = input().split()
    row[1] = - int(row[1])
    row.append(i+1)
    sp.append(row)

sp.sort(key=itemgetter(0, 1))
for index in sp:
    print(index[2])
Buggy code:
l = []
for i in range(int(input())):
  s,p = map(str, input().split())
  l.append((s,100-int(p),i+1))
m = sorted(l)
for i in l:
  print(l[2])

Fixed code:
l = []
for i in range(int(input())):
  s,p = map(str, input().split())
  l.append((s,100-int(p),i+1))
m = sorted(l)
for i in m:
  print(i[2])
Buggy code:
n=int(input())
A = [list(map(str,input().split())) for i in range(n)]
A_s = sorted(A, key=lambda x: x[1], reverse=True)
A_ss = sorted(A_s, key=lambda x: x[0], reverse=False)
for i in range(n):
    print(A.index( A_ss[i])+1)

Fixed code:
n=int(input())
A = [list(map(str,input().split())) for i in range(n)]
A_s = sorted(A, key=lambda x: int(x[1]), reverse=True)
A_ss = sorted(A_s, key=lambda x: x[0], reverse=False)
for i in range(n):
    print(A.index( A_ss[i])+1)
Buggy code:
n = int(input())
s =  [input().split() for i in range(n)]
temp = s
data = sorted(s,key=lambda x:(x[0],-int(x[1])))


for i in range(n):
    y = temp[i]
    result = data.index(y)
    print(result+1)


Fixed code:
n = int(input())
s =  [input().split() for i in range(n)]
temp = s
data = sorted(s,key=lambda x:(x[0],-int(x[1])))


for i in range(n):
    y = data[i]
    result = temp.index(y)
    print(result+1)
Buggy code:
N = int(input())
A = [input().split() for _ in range(N)]
a = []
for i in range(N):
  a.append([A[i][0], 100 - int(A[i][1])])
A = sorted(a)
print(a)
print(A)

for i in range(N):
  print(a.index(A[i])+1)

Fixed code:
N = int(input())
A = [input().split() for _ in range(N)]
a = []
for i in range(N):
  a.append([A[i][0], 100 - int(A[i][1])])
A = sorted(a)

for i in range(N):
  print(a.index(A[i])+1)
Buggy code:
import heapq, copy
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        # print(a, b)
        have = v[:a] + v[n-b:]
        # print(have)

        tmp = sum(have)
        ans = max(ans, tmp)

        have.sort()

        for c in range(min(n, k) - a - b + 1):
            if c >= len(have):
                break
            item = have[c]
            if item >= 0:
                break

            tmp -= item
            ans = max(ans, tmp)

print(ans)

Fixed code:
import heapq, copy
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(k + 1):
    for b in range(k - a + 1):
        if a + b > min(k, n):
            break
        # print(a, b)
        have = v[:a] + v[n-b:]
        # print(have)

        tmp = sum(have)
        ans = max(ans, tmp)

        have.sort()

        c = k - a - b

        for item in have:
            if c <= 0:
                break
            c -= 1
            if item >= 0:
                break

            tmp -= item
        ans = max(ans, tmp)

print(ans)
Buggy code:
N, K = map(int, input().split())
V = list(map(int, input().split()))
Ans = -float('inf')
for a in range(K+1):
    for b in range(K+1):
        if a + b > max(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans)
print(Ans)





Fixed code:
N, K = map(int, input().split())
V = list(map(int, input().split()))
Ans = -float('inf')
for a in range(K+1):
    for b in range(K+1):
        if a + b > min(K, N):
            break
        c = K - a - b
        A = V[:a] + V[N - b:]
        A.sort()
        ans = sum(A)
        for x in A:
            if c == 0:
                break
            if x >= 0:
                break
            if x < 0:
                c -= 1
                ans -= x
        Ans = max(ans, Ans)
print(Ans)
Buggy code:
n,k=map(int,input().split())
ans=0
v=list(map(int,input().split()))
for i in range(min(n,k+1)):
    for j in range(min(n-i,k-i+1)):
        if j!=0
            tmp=v[:i]+v[-j:]
        else:
            tmp=v[:i]
        tmp.sort()
        t=sum(tmp)
        for d in range(min(k-i-j,len(tmp))):
            if tmp[d]<0:
                t-=tmp[d]
        if t>ans:
            ans=t
print(ans)
    

Fixed code:
n,k=map(int,input().split())
ans=0
v=list(map(int,input().split()))
for i in range(min(n,k+1)):
    for j in range(min(n-i+1,k-i+1)):
        if j!=0:
            tmp=v[:i]+v[-j:]
        else:
            tmp=v[:i]
        tmp.sort()
        t=sum(tmp)
        for d in range(min(k-i-j,len(tmp))):
            if tmp[d]<0:
                t-=tmp[d]
        if t>ans:
            ans=t
print(ans)
Buggy code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        if left + right > n:
            break
        rest = k - left - right
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

print(ans)

Fixed code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

print(ans)
Buggy code:
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        cur1 = 0
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
                cur += 1
        cur2 = 0
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-cur1):
                ls.append(x)
                cur2 += 1
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-(cur1+cur2):
                s -= x
        ans = max(ans, s)
print(ans)

Fixed code:
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s)
print(ans)
Buggy code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(n):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            print(g, min(k-i-j, i+j))
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

print(ans)


Fixed code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

print(ans)
Buggy code:
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    print (s,t)
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)

Fixed code:
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    # print (s,t)
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)
Buggy code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(min(n, k)):
    for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right+1))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans)


Fixed code:
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(min(n, k+1)):
    for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans)
Buggy code:
#!/usr/bin/env python3

import heapq

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

max_try = min(n, k)
ans = 0

for a in range(0, max_try+1):
    for b in range(0, max_try+1-a):
        c = k-(a+b)
        # print(a, b, c, "", end="")
        # print(a, b, c)
        ans_tmp = 0
        garbage = []
        heapq.heapify(garbage)
        for i in range(a):
            num = v[i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        for i in range(b):
            num = v[-1-i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        # print(garbage)
        for i in range(c):
            # print(garbage)
            if len(garbage) == 0:
                break
            num = -heapq.heappop(garbage)
            # print(num)
            ans_tmp += num
        # print()
        print(ans_tmp)
        ans = max(ans, ans_tmp)

print(ans)


Fixed code:
#!/usr/bin/env python3

import heapq

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

max_try = min(n, k)
ans = 0

for a in range(0, max_try+1):
    for b in range(0, max_try+1-a):
        c = k-(a+b)
        # print(a, b, c, "", end="")
        # print(a, b, c)
        ans_tmp = 0
        garbage = []
        heapq.heapify(garbage)
        for i in range(a):
            num = v[i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        for i in range(b):
            num = v[-1-i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        # print(garbage)
        for i in range(c):
            # print(garbage)
            if len(garbage) == 0:
                break
            num = -heapq.heappop(garbage)
            # print(num)
            ans_tmp += num
        # print()
        # print(ans_tmp)
        ans = max(ans, ans_tmp)

print(ans)
Buggy code:
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = m-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(a):
            if data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)


Fixed code:
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)+1
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)
Buggy code:
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
ans=0
for a in range(n+1):
    for b in range(1,n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:]))
print(ans)

Fixed code:
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
ans=0
for a in range(n+1):
    for b in range(n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:]))
print(ans)
Buggy code:
N, K = map(int, input().split())
V = list(map(int, input().split()))

for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)

Fixed code:
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick-right
        pick_list = V[:right]+V[N-left:]

        pick_list = sorted(pick_list)
        tmp_ans = sum(pick_list)
        rem = min(K-pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)
Buggy code:
N, K = map( int, input().split() )
V = list( map( int, input().split() ) )
 
max_number = 0
for A in range( K + 1 ):
  for B in range( K + 1 ):
    J = K - A - B
    if J < 0:
      continue
    if A + B >= N:
      hand = V
    else:
      hand = sorted( set( V[ : A ] + V[ N - B : ] ))
    hand_num = 0
    for i in hand:
      if i > 0:
        hand = hand[ i: ]
        break
    max_number = max( max_number, sum( hand ))
print( max_number )

Fixed code:
N, K = map( int, input().split() )
V = list( map( int, input().split() ) )
 
max_number = 0
for A in range( K + 1 ):
  for B in range( K + 1 ):
    J = K - A - B
    if J < 0:
      continue
    if A + B >= N:
      hand = V
    else:
      hand = V[ : A ] + V[ N - B : ]
    hand = sorted( hand )
      
    hand_num = 0
    for i, j in enumerate(hand):
      if ( j > 0 ) or ( i == J ):
        hand = hand[ i: ]
        break
    max_number = max( max_number, sum( hand ))
print( max_number )
Buggy code:
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[cnt] = max(0,num[cnt])
            ans = max(ans,sum(num))
print(ans)

Fixed code:
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num))
print(ans)