N,K = map(int,input().split())
V = list(map(int,input().split()))
max_cnt = -float('inf')
for k in range(min(N,K)+1):
  for i in range(k+1):
    j = k - i
    le = V[:i]
    ri = V[-j:] if j > 0 else []
    ne = [i for i in le if i < 0]+[j for j in ri if j < 0]
    ne.sort()
    max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt)
    
print(max_cnt) 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 max_cnt = -float('inf') max_cnt -float('inf') float('inf') float 'inf' for k in range(min(N,K)+1):
  for i in range(k+1):
    j = k - i
    le = V[:i]
    ri = V[-j:] if j > 0 else []
    ne = [i for i in le if i < 0]+[j for j in ri if j < 0]
    ne.sort()
    max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt)
     k range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 for i in range(k+1):
    j = k - i
    le = V[:i]
    ri = V[-j:] if j > 0 else []
    ne = [i for i in le if i < 0]+[j for j in ri if j < 0]
    ne.sort()
    max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt)
     i range(k+1) range k+1 k 1 j = k - i j k - i k i le = V[:i] le V[:i] V :i i ri = V[-j:] if j > 0 else [] ri V[-j:] if j > 0 else [] j > 0 j 0 V[-j:] V -j: -j j [] i for i in le if i < 0 for i in le if i < 0 i le i < 0 i 0 if i < 0 i ne = [i for i in le if i < 0]+[j for j in ri if j < 0] ne [i for i in le if i < 0]+[j for j in ri if j < 0] [i for i in le if i < 0] [j for j in ri if j < 0] ne.sort() ne.sort ne sort max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt) max_cnt max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt) max sum(le)+sum(ri) - sum(ne[:K-k]) sum(le)+sum(ri) sum(le) sum le sum(ri) sum ri sum(ne[:K-k]) sum ne[:K-k] ne :K-k K-k K k max_cnt print(max_cnt) print max_cnt K = map(int,input().split()) map(int,input().split()) K j = k - i k - i j ne = [i for i in le if i < 0]+[j for j in ri if j < 0] [i for i in le if i < 0]+[j for j in ri if j < 0] ne max_cnt = -float('inf') -float('inf') max_cnt V = list(map(int,input().split())) list(map(int,input().split())) V le = V[:i] V[:i] le ri = V[-j:] if j > 0 else [] V[-j:] if j > 0 else [] ri max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt) max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt) max_cnt N,K = map(int,input().split()) map(int,input().split()) N
N,K = map(int,input().split())
V = list(map(int,input().split()))
max_cnt = -float('inf')
for k in range(min(N,K)+1):
  for i in range(k+1):
    j = k - i
    le = V[:i]
    ri = V[-j:] if j > 0 else []
    ne = [i for i in le if i < 0]+[j for j in ri if j < 0]
    ne.sort()
    max_cnt = max(sum(le)+sum(ri) - sum(ne[:K-k]),max_cnt)
    
print(max_cnt)