const main = (inputs) => {
  var N = inputs[0]-0;
  var sum = 0;
  var line = inputs[1].split(" ").map(v=>{sum+=v-0; return v-0;});

  var ans = sum;
  var t_sum=0;
  for(var i=0;i<N;i++){
    t_sum += line[i];
    ans = Math.min(ans, Math.abs(t_sum-(sum-t_sum)));
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
