"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const weights = arg[1].split(" ").map(n=>parseInt(n));
    
    let   right  = weights.reduce((m,n)=>m+n);
    let   left   = 0;
    let   answer = right;
    
    for(let i in weights) {
        left  += weights[i];
        right -= weights[i];
        answer = Math.min(answer, Math.abs(left - right));
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));