n, k = map(int, input().split())
v = list(map(int, input().split()))
reverse_v = v[::-1]
lst = [0] * (k + 1)
left = [[]]
right = [[]]
for i in range(1, n+1):
  left.append(v[:i])
  right.append(reverse_v[:i])

for cnt in range(1, k+1):
  rest = k - cnt
  total = 0
  if cnt <= n:
    for j in range(cnt+1):
      lst_j = left[j] + right[cnt-j]
      lst_j.sort()
      l = cnt
      for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
      if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
      if value > total:
        total = value
    lst[cnt] = total

ans = max(lst)
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 reverse_v = v[::-1] reverse_v v[::-1] v ::-1 -1 lst = [0] * (k + 1) lst [0] * (k + 1) [0] 0 k + 1 k 1 left = [[]] left [[]] [] right = [[]] right [[]] [] for i in range(1, n+1):
  left.append(v[:i])
  right.append(reverse_v[:i]) i range(1, n+1) range 1 n+1 n 1 left.append(v[:i]) left.append left append v[:i] v :i i right.append(reverse_v[:i]) right.append right append reverse_v[:i] reverse_v :i i for cnt in range(1, k+1):
  rest = k - cnt
  total = 0
  if cnt <= n:
    for j in range(cnt+1):
      lst_j = left[j] + right[cnt-j]
      lst_j.sort()
      l = cnt
      for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
      if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
      if value > total:
        total = value
    lst[cnt] = total cnt range(1, k+1) range 1 k+1 k 1 rest = k - cnt rest k - cnt k cnt total = 0 total 0 if cnt <= n:
    for j in range(cnt+1):
      lst_j = left[j] + right[cnt-j]
      lst_j.sort()
      l = cnt
      for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
      if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
      if value > total:
        total = value
    lst[cnt] = total cnt <= n cnt n for j in range(cnt+1):
      lst_j = left[j] + right[cnt-j]
      lst_j.sort()
      l = cnt
      for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
      if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
      if value > total:
        total = value
     j range(cnt+1) range cnt+1 cnt 1 lst_j = left[j] + right[cnt-j] lst_j left[j] + right[cnt-j] left[j] left j right[cnt-j] right cnt-j cnt j lst_j.sort() lst_j.sort lst_j sort l = cnt l cnt for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
       idx range(cnt) range cnt if lst_j[idx] >= 0:
          l = idx
          break
       lst_j[idx] >= 0 lst_j[idx] lst_j idx 0 l = idx l idx break if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
       l == cnt l cnt value = 0 value 0 flg = min(l, rest) flg min(l, rest) min l rest value = sum(lst_j[flg:]) value sum(lst_j[flg:]) sum lst_j[flg:] lst_j flg: flg if value > total:
        total = value
     value > total value total total = value total value lst[cnt] = total lst[cnt] lst cnt total ans = max(lst) ans max(lst) max lst print(ans) print ans l = cnt cnt l flg = min(l, rest) min(l, rest) flg n, k = map(int, input().split()) map(int, input().split()) n value = sum(lst_j[flg:]) sum(lst_j[flg:]) value left = [[]] [[]] left reverse_v = v[::-1] v[::-1] reverse_v lst = [0] * (k + 1) [0] * (k + 1) lst total = 0 0 total total = value value total k = map(int, input().split()) map(int, input().split()) k v = list(map(int, input().split())) list(map(int, input().split())) v l = idx idx l value = 0 0 value lst_j = left[j] + right[cnt-j] left[j] + right[cnt-j] lst_j rest = k - cnt k - cnt rest ans = max(lst) max(lst) ans right = [[]] [[]] right
n, k = map(int, input().split())
v = list(map(int, input().split()))
reverse_v = v[::-1]
lst = [0] * (k + 1)
left = [[]]
right = [[]]
for i in range(1, n+1):
  left.append(v[:i])
  right.append(reverse_v[:i])

for cnt in range(1, k+1):
  rest = k - cnt
  total = 0
  if cnt <= n:
    for j in range(cnt+1):
      lst_j = left[j] + right[cnt-j]
      lst_j.sort()
      l = cnt
      for idx in range(cnt):
        if lst_j[idx] >= 0:
          l = idx
          break
      if l == cnt:
        value = 0
      else:
        flg = min(l, rest)
        value = sum(lst_j[flg:])
      if value > total:
        total = value
    lst[cnt] = total

ans = max(lst)
print(ans)