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



#include <stdio.h>

using namespace std; 

typedef long ll;



 int main(){



    int length;

    ll arr[200000];

    ll res[200000]={0};

    ll temp = 0;

    ll m = 2147483647;

    scanf("%d",&length);

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

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

   	}

   	res[0] = arr[0];

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

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

    }

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

    	temp = abs(res[length-1]-res[i-1]*2);

    	m = min(temp,m);

    }

    printf("%ld\n", m);





 	return 0;

 }


// Faster C++ solution for the same problem (measured speedup: 2.636976879478713x):
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



int a[200005];

LL s[200005];



int main()

{

    int n;

    scanf("%d",&n);

    s[0]=0;

    rep(i,n)

    {

        cin>>a[i];

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

    }

    LL mn=200000000000001;

    rer(i,1,n-1)

    {

        mn=min(mn,abs(s[n]-s[i]-s[i]));

    }

    cout<<mn<<endl;

    return 0;

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



long long int abs_1(long long int i){

	if(i<0) return -i;

	else return i;

}

int main()

{

	 int N,i,j;

	 long long int sum1=0,sum=0;

	scanf("%d",&N);

	long long int a[200000]={0},x,min=2e+9;

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

	{

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

		sum+=a[i];

	}

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

	{

		sum1+=a[i];

		x=abs_1(2*sum1-sum);

		if(x<=min)

		{

			min=x;

		}

	}

	printf("%lld",min);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8006230624844173x):
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



int a[200005];

LL s[200005];



int main()

{

    int n;

    scanf("%d",&n);

    s[0]=0;

    rep(i,n)

    {

        cin>>a[i];

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

    }

    LL mn=200000000000001;

    rer(i,1,n-1)

    {

        mn=min(mn,abs(s[n]-s[i]-s[i]));

    }

    cout<<mn<<endl;

    return 0;

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

using namespace std;

int main()

{

	int a[200010];

	long long int b[200010];

	int N = 2;

	cin >> N;

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

	{

		cin >> a[i];

	}

	long long int sum = 0;

	long long int m, n;

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

	{

		sum = sum + a[j];

	}

	m = sum;

	n = sum;

	long long int x[200009], y[200009];

	for (int j = 1; j <= (N - 1); j++)

	{

		y[j] = sum - a[j];

		sum = sum - a[j];

	}

	for (int k = 1; k <= (N - 1); k++)

	{

		x[k] = m - y[k];

		m = n;

	}

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

	{

		b[n] = abs(x[n] - y[n]);

	}

	long long int min = b[1];

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

	{

		if (min > b[i])

			min = b[i];

	}

	cout << min<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1235448742020278x):
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



int a[200005];

LL s[200005];



int main()

{

    int n;

    scanf("%d",&n);

    s[0]=0;

    rep(i,n)

    {

        cin>>a[i];

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

    }

    LL mn=200000000000001;

    rer(i,1,n-1)

    {

        mn=min(mn,abs(s[n]-s[i]-s[i]));

    }

    cout<<mn<<endl;

    return 0;

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

#include<cstdlib>

using namespace std;



int main()

{

       long long N;

       long long Sum_t[200000]={0};



       cin>>N;

       cin>>Sum_t[0];

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

       {

             cin>>Sum_t[i];

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

        }



       long long min=abs(Sum_t[N-1]-2*Sum_t[0]);

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

        {

                long long temp=abs(Sum_t[N-1]-2*Sum_t[i]);

                if(temp<min) min=temp;

         }

   

        cout<<min;

        return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.6024163128076085x):
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



int a[200005];

LL s[200005];



int main()

{

    int n;

    scanf("%d",&n);

    s[0]=0;

    rep(i,n)

    {

        cin>>a[i];

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

    }

    LL mn=200000000000001;

    rer(i,1,n-1)

    {

        mn=min(mn,abs(s[n]-s[i]-s[i]));

    }

    cout<<mn<<endl;

    return 0;

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

using namespace std;

long long n,m,a[200005],ans;

int main()

{

	cin>>n;

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

		cin>>a[i];

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

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

	ans=abs(a[1]-(a[n]-a[1]));

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

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

	cout<<ans;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	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.295233775449737x):
#include <stdio.h>

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

using namespace std;



int main(){

    long int a[200000],n,cha;

    

    cin>>n;

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

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

        cin>>a[i];

    }

    

    long int back = 0;

    for(long int j=1;j<n;j++){

        back += a[j];

    }

    

    long int front = a[0];

    

    cha = abs(back - front);

    

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

        front += a[k];

        back -= a[k];

        if(abs(front - back)<cha){

            cha = abs(front -back);

        }

    }

    cout<<cha<<endl;

    //printf("%ld\n",cha);

}


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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

#include<cmath>

using namespace std;

long long a[200000];



int main()

{

	int num;

	long long min, carnum;

	int i = 0;

	cin >> num;

	while ((i <= num - 1)&&cin >> carnum)

	{

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

		++i;

	}

	min = abs(a[num] - a[1] - a[1]);

	for (int j = 2; j < num; j++)

	{

		if (abs(a[num] - a[j] - a[j])<min)

		min = abs(a[num] - a[j] - a[j]);

	}

	cout << min;

    return 0;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

#include<cmath>

using namespace std;



long long int sa(long long int*a,int c,int d){

	long long int res=0;

	for(int i=c;i<=d;i++){

		res += a[i];

	}

	return res;

}





int main(void)

{

	int n = 0;

	cin>>n;

	long long int a[n]={0};

	long long int b[n+1]={0};

	long long int sac = 0;

	long long int pre = 0;long long int las = 0;long long int re = 0;

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

		long long int h =0;

		cin>>h;

		a[k]=h;

		b[k+1]=b[k]+h;

	}

	sac = sa(a,0,n-1);

	long long int res = 0;

	long long int min = 9223372036854775807;

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

	{

		res = abs(sac- 2*b[i+1]);

		if (res < min) min=res;

	}

	cout <<min;

	return 0;

}








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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	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.304922782041246x):
#include <stdio.h>

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

#include<cmath>

using namespace std;

const int MAXN = 2e5 + 100;

long long x,sum[MAXN],n,min_,i;

int main()

{

    cin>>n;

    sum[0]=0;

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

       {

           cin>>x;

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

       }

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

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

   {

       min_=min_<abs(2*sum[i]-sum[n])?min_:abs(2*sum[i]-sum[n]);

   }

    cout<<min_;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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



#include <stdio.h>

using namespace std; 

typedef long ll;



 int main(){



    int length;

    ll arr[200000];

    ll res[200000]={0};

    ll temp = 0;

    ll m = 2147483647;

    scanf("%d",&length);

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

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

   	}

   	res[0] = arr[0];

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

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

    }

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

    	temp = abs(res[length-1]-res[i-1]*2);

    	m = min(temp,m);

    }

    printf("%ld\n", m);





 	return 0;

 }


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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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



