import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new long[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  auto c = new long[n+1];
  foreach (i; 1 .. n + 1) {
    c[i] = c[i-1] + a[i-1];
  }
  immutable s = c[n];
  debug stderr.writeln (c);
  long res = long.max;
  foreach (i; 0 .. n + 1) {
    long t1 = c[i];
    long t2 = s - t1;
    debug stderr.writeln ("t1 = ", t1, ", t2 = ", t2);
    res = min (res, abs (t1 - t2));
  }
  writeln (res);
}

