// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System

[<EntryPoint>]
let main argv =
    let count = stdin.ReadLine() |> int

    let weight = stdin.ReadLine().Split(' ') |> Array.toList |> List.map int

    let calcDiffOfPartition (list:int List) (separation:int) =
           (list.[..separation], list.[separation+1..])
                ||> fun list1 list2 -> Math.Abs(List.sum(list1) - List.sum(list2))

    let answer = [0..count - 1]
                 |> List.map(calcDiffOfPartition weight) 
                 |> List.min

    printfn "%d" answer

    0
