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

#とるか戻すか
ruil=[0]*N
ruil[0]=V[0]

ruir=[0]*N
ruir[0]=V[-1]
for i in range(1,N):
    ruil[i]=ruil[i-1]+V[i]
    ruir[-(i+1)]=ruir[-i]+V[-(i+1)]
#操作何回やるか 0~K
#K回のうちX回とる　K-X回戻す 0~K
#左右の割合　0~X
ans=0
for i in range(K+1):
    if i==0:
        continue
    for j in range(0,i+1):
        if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
        for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k)

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 ruil=[0]*N ruil [0]*N [0] 0 N ruil[0]=V[0] ruil[0] ruil 0 V[0] V 0 ruir=[0]*N ruir [0]*N [0] 0 N ruir[0]=V[-1] ruir[0] ruir 0 V[-1] V -1 for i in range(1,N):
    ruil[i]=ruil[i-1]+V[i]
    ruir[-(i+1)]=ruir[-i]+V[-(i+1)]
#操作何回やるか 0~K
#K回のうちX回とる　K-X回戻す 0~K
#左右の割合　0~X i range(1,N) range 1 N ruil[i]=ruil[i-1]+V[i] ruil[i] ruil i ruil[i-1]+V[i] ruil[i-1] ruil i-1 i 1 V[i] V i ruir[-(i+1)]=ruir[-i]+V[-(i+1)] ruir[-(i+1)] ruir -(i+1) i+1 i 1 ruir[-i]+V[-(i+1)] ruir[-i] ruir -i i V[-(i+1)] V -(i+1) i+1 i 1 ans=0 ans 0 for i in range(K+1):
    if i==0:
        continue
    for j in range(0,i+1):
        if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
        for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k) i range(K+1) range K+1 K 1 if i==0:
        continue
     i==0 i 0 continue for j in range(0,i+1):
        if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
        for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k) j range(0,i+1) range 0 i+1 i 1 if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
         i/2<=j i/2 i 2 j continue for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k) k range(i-j+1) range i-j+1 i-j i j 1 if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
             i-j>=N i-j i j N get=V get V if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
             i-j-k==0 i-j-k i-j i j k 0 get=V[:k] get V[:k] V :k k get=V[:k]+V[-(i-j-k):] get V[:k]+V[-(i-j-k):] V[:k] V :k k V[-(i-j-k):] V -(i-j-k): -(i-j-k) i-j-k i-j i j k get=sorted(get) get sorted(get) sorted get score=sum(get)-sum(get[:j]) score sum(get)-sum(get[:j]) sum(get) sum get sum(get[:j]) sum get[:j] get :j j ans=max(ans, score) ans max(ans, score) max ans score print(ans) print ans ans=max(ans, score) max(ans, score) ans K=map(int, input().split()) map(int, input().split()) K get=V[:k] V[:k] get V=list(map(int, input().split())) list(map(int, input().split())) V ruil=[0]*N [0]*N ruil get=sorted(get) sorted(get) get ans=0 0 ans N,K=map(int, input().split()) map(int, input().split()) N get=V V get score=sum(get)-sum(get[:j]) sum(get)-sum(get[:j]) score ruir=[0]*N [0]*N ruir get=V[:k]+V[-(i-j-k):] V[:k]+V[-(i-j-k):] get
N,K=map(int, input().split())
V=list(map(int, input().split()))

#とるか戻すか
ruil=[0]*N
ruil[0]=V[0]

ruir=[0]*N
ruir[0]=V[-1]
for i in range(1,N):
    ruil[i]=ruil[i-1]+V[i]
    ruir[-(i+1)]=ruir[-i]+V[-(i+1)]
#操作何回やるか 0~K
#K回のうちX回とる　K-X回戻す 0~K
#左右の割合　0~X
ans=0
for i in range(K+1):
    if i==0:
        continue
    for j in range(0,i+1):
        if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
        for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k)

print(ans)

