n, k = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for L in range(k+1):
    for R in range(k-L+1):
        if n < L+R:
            break
        val = 0
        neg = []
        for i in range(L):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        for i in range(n-1, n-1-R, -1):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        neg.sort()
        val -= sum(neg[:k-L-R])
        if ans < val:
            ans = val
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(k+1):
    for R in range(k-L+1):
        if n < L+R:
            break
        val = 0
        neg = []
        for i in range(L):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        for i in range(n-1, n-1-R, -1):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        neg.sort()
        val -= sum(neg[:k-L-R])
        if ans < val:
            ans = val L range(k+1) range k+1 k 1 for R in range(k-L+1):
        if n < L+R:
            break
        val = 0
        neg = []
        for i in range(L):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        for i in range(n-1, n-1-R, -1):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        neg.sort()
        val -= sum(neg[:k-L-R])
        if ans < val:
            ans = val R range(k-L+1) range k-L+1 k-L k L 1 if n < L+R:
            break
         n < L+R n L+R L R break val = 0 val 0 neg = [] neg [] for i in range(L):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
         i range(L) range L val += V[i] val V[i] V i if V[i] < 0:
                neg.append(V[i])
         V[i] < 0 V[i] V i 0 neg.append(V[i]) neg.append neg append V[i] V i for i in range(n-1, n-1-R, -1):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
         i range(n-1, n-1-R, -1) range n-1 n 1 n-1-R n-1 n 1 R -1 val += V[i] val V[i] V i if V[i] < 0:
                neg.append(V[i])
         V[i] < 0 V[i] V i 0 neg.append(V[i]) neg.append neg append V[i] V i neg.sort() neg.sort neg sort val -= sum(neg[:k-L-R]) val sum(neg[:k-L-R]) sum neg[:k-L-R] neg :k-L-R k-L-R k-L k L R if ans < val:
            ans = val ans < val ans val ans = val ans val print(ans) print ans val = 0 0 val ans = 0 0 ans neg = [] [] neg ans = val val ans val += V[i] V[i] val V = list(map(int, input().split())) list(map(int, input().split())) V n, k = map(int, input().split()) map(int, input().split()) n val += V[i] V[i] val val -= sum(neg[:k-L-R]) sum(neg[:k-L-R]) val k = map(int, input().split()) map(int, input().split()) k
n, k = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for L in range(k+1):
    for R in range(k-L+1):
        if n < L+R:
            break
        val = 0
        neg = []
        for i in range(L):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        for i in range(n-1, n-1-R, -1):
            val += V[i]
            if V[i] < 0:
                neg.append(V[i])
        neg.sort()
        val -= sum(neg[:k-L-R])
        if ans < val:
            ans = val
print(ans)