long long int abs_1(long long int i){

	if(i<0) return -i;

	else return i;

}

int main()

{

	 int N,i,j;

	 long long int sum1=0,sum=0;

	scanf("%d",&N);

	long long int a[200000]={0},x,min=2e+9;

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

	{

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

		sum+=a[i];

	}

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

	{

		sum1+=a[i];

		x=abs_1(2*sum1-sum);

		if(x<=min)

		{

			min=x;

		}

	}

	printf("%lld",min);

	return 0;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

#include<cmath>

using namespace std;

const int MAXN = 2e5 + 100;

long long x,sum[MAXN],n,min_,i;

int main()

{

    cin>>n;

    sum[0]=0;

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

       {

           cin>>x;

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

       }

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

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

   {

       min_=min_<abs(2*sum[i]-sum[n])?min_:abs(2*sum[i]-sum[n]);

   }

    cout<<min_;

}


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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

using namespace std;

int main()

{

	int a[200010];

	long long int b[200010];

	int N = 2;

	cin >> N;

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

	{

		cin >> a[i];

	}

	long long int sum = 0;

	long long int m, n;

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

	{

		sum = sum + a[j];

	}

	m = sum;

	n = sum;

	long long int x[200009], y[200009];

	for (int j = 1; j <= (N - 1); j++)

	{

		y[j] = sum - a[j];

		sum = sum - a[j];

	}

	for (int k = 1; k <= (N - 1); k++)

	{

		x[k] = m - y[k];

		m = n;

	}

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

	{

		b[n] = abs(x[n] - y[n]);

	}

	long long int min = b[1];

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

	{

		if (min > b[i])

			min = b[i];

	}

	cout << min<<endl;

	return 0;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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

#include<cstdlib>

using namespace std;



int main()

{

       long long N;

       long long Sum_t[200000]={0};



       cin>>N;

       cin>>Sum_t[0];

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

       {

             cin>>Sum_t[i];

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

        }



       long long min=abs(Sum_t[N-1]-2*Sum_t[0]);

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

        {

                long long temp=abs(Sum_t[N-1]-2*Sum_t[i]);

                if(temp<min) min=temp;

         }

   

        cout<<min;

        return 0;

}

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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

}
// Slower C++ solution:
/*g++ main.cpp -o main.out*/

/*./main.out*/

/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/



#include<bits/stdc++.h>

using namespace std;



#define LL long long

#define Mod 1000000007

#define L_Mod 17100000013



const double eps = 1e-9;

const int INF = 0x3f3f3f3f;

const double PI = 3.1415926535;



#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);



#define ree(n,a) memset(n,a,sizeof(n));



#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))



int a[200005];

LL s[200005];



int main()

{

    int n;

    scanf("%d",&n);

    s[0]=0;

    rep(i,n)

    {

        cin>>a[i];

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

    }

    LL mn=200000000000001;

    rer(i,1,n-1)

    {

        mn=min(mn,abs(s[n]-s[i]-s[i]));

    }

    cout<<mn<<endl;

    return 0;

}


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

#include <math.h>

#include <algorithm>

using namespace std;

#define ll long long

const int N=2e5+10;

ll a[N];

int main()

{

	ll n,m,i,j,k,s,t,sum,l,r;

      scanf("%lld",&n);

	{

		sum=0;

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

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

		l=0;

		m=1e15;

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

		 {

		 	l+=a[i];

		 	r=sum-l;

		 	m=min(m,llabs(l-r));

		 }

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

	}

	return 0;

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



#include <stdio.h>

using namespace std; 

typedef long ll;



 int main(){



    int length;

    ll arr[200000];

    ll res[200000]={0};

    ll temp = 0;

    ll m = 2147483647;

    scanf("%d",&length);

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

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

   	}

   	res[0] = arr[0];

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

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

    }

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

    	temp = abs(res[length-1]-res[i-1]*2);

    	m = min(temp,m);

    }

    printf("%ld\n", m);





 	return 0;

 }


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

