n,k=map(int,input().split())
*q,=map(int,input().split())

ans=0
for i in range(1,k+1): # iは抜き取り回数
    if i<n:
        for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
    else:
        for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp)
print(ans) n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k *q,=map(int,input().split()) *q q map(int,input().split()) map int input().split() ().split () input split ans=0 ans 0 for i in range(1,k+1): # iは抜き取り回数
    if i<n:
        for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
    else:
        for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp) i range(1,k+1) range 1 k+1 k 1 if i<n:
        for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
    else:
        for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp) i<n i n for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
     left range(0,i+1) range 0 i+1 i 1 tmp=0 tmp 0 tmpq=[] tmpq [] right=i-left right i-left i left if right==0:
                right=-n
             right==0 right 0 right=-n right -n n tmpq+=q[:left]+q[-right:] tmpq q[:left]+q[-right:] q[:left] q :left left q[-right:] q -right: -right right tmp+=sum(tmpq) tmp sum(tmpq) sum tmpq x for x in tmpq if x<0 for x in tmpq if x<0 x tmpq x<0 x 0 if x<0 x tmpq=[x for x in tmpq if x<0] tmpq [x for x in tmpq if x<0] tmpq=sorted(tmpq) tmpq sorted(tmpq) sorted tmpq tmp-=sum(tmpq[:min(k-i, len(tmpq))]) tmp sum(tmpq[:min(k-i, len(tmpq))]) sum tmpq[:min(k-i, len(tmpq))] tmpq :min(k-i, len(tmpq)) min(k-i, len(tmpq)) min k-i k i len(tmpq) len tmpq ans=max(ans,tmp) ans max(ans,tmp) max ans tmp for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp) left range(0,n+1) range 0 n+1 n 1 tmp=0 tmp 0 tmpq=[] tmpq [] right=n-left right n-left n left if right==0:
                right=-n
             right==0 right 0 right=-n right -n n tmpq+=q[:left]+q[-right:] tmpq q[:left]+q[-right:] q[:left] q :left left q[-right:] q -right: -right right tmp+=sum(tmpq) tmp sum(tmpq) sum tmpq x for x in tmpq if x<0 for x in tmpq if x<0 x tmpq x<0 x 0 if x<0 x tmpq=[x for x in tmpq if x<0] tmpq [x for x in tmpq if x<0] tmpq=sorted(tmpq) tmpq sorted(tmpq) sorted tmpq tmp-=sum(tmpq[:min(i-n, len(tmpq))]) tmp sum(tmpq[:min(i-n, len(tmpq))]) sum tmpq[:min(i-n, len(tmpq))] tmpq :min(i-n, len(tmpq)) min(i-n, len(tmpq)) min i-n i n len(tmpq) len tmpq ans=max(ans,tmp) ans max(ans,tmp) max ans tmp print(ans) print ans tmp+=sum(tmpq) sum(tmpq) tmp tmpq+=q[:left]+q[-right:] q[:left]+q[-right:] tmpq tmp-=sum(tmpq[:min(k-i, len(tmpq))]) sum(tmpq[:min(k-i, len(tmpq))]) tmp ans=max(ans,tmp) max(ans,tmp) ans tmpq=[] [] tmpq tmpq=sorted(tmpq) sorted(tmpq) tmpq tmp=0 0 tmp ans=0 0 ans k=map(int,input().split()) map(int,input().split()) k tmpq=[x for x in tmpq if x<0] [x for x in tmpq if x<0] tmpq tmpq=sorted(tmpq) sorted(tmpq) tmpq right=-n -n right ans=max(ans,tmp) max(ans,tmp) ans tmpq=[] [] tmpq tmp+=sum(tmpq) sum(tmpq) tmp tmp-=sum(tmpq[:min(i-n, len(tmpq))]) sum(tmpq[:min(i-n, len(tmpq))]) tmp right=n-left n-left right n,k=map(int,input().split()) map(int,input().split()) n tmp=0 0 tmp tmpq+=q[:left]+q[-right:] q[:left]+q[-right:] tmpq right=-n -n right right=i-left i-left right tmpq=[x for x in tmpq if x<0] [x for x in tmpq if x<0] tmpq
n,k=map(int,input().split())
*q,=map(int,input().split())

ans=0
for i in range(1,k+1): # iは抜き取り回数
    if i<n:
        for left in range(0,i+1): # 左からleft個目まで抜き取る
            tmp=0
            tmpq=[]
            right=i-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(k-i, len(tmpq))])
            ans=max(ans,tmp)
    else:
        for left in range(0,n+1):
            tmp=0
            tmpq=[]
            right=n-left
            if right==0:
                right=-n
            tmpq+=q[:left]+q[-right:]
            tmp+=sum(tmpq)
            tmpq=[x for x in tmpq if x<0]
            tmpq=sorted(tmpq)
            tmp-=sum(tmpq[:min(i-n, len(tmpq))])
            ans=max(ans,tmp)
print(ans)