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

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

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 i in range(n+1):
    for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:])) i range(n+1) range n+1 n 1 for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:])) j range(n+1) range n+1 n 1 if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:])) i + j <= k and i + j <= n i + j <= k i + j i j k i + j <= n i + j i j n g = v[:i] + v[n-j:] g v[:i] + v[n-j:] v[:i] v :i i v[n-j:] v n-j: n-j n j g.sort() g.sort g sort for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:])) l range(min(k-i-j, i+j)+1) range min(k-i-j, i+j)+1 min(k-i-j, i+j) min k-i-j k-i k i j i+j i j 1 ans = max(ans, sum(g[l:])) ans max(ans, sum(g[l:])) max ans sum(g[l:]) sum g[l:] g l: l print(ans) print ans ans = max(ans, sum(g[l:])) max(ans, sum(g[l:])) ans n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k ans = 0 0 ans v = list(map(int, input().split())) list(map(int, input().split())) v g = v[:i] + v[n-j:] v[:i] + v[n-j:] g
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

print(ans)
