import sys sys.setrecursionlimit(10**6) try: import pypyjit pypyjit.set_param('max_unroll_recursion=-1') except ModuleNotFoundError: pass N = int(input()) A = list(map(int, input().split())) memo = {} def f(l, r): if l >= r: return 0 if (l, r) in memo: return memo[l, r] res = max(A[l] - A[l+1] + f(l+2, r), A[r] - A[r-1] + f(l, r-2)) memo[l, r] = res return res ans = f(0, 2*N-1) print(ans)