N,K=list(map(int,input().split()))

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

r=min(N,K)

ans=0

for a in range(r+1):

    for b in range(r-a+1):

        tmp,minus=0,[]

        for i in range(a):

            t=V[i]

            tmp+=t

            if t<0:

                minus.append(t)

        for j in range(b):

            t=V[N-1-j]

            tmp+=t

            if t<0:

                minus.append(t)

        tmp-=sum(sorted(minus)[:K-(a+b)])

        ans=max(ans,tmp)

print(ans)

N,K=list(map(int,input().split()))

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

r,ans=min(N,K),0

for a in range(r+1):

  for b in range(r-a+1):

    tmp,minus=0,[]

    for i in range(a):

      tmp+=V[i]

      if V[i]<0:

        minus.append(V[i])

    for j in range(b):

      tmp+=V[N-j-1]

      if V[N-j-1]<0:

        minus.append(V[N-j-1])

    tmp-=sum(sorted(minus)[:K-(a+b)])

    ans=max(ans,tmp)

print(ans)
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
r = min(N, K)
ans = 0
for a in range(r + 1):
    for b in range(r - a + 1):
        tmp, minus = 0, []
        for i in range(a):
            t = V[i]
            tmp += t
            if t < 0:
                minus.append(t)
        for j in range(b):
            t = V[N - 1 - j]
            tmp += t
            if t < 0:
                minus.append(t)
        tmp -= sum(sorted(minus)[: K - (a + b)])
        ans = max(ans, tmp)
print(ans)

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
r, ans = min(N, K), 0
for a in range(r + 1):
    for b in range(r - a + 1):
        tmp, minus = 0, []
        for i in range(a):
            tmp += V[i]
            if V[i] < 0:
                minus.append(V[i])
        for j in range(b):
            tmp += V[N - j - 1]
            if V[N - j - 1] < 0:
                minus.append(V[N - j - 1])
        tmp -= sum(sorted(minus)[: K - (a + b)])
        ans = max(ans, tmp)
print(ans)

-r = min(N, K) -ans = 0 +r, ans = min(N, K), 0 -            t = V[i] -            tmp += t -            if t < 0: -                minus.append(t) +            tmp += V[i] +            if V[i] < 0: +                minus.append(V[i]) -            t = V[N - 1 - j] -            tmp += t -            if t < 0: -                minus.append(t) +            tmp += V[N - j - 1] +            if V[N - j - 1] < 0: +                minus.append(V[N - j - 1])