import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto S = A.sum;
    auto md = 1L << 59;
    long x = 0;

    foreach (a; A) {
        x += a;
        auto y = S - x;
        md = min(md, abs(x - y));
    }

    md.writeln;
}


