#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,a[200000],sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int tmp=0,ans=mod*mod;
    for(int i=1;i<n;i++){
        tmp+=a[i-1];
        ans=min(ans,abs(sum-tmp-tmp));
    }
    cout<<ans<<endl;
}
