'use strict'

function main(input) {

  const nums = input.split('\n')[1].split(' ').map(n => Number(n));
  const arr = [];

  //  27 23 76 2 3 5 62 52
  // -> [27, 50, 126, 128, 131, 136, 198, 250 ]
  for (let i = 0, cum = 0; i < nums.length; i++) {
    cum += nums[i];
    arr.push(cum);
  }
  
  const sum = arr[arr.length - 1];
  let min = sum;
  
  for (let i = 0; i < arr.length - 1; i++) {
    min = Math.min(min, Math.abs(arr[i] - (sum - arr[i])));
  }

  console.log(min);
}

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