n,k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for x in range(k+1):# LeftHand
  for y in range(k-x+1):# RightHand
    temp = v[:x]+v[len(v)-y:]
    if x+y >= n:
      temp = v
    temp1 = []
    temp2 = []
    for i in temp:
      if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

    temp2.sort()
    ans = max(ans, sum(temp1) + sum(temp2[k-x-y:]))
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 x in range(k+1):# LeftHand
  for y in range(k-x+1):# RightHand
    temp = v[:x]+v[len(v)-y:]
    if x+y >= n:
      temp = v
    temp1 = []
    temp2 = []
    for i in temp:
      if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

    temp2.sort()
    ans = max(ans, sum(temp1) + sum(temp2[k-x-y:])) x range(k+1) range k+1 k 1 for y in range(k-x+1):# RightHand
    temp = v[:x]+v[len(v)-y:]
    if x+y >= n:
      temp = v
    temp1 = []
    temp2 = []
    for i in temp:
      if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

    temp2.sort()
    ans = max(ans, sum(temp1) + sum(temp2[k-x-y:])) y range(k-x+1) range k-x+1 k-x k x 1 temp = v[:x]+v[len(v)-y:] temp v[:x]+v[len(v)-y:] v[:x] v :x x v[len(v)-y:] v len(v)-y: len(v)-y len(v) len v y if x+y >= n:
      temp = v
     x+y >= n x+y x y n temp = v temp v temp1 = [] temp1 [] temp2 = [] temp2 [] for i in temp:
      if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

     i temp if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

     i >= 0 i 0 temp1.append(i) temp1.append temp1 append i temp2.append(i) temp2.append temp2 append i temp2.sort() temp2.sort temp2 sort ans = max(ans, sum(temp1) + sum(temp2[k-x-y:])) ans max(ans, sum(temp1) + sum(temp2[k-x-y:])) max ans sum(temp1) + sum(temp2[k-x-y:]) sum(temp1) sum temp1 sum(temp2[k-x-y:]) sum temp2[k-x-y:] temp2 k-x-y: k-x-y k-x k x y print(ans) print ans v = list(map(int, input().split())) list(map(int, input().split())) v ans = 0 0 ans temp = v v temp n,k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k ans = max(ans, sum(temp1) + sum(temp2[k-x-y:])) max(ans, sum(temp1) + sum(temp2[k-x-y:])) ans temp2 = [] [] temp2 temp = v[:x]+v[len(v)-y:] v[:x]+v[len(v)-y:] temp temp1 = [] [] temp1
n,k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for x in range(k+1):# LeftHand
  for y in range(k-x+1):# RightHand
    temp = v[:x]+v[len(v)-y:]
    if x+y >= n:
      temp = v
    temp1 = []
    temp2 = []
    for i in temp:
      if i >= 0:
        temp1.append(i)
      else:
        temp2.append(i)

    temp2.sort()
    ans = max(ans, sum(temp1) + sum(temp2[k-x-y:]))
print(ans)