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

if k <= n:
    ans = - 10 ** 9
    for i in range(k + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort()
            ans = max(ans, sum(tmp[k - i:]))
            if k != i:
                ans = max(ans, sum(tmp[k - i - 1:]))

elif k >= 2 * n:
    v.sort(reverse = True)
    ans = 0
    for num in v:
        if num <= 0:
            break
        ans += num

else:
    ans = - 10 ** 9
    for i in range(n + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort(reverse = True)
            ans_tmp = 0
            for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
            ans = max(ans, ans_tmp)

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 if k <= n:
    ans = - 10 ** 9
    for i in range(k + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort()
            ans = max(ans, sum(tmp[k - i:]))
            if k != i:
                ans = max(ans, sum(tmp[k - i - 1:]))

elif k >= 2 * n:
    v.sort(reverse = True)
    ans = 0
    for num in v:
        if num <= 0:
            break
        ans += num

else:
    ans = - 10 ** 9
    for i in range(n + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort(reverse = True)
            ans_tmp = 0
            for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
            ans = max(ans, ans_tmp) k <= n k n ans = - 10 ** 9 ans - 10 ** 9 - 10 9 for i in range(k + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort()
            ans = max(ans, sum(tmp[k - i:]))
            if k != i:
                ans = max(ans, sum(tmp[k - i - 1:])) i range(k + 1) range k + 1 k 1 for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort()
            ans = max(ans, sum(tmp[k - i:]))
            if k != i:
                ans = max(ans, sum(tmp[k - i - 1:])) j range(i + 1) range i + 1 i 1 tmp = v[:j] tmp v[:j] v :j j if i != j:
                tmp += v[-(i - j):]
             i != j i j tmp += v[-(i - j):] tmp v[-(i - j):] v -(i - j): -(i - j) i - j i j tmp.sort() tmp.sort tmp sort ans = max(ans, sum(tmp[k - i:])) ans max(ans, sum(tmp[k - i:])) max ans sum(tmp[k - i:]) sum tmp[k - i:] tmp k - i: k - i k i if k != i:
                ans = max(ans, sum(tmp[k - i - 1:])) k != i k i ans = max(ans, sum(tmp[k - i - 1:])) ans max(ans, sum(tmp[k - i - 1:])) max ans sum(tmp[k - i - 1:]) sum tmp[k - i - 1:] tmp k - i - 1: k - i - 1 k - i k i 1 elif k >= 2 * n:
    v.sort(reverse = True)
    ans = 0
    for num in v:
        if num <= 0:
            break
        ans += num k >= 2 * n k 2 * n 2 n v.sort(reverse = True) v.sort v sort reverse = True reverse True ans = 0 ans 0 for num in v:
        if num <= 0:
            break
        ans += num num v if num <= 0:
            break
         num <= 0 num 0 break ans += num ans num ans = - 10 ** 9 ans - 10 ** 9 - 10 9 for i in range(n + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort(reverse = True)
            ans_tmp = 0
            for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
            ans = max(ans, ans_tmp) i range(n + 1) range n + 1 n 1 for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort(reverse = True)
            ans_tmp = 0
            for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
            ans = max(ans, ans_tmp) j range(i + 1) range i + 1 i 1 tmp = v[:j] tmp v[:j] v :j j if i != j:
                tmp += v[-(i - j):]
             i != j i j tmp += v[-(i - j):] tmp v[-(i - j):] v -(i - j): -(i - j) i - j i j tmp.sort(reverse = True) tmp.sort tmp sort reverse = True reverse True ans_tmp = 0 ans_tmp 0 for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
             l num enumerate(tmp) enumerate tmp if l >= 2 * i - k and num <= 0:
                    break
                 l >= 2 * i - k and num <= 0 l >= 2 * i - k l 2 * i - k 2 * i 2 i k num <= 0 num 0 break ans_tmp += num ans_tmp num ans = max(ans, ans_tmp) ans max(ans, ans_tmp) max ans ans_tmp print(ans) print ans tmp += v[-(i - j):] v[-(i - j):] tmp ans = max(ans, sum(tmp[k - i:])) max(ans, sum(tmp[k - i:])) ans ans = - 10 ** 9 - 10 ** 9 ans tmp = v[:j] v[:j] tmp ans_tmp += num num ans_tmp ans_tmp = 0 0 ans_tmp n, k = map(int, input().split()) map(int, input().split()) n tmp = v[:j] v[:j] tmp tmp += v[-(i - j):] v[-(i - j):] tmp ans = max(ans, sum(tmp[k - i - 1:])) max(ans, sum(tmp[k - i - 1:])) ans ans = - 10 ** 9 - 10 ** 9 ans ans += num num ans ans = 0 0 ans v = list(map(int, input().split())) list(map(int, input().split())) v ans = max(ans, ans_tmp) max(ans, ans_tmp) ans k = map(int, input().split()) map(int, input().split()) k
n, k = map(int, input().split())
v = list(map(int, input().split()))

if k <= n:
    ans = - 10 ** 9
    for i in range(k + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort()
            ans = max(ans, sum(tmp[k - i:]))
            if k != i:
                ans = max(ans, sum(tmp[k - i - 1:]))

elif k >= 2 * n:
    v.sort(reverse = True)
    ans = 0
    for num in v:
        if num <= 0:
            break
        ans += num

else:
    ans = - 10 ** 9
    for i in range(n + 1):
        for j in range(i + 1):
            tmp = v[:j]
            if i != j:
                tmp += v[-(i - j):]
            tmp.sort(reverse = True)
            ans_tmp = 0
            for l, num in enumerate(tmp):
                if l >= 2 * i - k and num <= 0:
                    break
                ans_tmp += num
            ans = max(ans, ans_tmp)

print(ans)
