def fun(i,j):

	# print(i,j)

	if i>j or i>=n or j<0:

		return 0

	elif i==j:

		dp[i][j]=arr[i]

		return dp[i][j]

	else:

		if dp[i][j]==0:

			dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))

		return dp[i][j]

n=int(eval(input()))

dp=[0]*n

for i in range(n):

	dp[i]=[0]*n

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

print((2*fun(0,n-1)-sum(arr)))
def fun(i,j):

	# print(i,j)

	if i>j or i>=n or j<0:

		return 0

	elif i==j:

		dp[i][j]=arr[i]

		return dp[i][j]

	else:

		if dp[i][j]==0:

			dp[i][j]=max(arr[i]+min(fun(i+1,j-1),fun(i+2,j)),arr[j]+min(fun(i+1,j-1),fun(i,j-2)))

		return dp[i][j]

n=int(eval(input()))

dp=[0]*n

for i in range(n):

	dp[i]=[0]*n

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



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

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

		if i==j:

			dp[i][j]=arr[i]

		else:

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

		# print(dp[i])

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

# print(2*fun(0,n-1)-sum(arr))
def fun(i, j):
    # print(i,j)
    if i > j or i >= n or j < 0:
        return 0
    elif i == j:
        dp[i][j] = arr[i]
        return dp[i][j]
    else:
        if dp[i][j] == 0:
            dp[i][j] = max(
                arr[i] + min(fun(i + 1, j - 1), fun(i + 2, j)),
                arr[j] + min(fun(i + 1, j - 1), fun(i, j - 2)),
            )
        return dp[i][j]


n = int(eval(input()))
dp = [0] * n
for i in range(n):
    dp[i] = [0] * n
arr = list(map(int, input().split()))
print((2 * fun(0, n - 1) - sum(arr)))

def fun(i, j):
    # print(i,j)
    if i > j or i >= n or j < 0:
        return 0
    elif i == j:
        dp[i][j] = arr[i]
        return dp[i][j]
    else:
        if dp[i][j] == 0:
            dp[i][j] = max(
                arr[i] + min(fun(i + 1, j - 1), fun(i + 2, j)),
                arr[j] + min(fun(i + 1, j - 1), fun(i, j - 2)),
            )
        return dp[i][j]


n = int(eval(input()))
dp = [0] * n
for i in range(n):
    dp[i] = [0] * n
arr = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
    for j in range(i, n, 1):
        if i == j:
            dp[i][j] = arr[i]
        else:
            dp[i][j] = max(arr[i] - dp[i + 1][j], arr[j] - dp[i][j - 1])
        # print(dp[i])
print((dp[0][n - 1]))
# print(2*fun(0,n-1)-sum(arr))

-print((2 * fun(0, n - 1) - sum(arr))) +for i in range(n - 1, -1, -1): +    for j in range(i, n, 1): +        if i == j: +            dp[i][j] = arr[i] +        else: +            dp[i][j] = max(arr[i] - dp[i + 1][j], arr[j] - dp[i][j - 1]) +        # print(dp[i]) +print((dp[0][n - 1])) +# print(2*fun(0,n-1)-sum(arr))