n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
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 def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):]) get return sorted(v[:s]+v[n-(t-s):]) sorted(v[:s]+v[n-(t-s):]) sorted v[:s]+v[n-(t-s):] v[:s] v :s s v[n-(t-s):] v n-(t-s): n-(t-s) n t-s t s t t s s def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res f res=0 res 0 for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
     i range(t+1) range t+1 t 1 a=get(min(t,n),min(i,n)) a get(min(t,n),min(i,n)) get min(t,n) min t n min(i,n) min i n tmp=sum(a) tmp sum(a) sum a res=max(res,tmp) res max(res,tmp) max res tmp for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
     j range(min(k-t,t,n)) range min(k-t,t,n) min k-t k t t n tmp-=a[j] tmp a[j] a j res=max(res,tmp) res max(res,tmp) max res tmp return res res t t ans=0 ans 0 for i in range(1,k+1):
    ans=max(ans,f(i)) i range(1,k+1) range 1 k+1 k 1 ans=max(ans,f(i)) ans max(ans,f(i)) max ans f(i) f i print(ans) print ans n,k=map(int,input().split()) map(int,input().split()) n def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):]) def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):]) get ans=max(ans,f(i)) max(ans,f(i)) ans v=list(map(int,input().split())) list(map(int,input().split())) v def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res f ans=0 0 ans k=map(int,input().split()) map(int,input().split()) k
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)