import java.util.*

fun main(args: Array<String>) {
	val n = readLine()!!.toInt()
	val s = readLine()!!.trim().split(' ').map{ x -> x.toLong() }

	var dp = Array<LongArray>(n) { LongArray(n) { 0L } }

	for (i in 0..n - 1) {
		dp[i][i] = s[i]
	}

	for (i in (n - 2) downTo 0) {
		for (j in (i + 1) .. (n - 1)) {
			var a = s[i] - dp[i + 1][j]
			var b = s[j] - dp[i][j - 1]
			if (a > b) {
				dp[i][j] = a
			} else {
				dp[i][j] = b
			}
		}
	}

	println(dp[0][n - 1])
}