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

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

ret = 0

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

    for r in range(min(n, k) - l + 1):

        d = k - l - r

        g = sorted(v[:l] + v[n - r:])

        for i in range(min(d, len(g))):

            g[i] = max(0, g[i])

        ret = max(ret, sum(g))

print(ret)

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

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

ret = 0

for s in range(n):

    for e in range(s, n + 1):

        t = k - (s + n - e)

        if t < 0:

            continue

        l = sorted(v[:s] + v[e:])

        u = 0

        while u < len(l) and u < t and l[u] < 0:

            u += 1

        ret = max(ret, sum(l[u:]))

print(ret)
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ret = 0
for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        d = k - l - r
        g = sorted(v[:l] + v[n - r :])
        for i in range(min(d, len(g))):
            g[i] = max(0, g[i])
        ret = max(ret, sum(g))
print(ret)

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ret = 0
for s in range(n):
    for e in range(s, n + 1):
        t = k - (s + n - e)
        if t < 0:
            continue
        l = sorted(v[:s] + v[e:])
        u = 0
        while u < len(l) and u < t and l[u] < 0:
            u += 1
        ret = max(ret, sum(l[u:]))
print(ret)

-for l in range(min(n, k) + 1): -    for r in range(min(n, k) - l + 1): -        d = k - l - r -        g = sorted(v[:l] + v[n - r :]) -        for i in range(min(d, len(g))): -            g[i] = max(0, g[i]) -        ret = max(ret, sum(g)) +for s in range(n): +    for e in range(s, n + 1): +        t = k - (s + n - e) +        if t < 0: +            continue +        l = sorted(v[:s] + v[e:]) +        u = 0 +        while u < len(l) and u < t and l[u] < 0: +            u += 1 +        ret = max(ret, sum(l[u:]))