import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val AArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    
    var lIndex = 1
    var rIndex = N - 2
    var lSum = AArr[0]
    var rSum = AArr[N - 1]
    
    while (rIndex >= lIndex) {
        if (rSum > lSum) {
            lSum += AArr[lIndex]
            lIndex++
        } else {
            rSum += AArr[rIndex]
            rIndex--
        }
    }

    println(Math.abs(rSum - lSum))
}

fun readInputLine(): String {
    return readLine()!!
}
