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

V=list(map(int,input().split()))

ans=0

for i in range(n+1):

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

        #print(i, j)

        if i+j>k:

            continue

        tmp=V[:i]+V[n-j:]

        tmp.sort(reverse=True)

        for l in range(k-i-j):

            if tmp and tmp[-1]<0:

                tmp.pop()

            else:

                break

        ans=max(ans,sum(tmp))

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



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



res = 0



for i in range(n+1):

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

        if k < i+j:

            continue

        memo = v[:i] + v[n-j:]

        memo.sort()



        for _ in range(k-i-j):

            if memo and memo[0] < 0:

                memo.pop(0)

            else:

                break

        res = max(res,sum(memo))

print(res)

        
n, k = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for i in range(n + 1):
    for j in range(n - i + 1):
        # print(i, j)
        if i + j > k:
            continue
        tmp = V[:i] + V[n - j :]
        tmp.sort(reverse=True)
        for l in range(k - i - j):
            if tmp and tmp[-1] < 0:
                tmp.pop()
            else:
                break
        ans = max(ans, sum(tmp))
print(ans)

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
res = 0
for i in range(n + 1):
    for j in range(n - i + 1):
        if k < i + j:
            continue
        memo = v[:i] + v[n - j :]
        memo.sort()
        for _ in range(k - i - j):
            if memo and memo[0] < 0:
                memo.pop(0)
            else:
                break
        res = max(res, sum(memo))
print(res)

-V = list(map(int, input().split())) -ans = 0 +v = list(map(int, input().split())) +res = 0 -        # print(i, j) -        if i + j > k: +        if k < i + j: -        tmp = V[:i] + V[n - j :] -        tmp.sort(reverse=True) -        for l in range(k - i - j): -            if tmp and tmp[-1] < 0: -                tmp.pop() +        memo = v[:i] + v[n - j :] +        memo.sort() +        for _ in range(k - i - j): +            if memo and memo[0] < 0: +                memo.pop(0) -        ans = max(ans, sum(tmp)) -print(ans) +        res = max(res, sum(memo)) +print(res)