N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
if 2*N<=K:
    for i in V:
        if i>=0:
            ans+=i
else:
    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,min(N,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 if 2*N<=K:
    for i in V:
        if i>=0:
            ans+=i
else:
    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,min(N,K)-a-b)):
                if v[i]<0:
                    value=value-v[i]
                else:
                    break
            ans=max(ans,value) 2*N<=K 2*N 2 N K for i in V:
        if i>=0:
            ans+=i i V if i>=0:
            ans+=i i>=0 i 0 ans+=i ans i 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,min(N,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,min(N,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,min(N,K)-a-b)):
                if v[i]<0:
                    value=value-v[i]
                else:
                    break
             i range(min(a+b,min(N,K)-a-b)) range min(a+b,min(N,K)-a-b) min a+b a b min(N,K)-a-b min(N,K)-a min(N,K) min N 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 value=value+sum(V[-b:]) value+sum(V[-b:]) value ans=0 0 ans value=sum(V[:a]) sum(V[:a]) value V=list(map(int,input().split())) list(map(int,input().split())) V ans+=i i ans ans=max(ans,value) max(ans,value) ans K=map(int,input().split()) map(int,input().split()) K v=[] [] v N,K=map(int,input().split()) map(int,input().split()) N value=value-v[i] value-v[i] value
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
if 2*N<=K:
    for i in V:
        if i>=0:
            ans+=i
else:
    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,min(N,K)-a-b)):
                if v[i]<0:
                    value=value-v[i]
                else:
                    break
            ans=max(ans,value)
print(ans)