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

int main(){
    int n;
    cin >> n;
    long long ans = 1e18;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> acc(n + 1, 0);
    for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + a[i];
    for (int i = 1; i < n; i++) ans = min(ans, abs(acc.back() - acc[i] * 2));
    cout << ans << endl;
}