fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var w = readLine()!!.split(" ").map { it.toInt()}
    var l = 0
    var r = 0
    var lp = 0
    var rp = n-1
    repeat(n){
        if (l > r){
            r += w[rp]
            rp--
        }else{
            l += w[lp]
            lp++
        }
    }
    println(if (l > r) l - r else r - l)
}
