object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())
  val asc = a.scanLeft(0L)(_ + _)
  val desc = a.scanRight(0L)(_ + _)
  val diff = asc.zip(desc).map{case (x, y) => math.abs(x - y)}
  println(diff.min)
}
