'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");

let Nums = input.split('\n');
let amount = Nums[0]*1;
let arr = Nums[1].split(" ").map(x => x*1);
let sum = arr.reduce((x,a)=> { return a+=x });
// 差についての十分に大きい暫定最小値
let min = 5050;
let tempSum = 0;
let restSum = 0;
for(let i =0; i < amount; i++){
  tempSum += arr[i];
  restSum = sum - tempSum;
  if(Math.abs(tempSum - restSum) < min){
      min = Math.abs(tempSum - restSum);
  }
}

console.log(min);