// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main()
{
    ll n, s = 0, c = 0, ans = 1e18;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, s += e;
    for (ll e : a)
        c += e, ans = min(ans, abs(2 * c - s));
    cout << ans;
    return 0;
}