stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*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;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

const int MAX = 2e5 + 5;

int a[MAX];

int main() {

	int n;

	long long sum = 0;

	scanf("%d", &n);

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

	{

		scanf("%d", a + i);

		sum += a[i];

	}

	

	long long left,right,temp;

	

	left = sum - a[n - 1];

	right = a[n - 1];

	long long min = left > right ? left - right : right - left;

	left = 0;

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

		left += a[i];

		right = sum - left;

		temp = left > right ? left - right : right - left;

		if (temp < min)

			 min=temp;

	}

	printf("%d\n", min);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 ;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;		

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<math.h>

using namespace std;



#define long_long_max 9223372036854775807



int main()

{

	int n;

	cin >> n;

	long long total = 0;

	long long *p = (long long*)malloc(n * sizeof(long long));

	long long *p1 = (long long*)malloc(n * sizeof(long long));

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

	{

		cin >> p[i];

		total = total + p[i];

	}

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

	{

		if (i != 0)

		{

			p1[i] = p1[i - 1] + p[i];

		}

		else

		{

			p1[i] = p[i];

		}

	}

	long long min = long_long_max;

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

	{

		if (abs(2 * p1[i] - total) < min)

		{

			min = abs(2 * p1[i] - total);

		}

	}

	cout << min << endl;

	free(p); free(p1);

	return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: