fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val w = readLine()!!.split(' ').map(String::toInt)
    var i = 0
    var j = n - 1
    var s1 = 0
    var s2 = 0
    while (i <= j) {
        if (s1 < s2) {
            s1 += w[i++]
        } else {
            s2 += w[j--]
        }
    }
    println(Math.abs(s1 - s2))
}
