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

#define ll long long
#define M 5000000000000000

int main()
{
    ll n,m,a,b,c,i,j,k,mn=M;

    cin>> n;
    ll x[n],sum=0;

    for(i=0;i<n;i++){
        cin>> x[i];
        sum+=x[i];
    }
    sort(x,x+n);

    a=0;
    for(i=0;i<n-1;i++){
        a+=x[i];

        //cout<< mn-a;
        mn=min(mn,abs(sum-a-a));
    }

    cout<< mn;

    return 0;
}


