Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
v=list(map(int,input().split()))
ma=0
for i in range(k//2+1):
     pick=min(k-i,n)
     for j in range(pick+1):
          if j==0:
               l=v[:pick]
               al=l
          elif j==pick:
               r=v[-pick:]
               al=r
          else:
               l=v[:pick-j]
               r=v[-j:]
               al=l+r
          for rem in range(i):
               al.remove(min(al))
          ma=max(ma,sum(al))
print(ma)

Fixed submission:
n,k=map(int,input().split())
v=list(map(int,input().split()))
ma=0
for i in range(k//2+1):
     pick=min(k-i,n)
     for j in range(pick+1):
          if j==0:
               l=v[:pick]
               al=l
          elif j==pick:
               r=v[-pick:]
               al=r
          else:
               l=v[:pick-j]
               r=v[-j:]
               al=l+r
          for rem in range(i):
               if len(al)>0:
                    mi=min(al)
                    if mi<0:
                         al.remove(mi)
                    else:
                         break
               else:
                    break
          if len(al)>0:
               ma=max(ma,sum(al))
print(ma)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
v=list(map(int,input().split()))
a=[[v[:k],[]]]
for i in range(1,min(n,k)):
     l=v[:k-i]
     r=v[-i:][::-1]
     a.append([l,r])
a.append([[],v[-min(n,k):][::-1]])
ma=0
for a_ in a:
     l=a_[0]
     r=a_[1]
     su=sum(l)+sum(r)
     for i in range(k//2):
          if len(r)==0:
               l_=l.pop()
               su-=l_
               mi=min(l)
               l.remove(mi)
               su-=mi
               ma=max(ma,su)
          elif len(l)==0:
               r_=r.pop()
               su-=r_
               mi=min(r)
               r.remove(mi)
               su-=mi
               ma=max(ma,su)
          else:
               l_=l.pop()
               r_=r.pop()
               try:
                    l_mi=min(l)
               except:
                    l_mi=10**7+1
               try:
                    r_mi=min(r)
               except:
                    r_mi=10**7+1
               if l_mi>r_mi:
                    if r_mi<0:
                         r.remove(r_mi)
                         su-=r_mi
               else:
                    if l_mi<0:
                         l.remove(l_mi)
                         su-=l_mi
               if l_>r_:
                    l.append(l_)
                    su-=r_
               else:
                    r.append(r_)
                    su-=l_
               ma=max(ma,su)
print(ma)

Fixed submission:
n,k=map(int,input().split())
v=list(map(int,input().split()))
ma=0
for i in range(k//2+1):
     pick=min(k-i,n)
     for j in range(pick+1):
          if j==0:
               l=v[:pick]
               al=l
          elif j==pick:
               r=v[-pick:]
               al=r
          else:
               l=v[:pick-j]
               r=v[-j:]
               al=l+r
          for rem in range(i):
               if len(al)>0:
                    mi=min(al)
                    if mi<0:
                         al.remove(mi)
                    else:
                         break
               else:
                    break
          if len(al)>0:
               ma=max(ma,sum(al))
print(ma)