function Main(input) {
  input = input.split("\n");
  var A = input[1].split(" ").map(Number);
  var sum = 0;
  for(var i=0;i<A.length;i++){
    sum += A[i];
  }
  var half = 0;
  var jout = 0;
  for(var j=0;sum/2>half;j++){
    half += A[j];
    jout = j;
  }
  if(half-sum/2 > sum/2-half+A[jout]){
  half -= A[jout];
  }
	console.log(Math.abs(half-sum/2)*2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));