n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)+1
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans) n, k = list(map(int, input().split())) n list(map(int, input().split())) list 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 l = 0 l 0 r = 0 r 0 a = 0 a 0 m = min(n, k)+1 m min(n, k)+1 min(n, k) min n k 1 have = [] have [] total = 0 total 0 ans = 0 ans 0 for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total r range(m) range m for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total l range(m-r) range m-r m r have = [] have [] have.append(v[:r]) have.append have append v[:r] v :r r if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
         l != 0 l 0 have.append(v[-l:]) have.append have append v[-l:] v -l: -l l have.append([]) have.append have append [] a = k-l-r a k-l-r k-l k l r data = have[0]+have[1] data have[0]+have[1] have[0] have 0 have[1] have 1 data.sort() data.sort data sort for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
         i range(len(data)) range len(data) len data if i < a and data[i] < 0:
                data[i] = 0
         i < a and data[i] < 0 i < a i a data[i] < 0 data[i] data i 0 data[i] = 0 data[i] data i 0 total = sum(data) total sum(data) sum data if total > ans:
            ans = total total > ans total ans ans = total ans total print(ans) print ans a = k-l-r k-l-r a r = 0 0 r v = list(map(int, input().split())) list(map(int, input().split())) v ans = total total ans total = sum(data) sum(data) total data = have[0]+have[1] have[0]+have[1] data m = min(n, k)+1 min(n, k)+1 m ans = 0 0 ans k = list(map(int, input().split())) list(map(int, input().split())) k n, k = list(map(int, input().split())) list(map(int, input().split())) n l = 0 0 l a = 0 0 a have = [] [] have have = [] [] have total = 0 0 total
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)+1
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)
