import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n  = sc.nextInt
  val al = Vector.fill(n)(sc.nextInt)

  val acc = comulativeSum(al)
  val sum = acc.last

  val res =
    acc.foldLeft(Long.MaxValue){case (min, x) =>
      Math.min( min, Math.abs(x - (sum - x)) )
    }

  println(res)

  def comulativeSum(intVector: Vector[Int]): Vector[Long] ={
    intVector.foldLeft(Vector.empty[Long]){
      case (list, ac) =>
        if(list.isEmpty) Vector(ac)
        else list :+ (list.last + ac)
    }
  }
}