fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val aList = readLine()?.split(" ")?.map { it.toLong() } ?: return

    val total = aList.sum()
    var sideA = 0L
    var result = Long.MAX_VALUE

    for (i in 0 until aList.lastIndex) { // 最後の要素はsideBが取る必要がある
        sideA += aList[i]
        val sideB = total - sideA
        result = Math.min(result, Math.abs(sideA - sideB))
    }

    println(result)
}