#include <bits/stdc++.h>

#define filein freopen("in.txt","r",stdin)
#define fileout freopen("out.txt","w",stdout)

using namespace std;

typedef long long ll;

const int M = 10000000 + 7;

ll a[100000+5],b[100000+5],c[100000+5];
int main(){
    ll n;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i==0)
            b[i]=a[i];
        else
            b[i]=(a[i]+b[i-1]);

//            cout<<b[i]<<endl;

    }
     ll ans=1e10;
    for(int i=n-1;i>=0;i--){
        if(i==n-1)
            c[i]=a[i];
        else
            c[i]=(a[i]+c[i+1]);
        if(i>0)
             ans=min(ans, abs(c[i]-b[i-1]));
    }

//    for(int i=n-1;i>0;i--){
//
////        cout<<ans<<endl;
//    }
    cout<<ans<<endl;


    return 0;
}
