fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var ans = 1000000000000000000L
    val A = readLine()!!.split(" ").map(String::toLong)
    var r = A.sum()
    var l = 0L
    for (i in 0..N-2) {
        r -= A[i]
        l += A[i]
        ans = Math.min(ans, Math.abs(r - l))
    }
    println(ans)
}