import sys
import copy
def ring(H,n):
if n==0:
return H[1:]
elif n==len(H):
return H[:-2]
else:
for i in range(n):
H.append(H[i])
for i in range(n+1):
del(H[0])
return H
def solve(G,i):
#n=0或-1,取了之后删除节点
get_=G[i]
del(G[i])
return G,get_
def input_():
#N=int(input())
N=int(sys.stdin.readline())
H=[]
for i in range(N):
H.append(int(sys.stdin.readline()))
return H,N
H,N=input_()
#每个情况都试一遍
max_val=0
for i in range(N):
ming=H[i]
hong=0
G=copy.deepcopy(H)
ring_=ring(G,i)
ind=0
for j in range(N-1):
#红拿环里第一个
if j%2==0:
if int(ring_[0])>int(ring_[-1]):
ring_,val=solve(ring_,0)
hong=hong+int(val)
else:
ring_,val=solve(ring_,-1)
hong = hong + int(val)
else:
if int(ring_[0])>int(ring_[-1]):
ring_,val=solve(ring_,0)
ming=ming+int(val)
else:
ring_,val=solve(ring_,-1)
ming = ming + int(val)
if abs(ming-hong)>max_val:
max_val=abs(ming-hong)
print(max_val)