object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())
  val rui = a.scanLeft(0L)(_ + _).tail
  val sum = rui.last
  val i = rui.indexWhere(x => x >= sum / 2)
  val (a1, a2) = a.splitAt(i+1)
  val ans = math.abs(a1.sum - a2.sum)
  println(ans)  
}
