fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val bar = readLine()!!.split(" ").map { it.toLong() }
    val total = bar.sum()
    var subTotal = 0L
    var diff = total
    for(i in (0 until n-1)) {
        subTotal += bar[i]
        diff = Math.min(diff, Math.abs(subTotal*2-total))
    }
    println(diff)
}
