fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    //val a = sc.asSequence().take(n).map(String::toInt).sortedDescending().toList()
    val a = sc.asSequence().take(n).map(String::toInt).toList()

    var r = 999

    for (i in 1 until a.size) {
        val v = Math.abs(a.take(i).sum() - a.takeLast(a.size - i).sum())
        if (v < r) {
            r = v
        }
    }

    println(r)
}
