fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toLong)
    val sum = an.sum()
    var count = 0L
    var min = sum
    for (i in 0 until an.lastIndex) {
        count += an[i]
        min = Math.min(min, Math.abs(sum - count * 2))
    }
    println(min)
}