object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val As = List.fill(sc.nextInt())(sc.nextLong())
  val sum = As.sum
  val (_, diffs) = As.scanLeft(0L -> sum) {
    case ((acc, _), a) =>
      acc + a -> math.abs(sum - (acc + a) * 2)
  }.unzip
  println(diffs.min)
}
