
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val W = readLine()!!.split(" ").map(String::toInt)
    val weight = W
    var left = 0
    var right = weight.fold(0) {sum,ele -> sum + ele}
    var acc = right - left
    for (w in weight) {
        left += w
        right -= w
        val diff =  if (right - left < 0 ) {
            left - right
        } else {
            right - left
        }
        acc = if (acc > diff) {diff} else {acc} 
    }
    
    acc.run(::println)
}
 