N, K = map(int, input().split())
V = list(map(int, input().split()))

max_ = 0
for a in range(K + 1):
    for b in range(K - a + 1):
        if a + b > N:
            continue

        jwl = V[:a]
        jwl += V[N - b:]
        rmv = K - (a + b)
        jwl.sort()

        sum_ = sum(jwl)
        for i in range(min(rmv, len(jwl))):
            if jwl[i] >= 0:
                break

            sum_ -= jwl[i]

        max_ = max(max_, sum_)


print(max_) 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 max_ = 0 max_ 0 for a in range(K + 1):
    for b in range(K - a + 1):
        if a + b > N:
            continue

        jwl = V[:a]
        jwl += V[N - b:]
        rmv = K - (a + b)
        jwl.sort()

        sum_ = sum(jwl)
        for i in range(min(rmv, len(jwl))):
            if jwl[i] >= 0:
                break

            sum_ -= jwl[i]

        max_ = max(max_, sum_) a range(K + 1) range K + 1 K 1 for b in range(K - a + 1):
        if a + b > N:
            continue

        jwl = V[:a]
        jwl += V[N - b:]
        rmv = K - (a + b)
        jwl.sort()

        sum_ = sum(jwl)
        for i in range(min(rmv, len(jwl))):
            if jwl[i] >= 0:
                break

            sum_ -= jwl[i]

        max_ = max(max_, sum_) b range(K - a + 1) range K - a + 1 K - a K a 1 if a + b > N:
            continue

         a + b > N a + b a b N continue jwl = V[:a] jwl V[:a] V :a a jwl += V[N - b:] jwl V[N - b:] V N - b: N - b N b rmv = K - (a + b) rmv K - (a + b) K a + b a b jwl.sort() jwl.sort jwl sort sum_ = sum(jwl) sum_ sum(jwl) sum jwl for i in range(min(rmv, len(jwl))):
            if jwl[i] >= 0:
                break

            sum_ -= jwl[i]

         i range(min(rmv, len(jwl))) range min(rmv, len(jwl)) min rmv len(jwl) len jwl if jwl[i] >= 0:
                break

             jwl[i] >= 0 jwl[i] jwl i 0 break sum_ -= jwl[i] sum_ jwl[i] jwl i max_ = max(max_, sum_) max_ max(max_, sum_) max max_ sum_ print(max_) print max_ max_ = 0 0 max_ sum_ = sum(jwl) sum(jwl) sum_ K = map(int, input().split()) map(int, input().split()) K rmv = K - (a + b) K - (a + b) rmv jwl += V[N - b:] V[N - b:] jwl V = list(map(int, input().split())) list(map(int, input().split())) V sum_ -= jwl[i] jwl[i] sum_ N, K = map(int, input().split()) map(int, input().split()) N jwl = V[:a] V[:a] jwl max_ = max(max_, sum_) max(max_, sum_) max_
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_ = 0
for a in range(K + 1):
    for b in range(K - a + 1):
        if a + b > N:
            continue

        jwl = V[:a]
        jwl += V[N - b:]
        rmv = K - (a + b)
        jwl.sort()

        sum_ = sum(jwl)
        for i in range(min(rmv, len(jwl))):
            if jwl[i] >= 0:
                break

            sum_ -= jwl[i]

        max_ = max(max_, sum_)


print(max_)
