open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let N = read int
    let A = reada int64

    let mid = N / 2
    let left, right = A |> Array.splitAt mid
    let a = Array.sum left - Array.sum right |> abs
    let left, right = A |> Array.splitAt (mid+1)
    let b = Array.sum left - Array.sum right |> abs
    List.min [a;b] |> printfn "%d"
    0 // return an integer exit code
