'use strict'
function Main(input) {
    input = input.split("\n");
    const n = parseInt(input[0], 10)
    const arr = input[1].split(' ').map(v => parseInt(v, 10))
    let i = 0
    let j = n - 1
    let x = arr[i]
    let y = arr[j]
    calc(arr, x, y, i, j)
}
function calc(arr, x, y, i, j) {
    if (Math.abs(i - j) === 1) {
        console.log(Math.abs(x - y))
        return
    }
    if (x >= y) {
        j -= 1
        y += arr[j]
    } else if (x < y) {
        i += 1
        x += arr[i]
    }
    calc(arr, x, y, i, j)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));