fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val w = readLine()!!.split(" ").map(String::toInt).toIntArray()

    var min = Integer.MAX_VALUE
    for (t in 0 .. n - 2) {
        val s1 = w.filterIndexed { index, i -> index <= t }.sum()
        val s2 = w.filterIndexed { index, i -> index > t }.sum()
        min = Math.min(min, Math.abs(s1 - s2))
    }
    println(min)
}
