"use strict";
function Main(input) {
  const args = input.split('\n');
  const N = parseInt(args.shift());
  const ws = args.shift().split(' ')
  .map( m => parseInt(m));
  let s2 = ws.reduce((p, c) => p + c);
  let s1 = 0;
  for (let i = 0; i < N; i++) {
    const s1b = s1;
    const s2b = s2;
    s1 += ws[i];
    s2 -= ws[i];
    if (s2 <= s1) {
      const ret1 = s1 - s2;
      const ret2 = s2b - s1b;
      console.log(ret1 < ret2 ? ret1 : ret2);
      return;
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
