function Main(input){
  var N = input.split("\n")[0];
  var W = input.split("\n")[1].split(" ");
  for(i=0;i<=N-1;i++){
    W[i] = parseInt(W[i],10);
  }
  var sum = function(arr){
    var sum = 0;
    arr.forEach(function(elm){
      sum += elm;
    });
    return sum;
  }
  var halsum = sum(W)/2;
  var val = 0;
  var count = 0;
  for(j=0;val<=halsum;j++){
    val += W[j];
    count += 1
  }
  count -= 1;
  var a = val-halsum;
  var b = val-W[count]-halsum;
  a = Math.abs(a);
  b = Math.abs(b);
  if(a>=b){
    console.log(2*b);
  }else{
    console.log(2*a);
  }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));