// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

immutable inf = 10L^^16;
int n;
int[] a;

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

    auto p = new long[](n + 1);
    auto s = new long[](n + 1);

    iota(n).each!(i => p[i + 1] = p[i] + a[i]);
    iota(n).retro().each!(i => s[i] = s[i + 1] + a[i]);

    debug {
        writeln(p);
        writeln(s);
    }

    long ans = inf;

    foreach (i ; 1 .. n) {
        ans = min(ans, abs(p[i] - s[i]));
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}