log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n")
var N = Number(lines[0])
var Ws = lines[1].split(" ").map(Number)

var accumlate = []
Ws.forEach((v,i)=>{
  if(i===0){
    accumlate.push(v)
  }else {
    accumlate.push(v+accumlate[i-1])
  }
})

var sum = accumlate.slice(-1)
var diffs = []
accumlate.forEach((v)=>{
  diffs.push(Math.abs(sum - v*2));
})
log(Math.min(...diffs))