import numpy as np

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

value = np.array(list(map(int, input().split())))
r_value = value[::-1]

max_value = max(value[0], r_value[0])
for i in range(1, k):
    total_value = 0
    if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value
print(max_value) import numpy as np numpy n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k value = np.array(list(map(int, input().split()))) value np.array(list(map(int, input().split()))) np.array np array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split r_value = value[::-1] r_value value[::-1] value ::-1 -1 max_value = max(value[0], r_value[0]) max_value max(value[0], r_value[0]) max value[0] value 0 r_value[0] r_value 0 for i in range(1, k):
    total_value = 0
    if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value i range(1, k) range 1 k total_value = 0 total_value 0 if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value i > n i n s = value s value s.sort() s.sort s sort s = list(s) s list(s) list s for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
         j range(k-n) range k-n k n if s[0] < 0:
                s.pop(0)
         s[0] < 0 s[0] s 0 0 s.pop(0) s.pop s pop 0 total_value = sum(s) total_value sum(s) sum s for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value j range(i+1) range i+1 i 1 a = value[0:j] a value[0:j] value 0:j 0 j b = r_value[0:i-j] b r_value[0:i-j] r_value 0:i-j 0 i-j i j c = np.concatenate((a, b)) c np.concatenate((a, b)) np.concatenate np concatenate (a, b) a b c.sort() c.sort c sort c = list(c) c list(c) list c for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
             l range(k-i) range k-i k i if c[0] < 0:
                    c.pop(0)
                 c[0] < 0 c[0] c 0 0 c.pop(0) c.pop c pop 0 if c == []:
                    break
             c == [] c [] break total_value = sum(c) total_value sum(c) sum c if total_value > max_value:
                max_value = total_value total_value > max_value total_value max_value max_value = total_value max_value total_value print(max_value) print max_value value = np.array(list(map(int, input().split()))) np.array(list(map(int, input().split()))) value b = r_value[0:i-j] r_value[0:i-j] b c = list(c) list(c) c total_value = sum(c) sum(c) total_value total_value = sum(s) sum(s) total_value max_value = total_value total_value max_value total_value = 0 0 total_value k = map(int, input().split()) map(int, input().split()) k s = list(s) list(s) s n, k = map(int, input().split()) map(int, input().split()) n c = np.concatenate((a, b)) np.concatenate((a, b)) c a = value[0:j] value[0:j] a r_value = value[::-1] value[::-1] r_value s = value value s max_value = max(value[0], r_value[0]) max(value[0], r_value[0]) max_value
import numpy as np

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

value = np.array(list(map(int, input().split())))
r_value = value[::-1]

max_value = max(value[0], r_value[0])
for i in range(1, k):
    total_value = 0
    if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value
print(max_value)