import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n: Int = sc.nextInt()
    val w = IntArray(n)
    for(i in 0 until n) {
        w[i] = sc.nextInt()
    }
    
    val sum = w.sum()
    var psum = 0
    var nsum = 0
    var prev = 0
    for(i in 0 until n) {
        psum += w[i]
        nsum = sum - psum
        if(psum > nsum){
            val curr = psum - nsum
            println(if(prev > curr) curr else prev)
            break
        }
        prev = nsum - psum
    }
}
