import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val a = new Array[Int](N+1)
  for(i <- 1 to N)
    a(i) = in.next().toInt

  //
  import Math.{max, min}
  val memo = Array.ofDim[Long](N+1, N+1)

  def solve(bg: Int, ed: Int, turn: Boolean): Long = {
    if(memo(bg)(ed) > 0)
      memo(bg)(ed)
    else{
      if(bg == ed) {
        memo(bg)(ed) = a(bg) * (if(turn) 1 else -1)
        memo(bg)(ed)
      }
      else {
        val left = solve(bg+1, ed, !turn)
        val right = solve(bg, ed-1, !turn)
        if(turn)
          memo(bg)(ed) = max(left + a(bg), right + a(ed))
        else
          memo(bg)(ed) = min(left - a(bg), right - a(ed))
        memo(bg)(ed)
      }
    }
  }

  println(solve(1, N, true))
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

