let N = Int(readLine()!)!

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: N), count: N)

let a = readLine()!.split(separator: " ").map { Int($0)! }

for i in 0..<N {
  dp[i][i] = a[i]
}

for l in 1..<N {
  for row in 0..<N-l {
    let col = row + l
    dp[row][col] = max(a[row] - dp[row + 1][col], a[col] - dp[row][col - 1])
  }
}
print(dp[0][N-1])