n, k = map(int, input().split())
v = list(map(int, input().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
        a = sorted(v[:l] + v[n - r:])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a)))
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 l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        a = sorted(v[:l] + v[n - r:])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) 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
        a = sorted(v[:l] + v[n - r:])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) 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 a = sorted(v[:l] + v[n - r:]) a sorted(v[:l] + v[n - r:]) sorted v[:l] + v[n - r:] v[:l] v :l l v[n - r:] v n - r: n - r n r m = min(k - l - r, len(a) - 1) m min(k - l - r, len(a) - 1) min k - l - r k - l k l r len(a) - 1 len(a) len a 1 ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) ans max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) max ans sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a)) sum a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a) a[m] <
                           0 a[m] a m 0 a[m:] a m: m filter(lambda x: x > 0, a) filter lambda x: x > 0 x > 0 x 0 x a print(ans) print ans ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a))) ans v = list(map(int, input().split())) list(map(int, input().split())) v m = min(k - l - r, len(a) - 1) min(k - l - r, len(a) - 1) m a = sorted(v[:l] + v[n - r:]) sorted(v[:l] + v[n - r:]) a 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
n, k = map(int, input().split())
v = list(map(int, input().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
        a = sorted(v[:l] + v[n - r:])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] <
                           0 else filter(lambda x: x > 0, a)))
print(ans)