function Main(input) {
    input = input.trim().split("\n");
    var N = parseInt(input[0],10);
    tmp = input[1].split(" ");
    var W = [];
    for(var i = 0; i < tmp.length; i++){
        W[i] = parseInt(tmp[i],10);
    }
    var sum = 0;
    for(var i = 0; i < W.length; i++){
        sum += W[i];
    }

    var output;
    if(W[0] >= sum/2){
        var S1 = W[0];
        var S2 = 0;
        for(var i = 1; i < W.length; i++){
            S2 += W[i];
        }
        output = Math.abs(S1-S2);
    }
    else if(W[W.length-1] >= sum/2){
        var S1 = 0;
        for(var i = 0; i < W.length-1; i++){
            S1 += W[i];
        }
        var S2 = W[W.length-1];
        output = Math.abs(S1-S2);
    }
    else{
        var S1 = 0;
        for(var i = 0; i < W.length; i++){
            S1 += W[i];
            if(S1 >= sum/2){
                break;
            };
        }
        var S2 = sum - S1;
        output = Math.abs(S1-S2);        
    }
    console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));