stablegradients/pie-gem5-pairs huggingface dataset:
// 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.347180377426694x):
#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:
/*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.2100028131363265x):
#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 n;

int a[200000+5];

long long sum = 0;

long long sum1 = 0;

long long span = (2e5)*(1e9)+5;

int main(){

	scanf("%d",&n);

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

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

		sum = sum + a[i];

	}

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

		sum1 = sum1 + a[i];

		long long m = sum - 2*sum1;

		if(m<0){

			m = -m;

		}

		if(m<span){

			span = m;

		}

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.152458870635083x):
#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;



const long long F = (2e5) * (1e9);



int main()

{

    long long n;

	cin >> n;

	long long* a = new long long[n];

	long long* sum = new long long[n];

    cin >> a[0];

    sum[0] = a[0];

    long long tot = a[0];

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

    {

        cin >> a[i];

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

        tot += a[i];

    }

    long long Min = F;

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

    {

        if(Min > abs(2 * sum[i] - tot))

            Min = abs(2 * sum[i] - tot);

    }

    cout << Min << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.215215132049785x):
#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 "stdio.h"

#include "iostream"

using namespace std;



int main()

{

	long int n, min, A, a[200001], sum = 0;

	cin >> n;

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

		cin >> a[i];

		sum += a[i];

	}

	A = a[1];

	if (sum - 2 * A >= 0)

		min = sum - 2 * A;

	else min = 2 * A - sum;

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

		if (sum - 2 * A <= min && sum - 2 * A >= 0)

			min = sum - 2 * A;

		else if (sum - 2 * A <= 0 && min >= 2 * A - sum)

		{

			min = 2 * A - sum;

		}

		A += a[i + 1];

	}

	cout << min;

}




// Faster C++ solution for the same problem (measured speedup: 5.403813330184953x):
#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 R=0;

long long t,i,N,M;

cin>>N;

M=N-1;

  long long*a= new long long[N];

  long long*b= new long long[M];

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

   {

   cin>>a[i];

    R+=a[i];

   }

    b[0]=a[0];

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

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

    for(i=0;i<N-1;i++)

    if(abs(R-2*b[i])<t||i==0)

      t=abs(R-2*b[i]);

cout<<t;

delete[] a;

delete [] b;

return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.218474288954286x):
#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<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long LL;

const int MAXN=2e5+5;

const int MOD=1000000000;

const LL INF=(2e5)*(1e9)+5;

LL a[MAXN];

LL sum[MAXN];



int main()

{

    ios::sync_with_stdio(false);

    int n;

    while(cin>>n)

    {

        LL tot=0;

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

        {

            cin>>a[i];

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

            tot+=a[i];

        }

        LL Min=INF;

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

        {

            if(Min>abs(2*sum[i]-tot))

                Min=abs(2*sum[i]-tot);

        }

        cout<<Min<<endl;

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.28472583581487x):
#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 ;

}

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

#include<stdlib.h>



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

	if (a > b) {

		return a - b;

	}

	else {

		return b - a;

	}

}



int main() {

	int n;

	long int temp = 0;

	long int sum1 = 0;

	long int sum = 0;

	long int min = 2e+9;

	scanf("%d", &n);

	

	long int *a;

	a = (long int *)malloc(n * sizeof(long int));

	 

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

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

		sum += a[i];

	}

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

		sum1 += a[i];

		temp = value(2 * sum1, sum);

		if (temp < min) {

			min = temp;

		}

	}

	printf("%ld", min);

	return 0;

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

#include <iostream>

#include <vector>



using namespace std;



int main()

{



    int N;

    cin >> N;

    vector<int> a;

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

    {

        int t;

        cin >> t;

        a.push_back(t);

    }



    vector<long long> b;

    b.push_back(a[0]);



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

    {

        b.push_back(b[i-1]+a[i]);

    }



    long long x,y,m=9e18;

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

    {

        x=b[i];

        y=b[N-1]-x;

        if(abs(x-y)<m)

            m=abs(x-y);

    }

    cout << m;







	return 0;

}


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

#include<stdlib.h>



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

	if (a > b) {

		return a - b;

	}

	else {

		return b - a;

	}

}



int main() {

	int n;

	long int temp = 0;

	long int sum1 = 0;

	long int sum = 0;

	long int min = 2e+9;

	scanf("%d", &n);

	

	long int *a;

	a = (long int *)malloc(n * sizeof(long int));

	 

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

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

		sum += a[i];

	}

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

		sum1 += a[i];

		temp = value(2 * sum1, sum);

		if (temp < min) {

			min = temp;

		}

	}

	printf("%ld", min);

	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 ;

}

// Faster C++ solution for the same problem (measured speedup: 5.130025371854902x):
#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("%I64d\n", ans);

	}

	return 0;

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

#include <iostream>

#include <vector>



using namespace std;



int main()

{



    int N;

    cin >> N;

    vector<int> a;

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

    {

        int t;

        cin >> t;

        a.push_back(t);

    }



    vector<long long> b;

    b.push_back(a[0]);



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

    {

        b.push_back(b[i-1]+a[i]);

    }



    long long x,y,m=9e18;

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

    {

        x=b[i];

        y=b[N-1]-x;

        if(abs(x-y)<m)

            m=abs(x-y);

    }

    cout << m;







	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.184954647988846x):
#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("%I64d\n", ans);

	}

	return 0;

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

using namespace std;

int main()

{

	cin.tie(0); 	

	cout.tie(0); 

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	int nums[n];

	long long sum[n];

	cin>>nums[0];

	sum[0]=nums[0]; 

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

	{

		cin >> nums[i];

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

	}

	

	long long min = abs(sum[n-1] - 2*sum[0]);

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

	{

		if(min>abs(sum[n-1] - 2*sum[i]))

			min = abs(sum[n-1] - 2*sum[i]);		

	}	

	cout << min;		

}

// Faster C++ solution for the same problem (measured speedup: 5.191156178341022x):
#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("%I64d\n", ans);

	}

	return 0;

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

using namespace std;

#define MAXN 200005

#define INF 0x3f3f3f3f3f3f3f3f

long long sum[MAXN];

int main()

{

    int n;

    scanf("%d", &n);

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

    {

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

        if(i > 0)

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

    }

    long long min = INF;

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

    {

        long long cha = abs(sum[n - 1] - 2 * sum[i]);

        if(cha < min)

            min = cha;

    }

    cout << min << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.135491735839791x):
#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("%I64d\n", ans);

	}

	return 0;

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

#define Ll long long

using namespace std;

const Ll N=2e5+5;

Ll a[N];

Ll n,m,ans=1e18,x,y;

int main()

{

	cin>>n;

	for(Ll i=1;i<=n;i++)cin>>a[i],x+=a[i];

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

		y+=a[i];

		ans=min(ans,abs(x-y-y));

	}

	cout<<ans;

}

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

#include<algorithm>

#define MN 2100001

using namespace std;

int n,m,a[MN];

long long sum1=0,sum2=0,mmh=1e18;

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

int main()

{

    scanf("%d",&n);

    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum2+=a[i];

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

		if (sum1+=a[i],_abs(sum2-sum1-sum1)<mmh) mmh=abs(sum2-sum1-sum1);

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

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

#define ll long long

using namespace std;

const int N=200005;

ll a[N],f[N],g[N];

ll ans;

int n;

int main()

{

	scanf("%d",&n);

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

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

	}

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

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

	for(int i=n;i;i--)

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

	ans=abs(f[1]-g[2]);

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

		ans=min(abs(f[i-1]-g[i]),ans);

	printf("%lld",ans);

	return 0;

}

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

#include<algorithm>

#define MN 2100001

using namespace std;

int n,m,a[MN];

long long sum1=0,sum2=0,mmh=1e18;

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

int main()

{

    scanf("%d",&n);

    for (int i=1;i<=n;i++) scanf("%d",&a[i]),sum2+=a[i];

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

		if (sum1+=a[i],_abs(sum2-sum1-sum1)<mmh) mmh=abs(sum2-sum1-sum1);

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

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

#define Ll long long

using namespace std;

const Ll N=2e5+5;

Ll a[N];

Ll n,m,ans=1e18,x,y;

int main()

{

	cin>>n;

	for(Ll i=1;i<=n;i++)cin>>a[i],x+=a[i];

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

		y+=a[i];

		ans=min(ans,abs(x-y-y));

	}

	cout<<ans;

}

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

#include<math.h>

#include<algorithm> 

using namespace std;

long long a[200005] = {0}, i, n, m, ans= 99000000000;

int main()

{

	scanf("%lld", &n);

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

	{

		scanf("%lld", &m);

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

	}

	for (i = 1; i<n; i++)ans = min(abs(a[i] * 2 - a[n]), ans);

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

	return 0;

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

#define ll long long

using namespace std;

const int N=200005;

ll a[N],f[N],g[N];

ll ans;

int n;

int main()

{

	scanf("%d",&n);

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

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

	}

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

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

	for(int i=n;i;i--)

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

	ans=abs(f[1]-g[2]);

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

		ans=min(abs(f[i-1]-g[i]),ans);

	printf("%lld",ans);

	return 0;

}

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

#include<math.h>

#include<algorithm> 

using namespace std;

long long a[200005] = {0}, i, n, m, ans= 99000000000;

int main()

{

	scanf("%lld", &n);

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

	{

		scanf("%lld", &m);

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

	}

	for (i = 1; i<n; i++)ans = min(abs(a[i] * 2 - a[n]), ans);

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

	return 0;

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

#define ll long long

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

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

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-'0',ch=getchar();

    return x*f;

}

ll a[200200];

int main()

{

	ll n=read();

	For(i,1,n)

	{

		a[i]=read();

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

	}

	ll ans=1e18;

	For(i,1,n-1)ans=min(ans,abs(a[i]-a[n]+a[i]));

	cout<<ans<<endl;

	return 0;

}


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

#include<math.h>

#include<algorithm> 

using namespace std;

long long a[200005] = {0}, i, n, m, ans= 99000000000;

int main()

{

	scanf("%lld", &n);

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

	{

		scanf("%lld", &m);

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

	}

	for (i = 1; i<n; i++)ans = min(abs(a[i] * 2 - a[n]), ans);

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

	return 0;

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

#include <iostream>

#include <cstring>

#include <cstdio>

#include <cmath>



using namespace std;



long long sum[300000];



int main ()

{

	int n;

	long long ans,a;

	scanf ("%d",&n);

	sum[0]=0;

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

	{

		scanf ("%lld",&a);

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

	}

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

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

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

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

	return 0;

}


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

#include<math.h>

#include<algorithm> 

using namespace std;

long long a[200005] = {0}, i, n, m, ans= 99000000000;

int main()

{

	scanf("%lld", &n);

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

	{

		scanf("%lld", &m);

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

	}

	for (i = 1; i<n; i++)ans = min(abs(a[i] * 2 - a[n]), ans);

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

	return 0;

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

using namespace std;

const int s = 2e5+10;

int arr[s];

long long pre[s];

int main()

{

	int n;

	long long sum,mn;

	while(~scanf("%d",&n)){

		mn=0xffffffffffffffl;

		sum=0;

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

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

			sum+=arr[i];

		}

		pre[0]=arr[0];

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

			pre[i]=pre[i-1]+arr[i];

		}

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

			mn=min(mn,abs(sum-2*pre[i]));

		}

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

	}

	return 0;

}


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

#include<math.h>

#include<algorithm> 

using namespace std;

long long a[200005] = {0}, i, n, m, ans= 99000000000;

int main()

{

	scanf("%lld", &n);

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

	{

		scanf("%lld", &m);

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

	}

	for (i = 1; i<n; i++)ans = min(abs(a[i] * 2 - a[n]), ans);

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

	return 0;

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

#define Ll long long

using namespace std;

const Ll N=2e5+5;

Ll a[N];

Ll n,m,ans=1e18,x,y;

int main()

{

	cin>>n;

	for(Ll i=1;i<=n;i++)cin>>a[i],x+=a[i];

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

		y+=a[i];

		ans=min(ans,abs(x-y-y));

	}

	cout<<ans;

}

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

#include<stdlib.h>

#include<math.h>

#define N 2*1000000

#define min(x,y) (x)<(y)?(x):(y)

long long a[N];

long long sum[N + 400];

long long Min =1e10;

int main() {

	long long n, m;

	scanf("%lld", &n);

	sum[0] = 0;

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

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

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

	}

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

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

	}

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

	return 0;

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

#define ll long long

using namespace std;

const int N=200005;

ll a[N],f[N],g[N];

ll ans;

int n;

int main()

{

	scanf("%d",&n);

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

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

	}

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

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

	for(int i=n;i;i--)

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

	ans=abs(f[1]-g[2]);

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

		ans=min(abs(f[i-1]-g[i]),ans);

	printf("%lld",ans);

	return 0;

}

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

#include<stdlib.h>

#include<math.h>

#define N 2*1000000

#define min(x,y) (x)<(y)?(x):(y)

long long a[N];

long long sum[N + 400];

long long Min =1e10;

int main() {

	long long n, m;

	scanf("%lld", &n);

	sum[0] = 0;

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

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

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

	}

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

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

	}

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

	return 0;

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

#define ll long long

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

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

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-'0',ch=getchar();

    return x*f;

}

ll a[200200];

int main()

{

	ll n=read();

	For(i,1,n)

	{

		a[i]=read();

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

	}

	ll ans=1e18;

	For(i,1,n-1)ans=min(ans,abs(a[i]-a[n]+a[i]));

	cout<<ans<<endl;

	return 0;

}


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

#include<stdlib.h>

#include<math.h>

#define N 2*1000000

#define min(x,y) (x)<(y)?(x):(y)

long long a[N];

long long sum[N + 400];

long long Min =1e10;

int main() {

	long long n, m;

	scanf("%lld", &n);

	sum[0] = 0;

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

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

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

	}

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

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

	}

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

	return 0;

}