import sys

def input():

    return sys.stdin.readline()[:-1]



n = int(eval(input()))

a = [int(x) for x in input().split()]



dp=[]

for i in range(n):

	dp.append([0]*n)

for i in range(n):

    dp[i][i] = a[i]



for i in range(n - 2, -1, -1):

    for j in range(i + 1, n):

        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])



print((dp[0][n - 1]))
n = int(eval(input()))

a = list(map(int, input().split()))



def calc():

    dp = [[0] * n for _ in range(n)]

    for i in range(n):

        dp[i][i] = a[i]



    for i in range(n - 2, -1, -1):

        for j in range(i + 1, n):

            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])

    return dp



dp = calc()

print((dp[0][n - 1]))
import sys


def input():
    return sys.stdin.readline()[:-1]


n = int(eval(input()))
a = [int(x) for x in input().split()]
dp = []
for i in range(n):
    dp.append([0] * n)
for i in range(n):
    dp[i][i] = a[i]
for i in range(n - 2, -1, -1):
    for j in range(i + 1, n):
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
print((dp[0][n - 1]))

n = int(eval(input()))
a = list(map(int, input().split()))


def calc():
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
    return dp


dp = calc()
print((dp[0][n - 1]))

-import sys +n = int(eval(input())) +a = list(map(int, input().split())) -def input(): -    return sys.stdin.readline()[:-1] +def calc(): +    dp = [[0] * n for _ in range(n)] +    for i in range(n): +        dp[i][i] = a[i] +    for i in range(n - 2, -1, -1): +        for j in range(i + 1, n): +            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]) +    return dp -n = int(eval(input())) -a = [int(x) for x in input().split()] -dp = [] -for i in range(n): -    dp.append([0] * n) -for i in range(n): -    dp[i][i] = a[i] -for i in range(n - 2, -1, -1): -    for j in range(i + 1, n): -        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]) +dp = calc()