import bisect

abcd = []
n, k = map(int, input().split()) 
v_list = list(map(int, input().split())) 

for a in range(0, k+1):
    for b in range(0, k+1-a):
        for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d])


ans = 0
for curr_abcd in abcd:
    a,b,c,d = curr_abcd
    cd = c+d
    if a + b >= n:
        have = sorted(v_list)
    else:
        have = sorted(v_list[0:a] + v_list[n-b:n]) 

    minus_cnt = bisect.bisect_right(have,0)
    have = have[ min(minus_cnt, cd) : ]
    curr_sum = sum(have) 
    ans = max(ans, curr_sum)

print(ans) import bisect bisect abcd = [] abcd [] n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v_list = list(map(int, input().split())) v_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for a in range(0, k+1):
    for b in range(0, k+1-a):
        for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d]) a range(0, k+1) range 0 k+1 k 1 for b in range(0, k+1-a):
        for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d]) b range(0, k+1-a) range 0 k+1-a k+1 k 1 a for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d]) c range(0, k+1-a-b) range 0 k+1-a-b k+1-a k+1 k 1 a b d = k-a-b-c d k-a-b-c k-a-b k-a k a b c abcd.append([a,b,c,d]) abcd.append abcd append [a,b,c,d] a b c d ans = 0 ans 0 for curr_abcd in abcd:
    a,b,c,d = curr_abcd
    cd = c+d
    if a + b >= n:
        have = sorted(v_list)
    else:
        have = sorted(v_list[0:a] + v_list[n-b:n]) 

    minus_cnt = bisect.bisect_right(have,0)
    have = have[ min(minus_cnt, cd) : ]
    curr_sum = sum(have) 
    ans = max(ans, curr_sum) curr_abcd abcd a,b,c,d = curr_abcd a curr_abcd b c d cd = c+d cd c+d c d if a + b >= n:
        have = sorted(v_list)
    else:
        have = sorted(v_list[0:a] + v_list[n-b:n]) 

     a + b >= n a + b a b n have = sorted(v_list) have sorted(v_list) sorted v_list have = sorted(v_list[0:a] + v_list[n-b:n]) have sorted(v_list[0:a] + v_list[n-b:n]) sorted v_list[0:a] + v_list[n-b:n] v_list[0:a] v_list 0:a 0 a v_list[n-b:n] v_list n-b:n n-b n b n minus_cnt = bisect.bisect_right(have,0) minus_cnt bisect.bisect_right(have,0) bisect.bisect_right bisect bisect_right have 0 have = have[ min(minus_cnt, cd) : ] have have[ min(minus_cnt, cd) : ] have min(minus_cnt, cd) : min(minus_cnt, cd) min minus_cnt cd curr_sum = sum(have) curr_sum sum(have) sum have ans = max(ans, curr_sum) ans max(ans, curr_sum) max ans curr_sum print(ans) print ans ans = 0 0 ans n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k abcd = [] [] abcd cd = c+d c+d cd a,b,c,d = curr_abcd curr_abcd a d = curr_abcd curr_abcd d minus_cnt = bisect.bisect_right(have,0) bisect.bisect_right(have,0) minus_cnt curr_sum = sum(have) sum(have) curr_sum have = have[ min(minus_cnt, cd) : ] have[ min(minus_cnt, cd) : ] have have = sorted(v_list[0:a] + v_list[n-b:n]) sorted(v_list[0:a] + v_list[n-b:n]) have v_list = list(map(int, input().split())) list(map(int, input().split())) v_list c,d = curr_abcd curr_abcd c have = sorted(v_list) sorted(v_list) have b,c,d = curr_abcd curr_abcd b ans = max(ans, curr_sum) max(ans, curr_sum) ans d = k-a-b-c k-a-b-c d
import bisect

abcd = []
n, k = map(int, input().split()) 
v_list = list(map(int, input().split())) 

for a in range(0, k+1):
    for b in range(0, k+1-a):
        for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d])


ans = 0
for curr_abcd in abcd:
    a,b,c,d = curr_abcd
    cd = c+d
    if a + b >= n:
        have = sorted(v_list)
    else:
        have = sorted(v_list[0:a] + v_list[n-b:n]) 

    minus_cnt = bisect.bisect_right(have,0)
    have = have[ min(minus_cnt, cd) : ]
    curr_sum = sum(have) 
    ans = max(ans, curr_sum)

print(ans)