N = int(eval(input()))

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



INF = 10 ** 12



dp1 = [[-INF] * (N + 1) for _ in range(N + 1)] #X - Yの最大値

dp2 = [[+INF] * (N + 1) for _ in range(N + 1)] #X - Yの最小値



if N % 2 == 0: #偶数-->最後の一個はY

    for i in range(N):

        dp2[i][i + 1] = -A[i]

        # print (dp2[i][i + 1], end =' ')

    # print ()

    for k in range(2, N + 1):

        if k % 2 == 1:

            for i in range(N - k + 1):

                dp2[i][i + k] = min(dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i +k] - A[i])

                # print (dp2[i][i + k], end = ' ')

            # print ()

        else:

            for i in range(N - k + 1):

                dp1[i][i + k] = max(dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i])

                # print (dp1[i][i + k], end = ' ')

            # print ()

    print((dp1[0][N]))







else: #奇数-->最後の一個はX

    for i in range(N):

        dp1[i][i + 1] = A[i]

        # print (dp1[i][i + 1], end =' ')

    # print ()

    for k in range(2, N + 1):

        if k % 2 == 0:

            for i in range(N - k + 1):

                dp2[i][i + k] = min(dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i +k] - A[i])

                # print (dp2[i][i + k], end = ' ')

            # print ()

        else:

            for i in range(N - k + 1):

                dp1[i][i + k] = max(dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i])

                # print (dp1[i][i + k], end = ' ')

            # print ()

    print((dp1[0][N]))

import numpy as np



N = int(eval(input()))

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



A = np.array(A, dtype = np.int64)

INF = 10 ** 12



dp1 = np.array([-INF] * (N + 1), dtype = np.int64)

dp2 = np.array([+INF] * (N + 1), dtype = np.int64)



if N % 2 == 0:

    dp2[1:] = -A[:]

    # print (dp2)

    for k in range(2, N + 1):

        if k % 2 == 1:

            dp2[k:] = np.minimum(dp1[k - 1:N] - A[k - 1:], dp1[k:] - A[:N - k + 1])

            # print (dp2)

        else:

            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k])

            dp1[k:] = np.maximum(dp2[k - 1:N] + A[k - 1:], dp2[k:] + A[:N - k + 1])

            # print (dp1)

    print((dp1[N]))



else:

    dp1[1:] = A[:]

    # print (dp1)

    for k in range(2, N + 1):

        if k % 2 == 0:

            dp2[k:] = np.minimum(dp1[k - 1:N] - A[k - 1:], dp1[k:] - A[:N - k + 1])

            # print (dp2)

        else:

            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k])

            dp1[k:] = np.maximum(dp2[k - 1:N] + A[k - 1:], dp2[k:] + A[:N - k + 1])

            # print (dp1)

    print((dp1[N]))

N = int(eval(input()))
A = list(map(int, input().split()))
INF = 10**12
dp1 = [[-INF] * (N + 1) for _ in range(N + 1)]  # X - Yの最大値
dp2 = [[+INF] * (N + 1) for _ in range(N + 1)]  # X - Yの最小値
if N % 2 == 0:  # 偶数-->最後の一個はY
    for i in range(N):
        dp2[i][i + 1] = -A[i]
        # print (dp2[i][i + 1], end =' ')
    # print ()
    for k in range(2, N + 1):
        if k % 2 == 1:
            for i in range(N - k + 1):
                dp2[i][i + k] = min(
                    dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i + k] - A[i]
                )
                # print (dp2[i][i + k], end = ' ')
            # print ()
        else:
            for i in range(N - k + 1):
                dp1[i][i + k] = max(
                    dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i]
                )
                # print (dp1[i][i + k], end = ' ')
            # print ()
    print((dp1[0][N]))
else:  # 奇数-->最後の一個はX
    for i in range(N):
        dp1[i][i + 1] = A[i]
        # print (dp1[i][i + 1], end =' ')
    # print ()
    for k in range(2, N + 1):
        if k % 2 == 0:
            for i in range(N - k + 1):
                dp2[i][i + k] = min(
                    dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i + k] - A[i]
                )
                # print (dp2[i][i + k], end = ' ')
            # print ()
        else:
            for i in range(N - k + 1):
                dp1[i][i + k] = max(
                    dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i]
                )
                # print (dp1[i][i + k], end = ' ')
            # print ()
    print((dp1[0][N]))

