N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for a in range(min(N,K)+1):
    for b in range(min(N,K)+1-a):
        v=[]
        value=sum(V[:a])
        v.extend(V[:a])
        if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
        v.sort()
        for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
        ans=max(ans,value)
print(ans) N,K=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K V=list(map(int,input().split())) V list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ans=0 ans 0 for a in range(min(N,K)+1):
    for b in range(min(N,K)+1-a):
        v=[]
        value=sum(V[:a])
        v.extend(V[:a])
        if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
        v.sort()
        for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
        ans=max(ans,value) a range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 for b in range(min(N,K)+1-a):
        v=[]
        value=sum(V[:a])
        v.extend(V[:a])
        if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
        v.sort()
        for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
        ans=max(ans,value) b range(min(N,K)+1-a) range min(N,K)+1-a min(N,K)+1 min(N,K) min N K 1 a v=[] v [] value=sum(V[:a]) value sum(V[:a]) sum V[:a] V :a a v.extend(V[:a]) v.extend v extend V[:a] V :a a if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
         b!=0 b 0 value=value+sum(V[-b:]) value value+sum(V[-b:]) value sum(V[-b:]) sum V[-b:] V -b: -b b v.extend(V[-b:]) v.extend v extend V[-b:] V -b: -b b v.sort() v.sort v sort for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
         i range(min(a+b,K-a-b)) range min(a+b,K-a-b) min a+b a b K-a-b K-a K a b if v[i]<0:
                value=value-v[i]
            else:
                break
         v[i]<0 v[i] v i 0 value=value-v[i] value value-v[i] value v[i] v i break ans=max(ans,value) ans max(ans,value) max ans value print(ans) print ans V=list(map(int,input().split())) list(map(int,input().split())) V value=sum(V[:a]) sum(V[:a]) value value=value+sum(V[-b:]) value+sum(V[-b:]) value v=[] [] v value=value-v[i] value-v[i] value K=map(int,input().split()) map(int,input().split()) K ans=0 0 ans ans=max(ans,value) max(ans,value) ans N,K=map(int,input().split()) map(int,input().split()) N
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for a in range(min(N,K)+1):
    for b in range(min(N,K)+1-a):
        v=[]
        value=sum(V[:a])
        v.extend(V[:a])
        if b!=0:
            value=value+sum(V[-b:])
            v.extend(V[-b:])
        v.sort()
        for i in range(min(a+b,K-a-b)):
            if v[i]<0:
                value=value-v[i]
            else:
                break
        ans=max(ans,value)
print(ans)