stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

using namespace std;



const int N = 2e5 + 5;

typedef long long ll;



ll n, a[N], sum[N], ans = 1LL << 62;



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cin >> n;

	for (int i = 1; i <= n; ++i) {

		cin >> a[i];

		sum[i] = sum[i - 1] + a[i];

	}

	for (int i = 1; i <= n - 1; ++i) {

		ans = min(ans, abs(sum[n] - sum[i] - sum[i]));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.273167568827725x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <string>

#include <algorithm>

#include <iostream>

#include <iomanip>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std ;



inline LL read() {

	LL x = 0 , f = 1 ;

	char ch = getchar() ;

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }

	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }

	return x * f ;

}



const int N = 2e5+11;

int n;

int a[N];

LL ans;

LL L[N],R[N];



int main() {

	n=read();

	For(i, 1, n) a[i]=read();

	For(i, 1, n) L[i]=L[i-1]+a[i];

	Dow(i, n, 1) R[i]=R[i+1]+a[i];

	ans = 1e18;

	For(i, 1, n-1) 

		ans = min(ans,abs(L[i]-R[i+1]));

	printf("%lld\n",ans);

}
















// Faster C++ solution for the same problem (measured speedup: 5.133074462892403x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include <iostream>

using namespace std;



int main()

{

	int N;

	long long int * a;

	long long int sum=0, min;

	cin >> N;

	a = new long long int[N];

	for (int i = 0; i < N; i++) {

		cin >> a[i];

		sum += a[i];

	}

	sum -= 2 * a[0];

	min = abs(sum) ;

	for (int i = 1; i < N - 1 ; i++) {

		sum -= 2 * a[i];

		if (min > abs(sum))min = abs(sum);

	}

	cout << min;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.219655697456707x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cmath>



using namespace std;



#define N 200008



int n;

int a[N];

long long sum = 0;



void solve()

{

	long long first = a[1];

	long long minn = abs(sum-first-first);

	for (int i = 2; i < n; i++)

	{

		first += (long long)a[i];

		minn = min(minn,abs(sum-first-first));

	}

	printf("%lld\n", minn);

}



void init()

{

	scanf("%d", &n);

	for (int i = 1; i <= n; i++)

	{

		scanf("%d", &a[i]);

		sum += (long long)a[i];

	}

}



int main()

{

	init();

	solve();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.15130224459614x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include<iostream>

#include <cmath>

using namespace std;



int main() {

	int length;

	long long sum = 0;

	cin >> length;

	int *a = new int[length];

	for (int i = 0; i < length; i++) {

		cin >> a[i];

		sum += a[i];

	}

	long long sum1 = a[0];

	long long min = abs(sum - 2 * sum1);

	for (int i = 1; i < length-1; i++) {

		sum1 += a[i];

		if (abs(sum-2*sum1) < min)

			min = abs(sum-2*sum1);

	}

	cout << min << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.215440431871662x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include<iostream>

#include<cmath>



using namespace std;



int main()

{

	long long a[200005];

	int n,i;

	long long s(0),min;

	cin>>n;

	a[0]=0;

	for (i=1;i<=n;i++)

	{

		cin>>a[i];

		s+=a[i];

	    a[i]+=a[i-1];

	}

	min=fabs(2*a[1]-s);

	for (i=2;i<n;i++)

	  if (fabs(2*a[i]-s)<min) min=fabs(2*a[i]-s);

	cout<<min<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.383596453523528x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;



const int maxN = 2e6 + 10;

int n;

long long val[maxN];

long long sum[maxN];



int main(){

	//freopen("b2.txt","r",stdin);

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%lld",&val[i]);

	}

	for(int i=1; i<=n;i++){

		sum[i] = sum[i-1] + val[i];

	//	printf("%d\n",sum[i] );

	}	

	long long res = 5e18;

	for(int i=1; i<=n-1;i++){

		long long t =abs(sum[i] - (sum[n] - sum[i]));



		res = min(res, t);



	}

	printf("%lld\n",res);





	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.152307613850783x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <cstdio>

const long long MAXN=0x7fffffffffffff;

using namespace std;

int a_min(long long a,long long b){

	return a>b?b:a;

}

int main(){

	int n,a[400000];

		scanf("%d",&n);

	long long sum=0LL; 

	for(int i=1;i<=n;i++){ 

		scanf("%d",&a[i]);

		sum+=a[i]; 

	} 

	long long snu=0LL; 

 	long long rac; 

	long long ans=MAXN;

	for(int i=1;i<n;i++){ 

  		snu+=a[i]; 

  		rac= sum-snu;

   		ans = min(ans,abs(rac-snu)); 

   } 

	printf("%lld",ans); 

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.345248173214923x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
/*main*/

#include <iostream>

#include <stdio.h>

#include <algorithm>

#include <cstdlib>

#include <cmath>

using namespace std;



const int N = 200050;

int a[N];

int n;

typedef long long LL;



void init()

{



}



void solve()

{

    cin >> n;

    LL sumX = 0,sumY = 0;

    for(int i=0; i<n; i++)

    {

        cin >> a[i];

        sumY += a[i];

    }

    LL Min = abs(a[0] - (sumY-a[0]));

    for(int i=0; i<n-1; i++)

    {

        sumX += a[i];

        sumY -= a[i];

        if(Min > abs(sumX-sumY))

            Min = abs(sumX-sumY);

        if(Min == 0)

            break;

    }

    cout << Min << endl;

}



int main()

{

    /*init();*/

    solve();

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.208120178052352x):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

    while(scanf("%d",&n)!=EOF)

    {

        for(int i=1;i<=n;i++)

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

            sum[i] = sum[i-1]+a;

        }



        long long ans=abs(sum[n]-sum[1]-sum[1]);

        for(int i=1;i<n;i++)

        {

            ans = min(ans,abs(sum[n]-sum[i]-sum[i]));

        }

        printf("%lld\n",ans);

    }

}
// Slower C++ solution:
//C

/*==========================================================*/

/*    Template ver 2017-0401    |   Created by AVM.Martin   */

/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */

/*==========================================================*/

#include<cstdio>

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<cassert>

#include<algorithm>

#include<cmath>



#include<cstring>

#include<string>

#include<cctype>

#include<utility>

#include<vector>

#include<stack>

#include<queue>

#include<deque>

#include<map>

#include<set>

#include<list>



typedef long long ll;

typedef std::pair<int,int> pii;

typedef std::pair<ll,ll> pll;

typedef std::vector<int> vi;



const int OO=(int)2e9;

const ll INF=(ll)4e18;

const double EPS=(double)1e-12;



#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front



#define INL(i,a,b) ((a<=i)&&(i<=b))

#define EXL(i,a,b) ((a< i)&&(i< b))

#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)

#define REP(i,a,b) REPP(i,a,b,1)

#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)

#define REV(i,a,b) REVV(i,a,b,1)

using namespace std;



int n;

ll dat[200005];

ll res;



int main(){

	scanf("%d",&n);

	dat[0]=0;

	REP(i,1,n){

		scanf("%lld",dat+i);

		dat[i]+=dat[i-1];

	}

	res=INF;

	REP(i,1,n-1)res=min(res,abs(2*dat[i]-dat[n]));

	printf("%lld\n",res);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.154489284574247x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXSIZE=30000020;

const ll INF=0x3f3f3f3f3f3f3f3fLL;

int bufpos;

char buf[MAXSIZE];

#define NEG 1

void init(){

	#ifdef LOCAL

		freopen("E.txt","r",stdin);

	#endif

	buf[fread(buf,1,MAXSIZE,stdin)]='\0';

	bufpos=0;

}

#if NEG

int readint(){

	bool isneg;

	int val=0;

	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);

	bufpos+=(isneg=buf[bufpos]=='-');

	for(;isdigit(buf[bufpos]);bufpos++)

		val=val*10+buf[bufpos]-'0';

	return isneg?-val:val;

}

#else

int readint(){

	int val=0;

	for(;!isdigit(buf[bufpos]);bufpos++);

	for(;isdigit(buf[bufpos]);bufpos++)

		val=val*10+buf[bufpos]-'0';

	return val;

}

#endif

char readchar(){

	for(;isspace(buf[bufpos]);bufpos++);

	return buf[bufpos++];

}

int readstr(char* s){

	int cur=0;

	for(;isspace(buf[bufpos]);bufpos++);

	for(;!isspace(buf[bufpos]);bufpos++)

		s[cur++]=buf[bufpos];

	s[cur]='\0';

	return cur;

}

ll sum[200002];

ll myabs(ll x){

	return x>0?x:-x;

}

int main(){

	init();

	int n=readint();

	for(int i=1;i<=n;i++)

		sum[i]=sum[i-1]+readint();

	ll ans=INF;

	for(int i=1;i<n;i++)

		ans=min(ans,myabs(sum[n]-sum[i]-sum[i]));

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 5.136476466584168x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
//周♂雨扬是最强的！！！

//大佬祝您AK

//沈哲♂贝是最强的！！！

#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<fstream>

using namespace std;

//ifstream fin(.in);

//ofstream fout(.out);

long long n,num[400003];

int main(){

	cin>>n;

	for(int i=1;i<=n;i++){

		cin>>num[i];

		num[i]=num[i]+num[i-1];

	}

	long long ans=999999999999;

	for(int i=2;i<=n;i++){

		ans=min(ans,abs(num[n]-num[i-1]-num[i-1]));

	}

	cout<<ans<<endl;

	return 0;

}

//沈♂哲贝是最强的！！！

//大佬祝您AK

//周♂雨扬是最强的！！！

// Faster C++ solution for the same problem (measured speedup: 5.213751718126655x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



const int N = 2e5 + 5;

typedef long long ll;



ll n, a[N], sum[N], ans = 1LL << 62;



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cin >> n;

	for (int i = 1; i <= n; ++i) {

		cin >> a[i];

		sum[i] = sum[i - 1] + a[i];

	}

	for (int i = 1; i <= n - 1; ++i) {

		ans = min(ans, abs(sum[n] - sum[i] - sum[i]));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.275073717290002x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <string>

#include <algorithm>

#include <iostream>

#include <iomanip>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std ;



inline LL read() {

	LL x = 0 , f = 1 ;

	char ch = getchar() ;

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }

	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }

	return x * f ;

}



const int N = 2e5+11;

int n;

int a[N];

LL ans;

LL L[N],R[N];



int main() {

	n=read();

	For(i, 1, n) a[i]=read();

	For(i, 1, n) L[i]=L[i-1]+a[i];

	Dow(i, n, 1) R[i]=R[i+1]+a[i];

	ans = 1e18;

	For(i, 1, n-1) 

		ans = min(ans,abs(L[i]-R[i+1]));

	printf("%lld\n",ans);

}
















// Faster C++ solution for the same problem (measured speedup: 5.1349299703964775x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



int main()

{

	int N;

	long long int * a;

	long long int sum=0, min;

	cin >> N;

	a = new long long int[N];

	for (int i = 0; i < N; i++) {

		cin >> a[i];

		sum += a[i];

	}

	sum -= 2 * a[0];

	min = abs(sum) ;

	for (int i = 1; i < N - 1 ; i++) {

		sum -= 2 * a[i];

		if (min > abs(sum))min = abs(sum);

	}

	cout << min;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.221542502408657x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cmath>



using namespace std;



#define N 200008



int n;

int a[N];

long long sum = 0;



void solve()

{

	long long first = a[1];

	long long minn = abs(sum-first-first);

	for (int i = 2; i < n; i++)

	{

		first += (long long)a[i];

		minn = min(minn,abs(sum-first-first));

	}

	printf("%lld\n", minn);

}



void init()

{

	scanf("%d", &n);

	for (int i = 1; i <= n; i++)

	{

		scanf("%d", &a[i]);

		sum += (long long)a[i];

	}

}



int main()

{

	init();

	solve();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.153164341092051x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include <cmath>

using namespace std;



int main() {

	int length;

	long long sum = 0;

	cin >> length;

	int *a = new int[length];

	for (int i = 0; i < length; i++) {

		cin >> a[i];

		sum += a[i];

	}

	long long sum1 = a[0];

	long long min = abs(sum - 2 * sum1);

	for (int i = 1; i < length-1; i++) {

		sum1 += a[i];

		if (abs(sum-2*sum1) < min)

			min = abs(sum-2*sum1);

	}

	cout << min << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.217325713086331x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cmath>



using namespace std;



int main()

{

	long long a[200005];

	int n,i;

	long long s(0),min;

	cin>>n;

	a[0]=0;

	for (i=1;i<=n;i++)

	{

		cin>>a[i];

		s+=a[i];

	    a[i]+=a[i-1];

	}

	min=fabs(2*a[1]-s);

	for (i=2;i<n;i++)

	  if (fabs(2*a[i]-s)<min) min=fabs(2*a[i]-s);

	cout<<min<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.38554251989966x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;



const int maxN = 2e6 + 10;

int n;

long long val[maxN];

long long sum[maxN];



int main(){

	//freopen("b2.txt","r",stdin);

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

		scanf("%lld",&val[i]);

	}

	for(int i=1; i<=n;i++){

		sum[i] = sum[i-1] + val[i];

	//	printf("%d\n",sum[i] );

	}	

	long long res = 5e18;

	for(int i=1; i<=n-1;i++){

		long long t =abs(sum[i] - (sum[n] - sum[i]));



		res = min(res, t);



	}

	printf("%lld\n",res);





	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.154170073768306x):
#include <stdio.h>

int n;

int list[200001];

long long int abs(long long int x) { return x < 0 ? -x : x; }

int main() {

	while (scanf("%d", &n) != EOF) {

		long long int sum = 0;

		for (int i = 0; i < n; i++) {

			scanf("%d", &list[i]);

			sum += list[i];

		}

		long long int sumi = 0;

		long long int ans = 1e18;

		for (int i = 0; i < n - 1; i++) {

			sumi += list[i];

			long long int tmp = abs(sum - 2 * sumi);

			if (tmp < ans)  ans = tmp;

		}

		printf("%lld\n", ans);

	}

	return 0;

}