def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main() def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans) main n, k, *v = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split k *v v w = v[::-1] w v[::-1] v ::-1 -1 ans = 0 ans 0 m = min(n, k) m min(n, k) min n k for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

     i range(m + 1) range m + 1 m 1 for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

     j range(m + 1 - i) range m + 1 - i m + 1 m 1 i d = k - (i + j) d k - (i + j) k i + j i j g = v[:i] + w[:j] g v[:i] + w[:j] v[:i] v :i i w[:j] w :j j ps = sum(x for x in g if x > 0) ps sum(x for x in g if x > 0) sum x x for x in g if x < 0 for x in g if x < 0 x g x < 0 x 0 if x < 0 x ng = [x for x in g if x < 0] ng [x for x in g if x < 0] ng.sort() ng.sort ng sort val = ps + sum(ng[d:]) val ps + sum(ng[d:]) ps sum(ng[d:]) sum ng[d:] ng d: d ans = max(ans, val) ans max(ans, val) max ans val print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans) def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans) main
def main():
    n, k, *v = map(int, open(0).read().split())
    w = v[::-1]

    ans = 0
    m = min(n, k)
    for i in range(m + 1):
        for j in range(m + 1 - i):
            d = k - (i + j)
            g = v[:i] + w[:j]
            ps = sum(x for x in g if x > 0)
            ng = [x for x in g if x < 0]
            ng.sort()
            val = ps + sum(ng[d:])
            ans = max(ans, val)

    print(ans)


if __name__ == '__main__':
    main()
