import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = MI()
V = LI()

ans = 0
for i in range(K+1):  # 操作回数
    for j in range(N+1):  # 左から
        for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l)))
print(ans) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def I(): return int(sys.stdin.readline().rstrip()) I def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし LI2 def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり LS def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 N,K = MI() N MI() MI K V = LI() V LI() LI ans = 0 ans 0 for i in range(K+1):  # 操作回数
    for j in range(N+1):  # 左から
        for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l))) i range(K+1) range K+1 K 1 for j in range(N+1):  # 左から
        for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l))) j range(N+1) range N+1 N 1 for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l))) k range(N+1) range N+1 N 1 if j + k > min(N,i):
                break
             j + k > min(N,i) j + k j k min(N,i) min N i break l = i-j-k l i-j-k i-j i j k if l > j+k:
                continue
             l > j+k l j+k j k continue V[m] for m in range(j) for m in range(j) m range(j) range j for m in range(j) V[m] V m A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] A [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] [V[m] for m in range(j)] [V[N-1-m] for m in range(k)] A.sort(reverse=True) A.sort A sort reverse=True reverse True ans = max(ans,sum(A[m] for m in range(j+k-l))) ans max(ans,sum(A[m] for m in range(j+k-l))) max ans sum(A[m] for m in range(j+k-l)) sum A[m] A m print(ans) print ans ans = max(ans,sum(A[m] for m in range(j+k-l))) max(ans,sum(A[m] for m in range(j+k-l))) ans def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし LI2 def S(): return sys.stdin.readline().rstrip() def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり LS def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI ans = 0 0 ans def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 K = MI() MI() K A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] A def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI l = i-j-k i-j-k l N,K = MI() MI() N V = LI() LI() V
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = MI()
V = LI()

ans = 0
for i in range(K+1):  # 操作回数
    for j in range(N+1):  # 左から
        for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l)))
print(ans)
