fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{ it.toLong() }
    val s = Array<Long>(n + 1, {0})
    var sum = 0L
    for (i in a.indices) {
        s[i + 1] = s[i] + a[i]
        sum += a[i]
    }
    var ans = Long.MAX_VALUE
    for (i in 1 until s.size) {
        val left = s[i]
        val right = sum - s[i]
        val gap = Math.abs(right - left)
        ans = Math.min(ans, gap)
    }
    println(ans)
}