let n = stdin.ReadLine() |> int
let mutable a = stdin.ReadLine().Split(' ') |> Array.map int64
let mutable ans = 1000000005 |>int64

let X = Array.sum(a) |> int64
let mutable x = 0 |>int64

let mini(c,b)=
    if c > b then
        b
     else
        c

let abns(e)=
    if e > 0 then
        e|>int64
    else
        -e|>int64

for i in[0..n-1]do
x<-x+a.[i]
let tw = 2|>int64
let dd = tw*x
let dx = X-dd
if i+1<n then ans <- mini(ans,abs(dx));;

printfn "%d" ans