N,K = map(int,input().split())
V = list(map(int,input().split()))
vmax = 0
for i in range(K+1):
    for j in range(K-i+1):
        cnt = sum(V[:j])
        A = V[:j]
        n = N-(K-i-j)
        if n>=j:
            cnt += sum(V[n:])
            A += V[n:]
        else:
            cnt += sum(V[j:])
            A += V[j:]
        A = sorted(A)
        B = []
        for k in range(i):
            if k<len(A) and A[k]<0:
                B.append(k)
        for k in B:
            cnt -= A[k]
        vmax = max(vmax,cnt)
print(vmax) 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 vmax = 0 vmax 0 for i in range(K+1):
    for j in range(K-i+1):
        cnt = sum(V[:j])
        A = V[:j]
        n = N-(K-i-j)
        if n>=j:
            cnt += sum(V[n:])
            A += V[n:]
        else:
            cnt += sum(V[j:])
            A += V[j:]
        A = sorted(A)
        B = []
        for k in range(i):
            if k<len(A) and A[k]<0:
                B.append(k)
        for k in B:
            cnt -= A[k]
        vmax = max(vmax,cnt) i range(K+1) range K+1 K 1 for j in range(K-i+1):
        cnt = sum(V[:j])
        A = V[:j]
        n = N-(K-i-j)
        if n>=j:
            cnt += sum(V[n:])
            A += V[n:]
        else:
            cnt += sum(V[j:])
            A += V[j:]
        A = sorted(A)
        B = []
        for k in range(i):
            if k<len(A) and A[k]<0:
                B.append(k)
        for k in B:
            cnt -= A[k]
        vmax = max(vmax,cnt) j range(K-i+1) range K-i+1 K-i K i 1 cnt = sum(V[:j]) cnt sum(V[:j]) sum V[:j] V :j j A = V[:j] A V[:j] V :j j n = N-(K-i-j) n N-(K-i-j) N K-i-j K-i K i j if n>=j:
            cnt += sum(V[n:])
            A += V[n:]
        else:
            cnt += sum(V[j:])
            A += V[j:]
         n>=j n j cnt += sum(V[n:]) cnt sum(V[n:]) sum V[n:] V n: n A += V[n:] A V[n:] V n: n cnt += sum(V[j:]) cnt sum(V[j:]) sum V[j:] V j: j A += V[j:] A V[j:] V j: j A = sorted(A) A sorted(A) sorted A B = [] B [] for k in range(i):
            if k<len(A) and A[k]<0:
                B.append(k)
         k range(i) range i if k<len(A) and A[k]<0:
                B.append(k)
         k<len(A) and A[k]<0 k<len(A) k len(A) len A A[k]<0 A[k] A k 0 B.append(k) B.append B append k for k in B:
            cnt -= A[k]
         k B cnt -= A[k] cnt A[k] A k vmax = max(vmax,cnt) vmax max(vmax,cnt) max vmax cnt print(vmax) print vmax A = sorted(A) sorted(A) A vmax = max(vmax,cnt) max(vmax,cnt) vmax A += V[n:] V[n:] A cnt += sum(V[n:]) sum(V[n:]) cnt A += V[j:] V[j:] A K = map(int,input().split()) map(int,input().split()) K A = V[:j] V[:j] A n = N-(K-i-j) N-(K-i-j) n cnt = sum(V[:j]) sum(V[:j]) cnt cnt -= A[k] A[k] cnt N,K = map(int,input().split()) map(int,input().split()) N vmax = 0 0 vmax cnt += sum(V[j:]) sum(V[j:]) cnt V = list(map(int,input().split())) list(map(int,input().split())) V B = [] [] B
N,K = map(int,input().split())
V = list(map(int,input().split()))
vmax = 0
for i in range(K+1):
    for j in range(K-i+1):
        cnt = sum(V[:j])
        A = V[:j]
        n = N-(K-i-j)
        if n>=j:
            cnt += sum(V[n:])
            A += V[n:]
        else:
            cnt += sum(V[j:])
            A += V[j:]
        A = sorted(A)
        B = []
        for k in range(i):
            if k<len(A) and A[k]<0:
                B.append(k)
        for k in B:
            cnt -= A[k]
        vmax = max(vmax,cnt)
print(vmax)