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

ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        b = sorted(a[:l] + a[n - r:])
        c = min(k - l - r, len(b) - 1)
        ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b)))
print(ans) n, k, *a = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split k *a a ans = 0 ans 0 for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        b = sorted(a[:l] + a[n - r:])
        c = min(k - l - r, len(b) - 1)
        ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) l range(0, k + 1) range 0 k + 1 k 1 for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        b = sorted(a[:l] + a[n - r:])
        c = min(k - l - r, len(b) - 1)
        ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) r range(0, k + 1 - l) range 0 k + 1 - l k + 1 k 1 l if l == r == 0 or l + r > n:
            continue
         l == r == 0 or l + r > n l == r == 0 l == r l r 0 l + r > n l + r l r n continue b = sorted(a[:l] + a[n - r:]) b sorted(a[:l] + a[n - r:]) sorted a[:l] + a[n - r:] a[:l] a :l l a[n - r:] a n - r: n - r n r c = min(k - l - r, len(b) - 1) c min(k - l - r, len(b) - 1) min k - l - r k - l k l r len(b) - 1 len(b) len b 1 ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) ans max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) max ans sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b)) sum b[c:] if b[c] < 0 else filter(lambda x: x > 0, b) b[c] < 0 b[c] b c 0 b[c:] b c: c filter(lambda x: x > 0, b) filter lambda x: x > 0 x > 0 x 0 x b print(ans) print ans k, *a = map(int, open(0).read().split()) map(int, open(0).read().split()) k b = sorted(a[:l] + a[n - r:]) sorted(a[:l] + a[n - r:]) b c = min(k - l - r, len(b) - 1) min(k - l - r, len(b) - 1) c ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b))) ans ans = 0 0 ans n, k, *a = map(int, open(0).read().split()) map(int, open(0).read().split()) n
n, k, *a = map(int, open(0).read().split())

ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        b = sorted(a[:l] + a[n - r:])
        c = min(k - l - r, len(b) - 1)
        ans = max(ans, sum(b[c:] if b[c] < 0 else filter(lambda x: x > 0, b)))
print(ans)