#define   ll  long long int

#define   sz  1000100



using namespace std;





ll num[sz];





int main()

{





    ll n,b,s=0,k,x,y,a,i,j,d;



    cin>>n;



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

    {

        cin>>num[i];

        s+=num[i];

    }



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

    {

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



    }



        x=num[1];

        y=s-x;

        d=abs(x-y);

        a=d;







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

    {

        x=num[i];

        y=s-x;



        d=abs(x-y);

        a=min(a,d);

    }





    cout<<a<<endl;





    return 0;

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



long long int abs_1(long long int i){

	if(i<0) return -i;

	else return i;

}

int main()

{

	 int N,i,j;

	 long long int sum1=0,sum=0;

	scanf("%d",&N);

	long long int a[200000]={0},x,min=2e+9;

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

	{

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

		sum+=a[i];

	}

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

	{

		sum1+=a[i];

		x=abs_1(2*sum1-sum);

		if(x<=min)

		{

			min=x;

		}

	}

	printf("%lld",min);

	return 0;

}

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

#define   ll  long long int

#define   sz  1000100



using namespace std;





ll num[sz];





int main()

{





    ll n,b,s=0,k,x,y,a,i,j,d;



    cin>>n;



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

    {

        cin>>num[i];

        s+=num[i];

    }



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

    {

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



    }



        x=num[1];

        y=s-x;

        d=abs(x-y);

        a=d;







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

    {

        x=num[i];

        y=s-x;



        d=abs(x-y);

        a=min(a,d);

    }





    cout<<a<<endl;





    return 0;

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

using namespace std;

int main()

{

	int a[200010];

	long long int b[200010];

	int N = 2;

	cin >> N;

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

	{

		cin >> a[i];

	}

	long long int sum = 0;

	long long int m, n;

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

	{

		sum = sum + a[j];

	}

	m = sum;

	n = sum;

	long long int x[200009], y[200009];

	for (int j = 1; j <= (N - 1); j++)

	{

		y[j] = sum - a[j];

		sum = sum - a[j];

	}

	for (int k = 1; k <= (N - 1); k++)

	{

		x[k] = m - y[k];

		m = n;

	}

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

	{

		b[n] = abs(x[n] - y[n]);

	}

	long long int min = b[1];

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

	{

		if (min > b[i])

			min = b[i];

	}

	cout << min<<endl;

	return 0;

}

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

#define   ll  long long int

#define   sz  1000100



using namespace std;





ll num[sz];





int main()

{





    ll n,b,s=0,k,x,y,a,i,j,d;



    cin>>n;



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

    {

        cin>>num[i];

        s+=num[i];

    }



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

    {

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



    }



        x=num[1];

        y=s-x;

        d=abs(x-y);

        a=d;







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

    {

        x=num[i];

        y=s-x;



        d=abs(x-y);

        a=min(a,d);

    }





    cout<<a<<endl;





    return 0;

}