n,k,*v=list(map(int,open(0).read().split()))

motimono=[]

ans=[]

v*=2

for j in range(1,min(n,k)+1):

    for i in range(n-j,n+1):

        motimono=v[i:i+j]

        ans.append(sum(motimono))

        motimono.sort()

        for i in range(k-j):

            if len(motimono)>0:

                del motimono[0]

            ans.append(sum(motimono))

print((max(ans)))
n,k,*v=list(map(int,open(0).read().split()))

motimono=[]

ans=[]

v*=2

for j in range(1,min(n,k)+1):

    for i in range(n-j,n+1):

        motimono=v[i:i+j]

        ans.append(sum(motimono))

        motimono.sort()

        for i in range(min(k-j,j)):

            del motimono[0]

            ans.append(sum(motimono))

print((max(ans)))

n, k, *v = list(map(int, open(0).read().split()))
motimono = []
ans = []
v *= 2
for j in range(1, min(n, k) + 1):
    for i in range(n - j, n + 1):
        motimono = v[i : i + j]
        ans.append(sum(motimono))
        motimono.sort()
        for i in range(k - j):
            if len(motimono) > 0:
                del motimono[0]
            ans.append(sum(motimono))
print((max(ans)))

n, k, *v = list(map(int, open(0).read().split()))
motimono = []
ans = []
v *= 2
for j in range(1, min(n, k) + 1):
    for i in range(n - j, n + 1):
        motimono = v[i : i + j]
        ans.append(sum(motimono))
        motimono.sort()
        for i in range(min(k - j, j)):
            del motimono[0]
            ans.append(sum(motimono))
print((max(ans)))

-        for i in range(k - j): -            if len(motimono) > 0: -                del motimono[0] +        for i in range(min(k - j, j)): +            del motimono[0]