N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for anum in range(min(N, K) + 1):
    owned = V[:anum]
    for bnum in range(min(N, K) - anum + 1):
        if bnum > 0:
            owned.append(V[-bnum])
        owned.sort()
        cdnum = K - (anum + bnum)
        total = 0
        for v in owned:
            if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
        ans = max(ans, total)
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 ans = 0 ans 0 for anum in range(min(N, K) + 1):
    owned = V[:anum]
    for bnum in range(min(N, K) - anum + 1):
        if bnum > 0:
            owned.append(V[-bnum])
        owned.sort()
        cdnum = K - (anum + bnum)
        total = 0
        for v in owned:
            if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
        ans = max(ans, total) anum range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 owned = V[:anum] owned V[:anum] V :anum anum for bnum in range(min(N, K) - anum + 1):
        if bnum > 0:
            owned.append(V[-bnum])
        owned.sort()
        cdnum = K - (anum + bnum)
        total = 0
        for v in owned:
            if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
        ans = max(ans, total) bnum range(min(N, K) - anum + 1) range min(N, K) - anum + 1 min(N, K) - anum min(N, K) min N K anum 1 if bnum > 0:
            owned.append(V[-bnum])
         bnum > 0 bnum 0 owned.append(V[-bnum]) owned.append owned append V[-bnum] V -bnum bnum owned.sort() owned.sort owned sort cdnum = K - (anum + bnum) cdnum K - (anum + bnum) K anum + bnum anum bnum total = 0 total 0 for v in owned:
            if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
         v owned if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
         v < 0 and 0 < cdnum v < 0 v 0 0 < cdnum 0 cdnum cdnum -= 1 cdnum 1 total += v total v ans = max(ans, total) ans max(ans, total) max ans total print(ans) print ans owned = V[:anum] V[:anum] owned K = map(int, input().split()) map(int, input().split()) K V = list(map(int, input().split())) list(map(int, input().split())) V cdnum -= 1 1 cdnum N, K = map(int, input().split()) map(int, input().split()) N total += v v total ans = 0 0 ans cdnum = K - (anum + bnum) K - (anum + bnum) cdnum ans = max(ans, total) max(ans, total) ans total = 0 0 total
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for anum in range(min(N, K) + 1):
    owned = V[:anum]
    for bnum in range(min(N, K) - anum + 1):
        if bnum > 0:
            owned.append(V[-bnum])
        owned.sort()
        cdnum = K - (anum + bnum)
        total = 0
        for v in owned:
            if v < 0 and 0 < cdnum:
                cdnum -= 1
            else:
                total += v
        ans = max(ans, total)
print(ans)