fun main(args: Array<String>) {
    readLine()!!
    val w = readLine()!!.split(" ").map { it.toInt() }
    var tmp = 0
    val s = w.map { tmp+=it; tmp }
    val sum = w.sum()
    val ans = s.map { Math.abs(sum-it*2) }.min()!!
    println(ans)
}
