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

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i+j>k: continue
        cand = sorted([v[I] for I in range(n) if I<i or n-j<=I])
        cnt = sum(cand)
        ans = max(ans, cnt)
        for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt)
print(ans) n, k, *v = 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 *v v ans = 0 ans 0 for i in range(n+1):
    for j in range(n+1):
        if i+j>k: continue
        cand = sorted([v[I] for I in range(n) if I<i or n-j<=I])
        cnt = sum(cand)
        ans = max(ans, cnt)
        for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt) i range(n+1) range n+1 n 1 for j in range(n+1):
        if i+j>k: continue
        cand = sorted([v[I] for I in range(n) if I<i or n-j<=I])
        cnt = sum(cand)
        ans = max(ans, cnt)
        for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt) j range(n+1) range n+1 n 1 if i+j>k: continue
         i+j>k i+j i j k v[I] for I in range(n) if I<i or n-j<=I for I in range(n) if I<i or n-j<=I I range(n) range n I<i or n-j<=I I<i I i n-j<=I n-j n j I if I<i or n-j<=I v[I] v I cand = sorted([v[I] for I in range(n) if I<i or n-j<=I]) cand sorted([v[I] for I in range(n) if I<i or n-j<=I]) sorted [v[I] for I in range(n) if I<i or n-j<=I] cnt = sum(cand) cnt sum(cand) sum cand ans = max(ans, cnt) ans max(ans, cnt) max ans cnt for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt) l range(min(k-i-j, len(cand))) range min(k-i-j, len(cand)) min k-i-j k-i k i j len(cand) len cand cnt -= cand[l] cnt cand[l] cand l ans = max(ans, cnt) ans max(ans, cnt) max ans cnt print(ans) print ans ans = max(ans, cnt) max(ans, cnt) ans k, *v = map(int, open(0).read().split()) map(int, open(0).read().split()) k n, k, *v = map(int, open(0).read().split()) map(int, open(0).read().split()) n ans = 0 0 ans cnt = sum(cand) sum(cand) cnt cnt -= cand[l] cand[l] cnt cand = sorted([v[I] for I in range(n) if I<i or n-j<=I]) sorted([v[I] for I in range(n) if I<i or n-j<=I]) cand ans = max(ans, cnt) max(ans, cnt) ans
n, k, *v = map(int, open(0).read().split())

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i+j>k: continue
        cand = sorted([v[I] for I in range(n) if I<i or n-j<=I])
        cnt = sum(cand)
        ans = max(ans, cnt)
        for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt)
print(ans)