void main() {
    long n = readln.chomp.to!int;
    long[] a = readln.split.to!(long[]);

    long l, r = a.sum;
    long diff = long.max;
    foreach (i; 0 .. n) {
        if (abs(r-l-2*a[i]) < diff) {
            l += a[i];
            r -= a[i];
            diff = abs(r-l);
        } else {
            break;
        }
    }

    abs(r-l).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;