import numpy as np

N = int(eval(input()))
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)
INF = 10**12
dp1 = np.array([-INF] * (N + 1), dtype=np.int64)
dp2 = np.array([+INF] * (N + 1), dtype=np.int64)
if N % 2 == 0:
    dp2[1:] = -A[:]
    # print (dp2)
    for k in range(2, N + 1):
        if k % 2 == 1:
            dp2[k:] = np.minimum(dp1[k - 1 : N] - A[k - 1 :], dp1[k:] - A[: N - k + 1])
            # print (dp2)
        else:
            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k])
            dp1[k:] = np.maximum(dp2[k - 1 : N] + A[k - 1 :], dp2[k:] + A[: N - k + 1])
            # print (dp1)
    print((dp1[N]))
else:
    dp1[1:] = A[:]
    # print (dp1)
    for k in range(2, N + 1):
        if k % 2 == 0:
            dp2[k:] = np.minimum(dp1[k - 1 : N] - A[k - 1 :], dp1[k:] - A[: N - k + 1])
            # print (dp2)
        else:
            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k])
            dp1[k:] = np.maximum(dp2[k - 1 : N] + A[k - 1 :], dp2[k:] + A[: N - k + 1])
            # print (dp1)
    print((dp1[N]))

+import numpy as np + +A = np.array(A, dtype=np.int64) -dp1 = [[-INF] * (N + 1) for _ in range(N + 1)]  # X - Yの最大値 -dp2 = [[+INF] * (N + 1) for _ in range(N + 1)]  # X - Yの最小値 -if N % 2 == 0:  # 偶数-->最後の一個はY -    for i in range(N): -        dp2[i][i + 1] = -A[i] -        # print (dp2[i][i + 1], end =' ') -    # print () +dp1 = np.array([-INF] * (N + 1), dtype=np.int64) +dp2 = np.array([+INF] * (N + 1), dtype=np.int64) +if N % 2 == 0: +    dp2[1:] = -A[:] +    # print (dp2) -            for i in range(N - k + 1): -                dp2[i][i + k] = min( -                    dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i + k] - A[i] -                ) -                # print (dp2[i][i + k], end = ' ') -            # print () +            dp2[k:] = np.minimum(dp1[k - 1 : N] - A[k - 1 :], dp1[k:] - A[: N - k + 1]) +            # print (dp2) -            for i in range(N - k + 1): -                dp1[i][i + k] = max( -                    dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i] -                ) -                # print (dp1[i][i + k], end = ' ') -            # print () -    print((dp1[0][N])) -else:  # 奇数-->最後の一個はX -    for i in range(N): -        dp1[i][i + 1] = A[i] -        # print (dp1[i][i + 1], end =' ') -    # print () +            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k]) +            dp1[k:] = np.maximum(dp2[k - 1 : N] + A[k - 1 :], dp2[k:] + A[: N - k + 1]) +            # print (dp1) +    print((dp1[N])) +else: +    dp1[1:] = A[:] +    # print (dp1) -            for i in range(N - k + 1): -                dp2[i][i + k] = min( -                    dp1[i][i + k - 1] - A[i + k - 1], dp1[i + 1][i + k] - A[i] -                ) -                # print (dp2[i][i + k], end = ' ') -            # print () +            dp2[k:] = np.minimum(dp1[k - 1 : N] - A[k - 1 :], dp1[k:] - A[: N - k + 1]) +            # print (dp2) -            for i in range(N - k + 1): -                dp1[i][i + k] = max( -                    dp2[i][i + k - 1] + A[i + k - 1], dp2[i + 1][i + k] + A[i] -                ) -                # print (dp1[i][i + k], end = ' ') -            # print () -    print((dp1[0][N])) +            # print (dp2[k - 1:N], A[k - 1:], dp2[k:], A[: N - k]) +            dp1[k:] = np.maximum(dp2[k - 1 : N] + A[k - 1 :], dp2[k:] + A[: N - k + 1]) +            # print (dp1) +    print((dp1[N]))