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


def get_jewelries(box, left_pop, right_pop):
    if left_pop + right_pop >= len(box):
        return box[:]

    left = box[:left_pop]
    right = box[-right_pop:] if right_pop else []

    return left + right


candidates = []
pop_max = min(k, n)
for pop_count in range(pop_max+1):
    residue = k - pop_count

    for left_pop in range(pop_count+1):
        right_pop = pop_count - left_pop
        jewelries = get_jewelries(V, left_pop, right_pop)
        jewelries.sort(reverse=True)

        for _ in range(residue):
            if not jewelries:
                break
            if jewelries[-1] < 0:
                jewelries.pop()

        value = sum(jewelries)
        candidates.append(value)

print(max(candidates)) 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 def get_jewelries(box, left_pop, right_pop):
    if left_pop + right_pop >= len(box):
        return box[:]

    left = box[:left_pop]
    right = box[-right_pop:] if right_pop else []

    return left + right get_jewelries if left_pop + right_pop >= len(box):
        return box[:]

     left_pop + right_pop >= len(box) left_pop + right_pop left_pop right_pop len(box) len box return box[:] box[:] box : left = box[:left_pop] left box[:left_pop] box :left_pop left_pop right = box[-right_pop:] if right_pop else [] right box[-right_pop:] if right_pop else [] right_pop box[-right_pop:] box -right_pop: -right_pop right_pop [] return left + right left + right left right box box left_pop left_pop right_pop right_pop candidates = [] candidates [] pop_max = min(k, n) pop_max min(k, n) min k n for pop_count in range(pop_max+1):
    residue = k - pop_count

    for left_pop in range(pop_count+1):
        right_pop = pop_count - left_pop
        jewelries = get_jewelries(V, left_pop, right_pop)
        jewelries.sort(reverse=True)

        for _ in range(residue):
            if not jewelries:
                break
            if jewelries[-1] < 0:
                jewelries.pop()

        value = sum(jewelries)
        candidates.append(value) pop_count range(pop_max+1) range pop_max+1 pop_max 1 residue = k - pop_count residue k - pop_count k pop_count for left_pop in range(pop_count+1):
        right_pop = pop_count - left_pop
        jewelries = get_jewelries(V, left_pop, right_pop)
        jewelries.sort(reverse=True)

        for _ in range(residue):
            if not jewelries:
                break
            if jewelries[-1] < 0:
                jewelries.pop()

        value = sum(jewelries)
        candidates.append(value) left_pop range(pop_count+1) range pop_count+1 pop_count 1 right_pop = pop_count - left_pop right_pop pop_count - left_pop pop_count left_pop jewelries = get_jewelries(V, left_pop, right_pop) jewelries get_jewelries(V, left_pop, right_pop) get_jewelries V left_pop right_pop jewelries.sort(reverse=True) jewelries.sort jewelries sort reverse=True reverse True for _ in range(residue):
            if not jewelries:
                break
            if jewelries[-1] < 0:
                jewelries.pop()

         _ range(residue) range residue if not jewelries:
                break
             not jewelries jewelries break if jewelries[-1] < 0:
                jewelries.pop()

         jewelries[-1] < 0 jewelries[-1] jewelries -1 0 jewelries.pop() jewelries.pop jewelries pop value = sum(jewelries) value sum(jewelries) sum jewelries candidates.append(value) candidates.append candidates append value print(max(candidates)) print max(candidates) max candidates residue = k - pop_count k - pop_count residue value = sum(jewelries) sum(jewelries) value V = list(map(int, input().split())) list(map(int, input().split())) V k = map(int, input().split()) map(int, input().split()) k right_pop = pop_count - left_pop pop_count - left_pop right_pop candidates = [] [] candidates pop_max = min(k, n) min(k, n) pop_max def get_jewelries(box, left_pop, right_pop):
    if left_pop + right_pop >= len(box):
        return box[:]

    left = box[:left_pop]
    right = box[-right_pop:] if right_pop else []

    return left + right def get_jewelries(box, left_pop, right_pop):
    if left_pop + right_pop >= len(box):
        return box[:]

    left = box[:left_pop]
    right = box[-right_pop:] if right_pop else []

    return left + right get_jewelries n, k = map(int, input().split()) map(int, input().split()) n jewelries = get_jewelries(V, left_pop, right_pop) get_jewelries(V, left_pop, right_pop) jewelries
n, k = map(int, input().split())
V = list(map(int, input().split()))


def get_jewelries(box, left_pop, right_pop):
    if left_pop + right_pop >= len(box):
        return box[:]

    left = box[:left_pop]
    right = box[-right_pop:] if right_pop else []

    return left + right


candidates = []
pop_max = min(k, n)
for pop_count in range(pop_max+1):
    residue = k - pop_count

    for left_pop in range(pop_count+1):
        right_pop = pop_count - left_pop
        jewelries = get_jewelries(V, left_pop, right_pop)
        jewelries.sort(reverse=True)

        for _ in range(residue):
            if not jewelries:
                break
            if jewelries[-1] < 0:
                jewelries.pop()

        value = sum(jewelries)
        candidates.append(value)

print(max(candidates))
