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