import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toInt)
  val sum = a.sum
  val initial = (math.abs(a.head-(sum-a.head)),a.head)

  val ans = a.tail.init./:(initial)((acc,i) => {
      val xy = math.min(math.abs(acc._2-(sum-acc._2)), acc._1)
      (xy, acc._2 + i)
    })._1

  println(ans)
}