stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
    #include<iostream>

    using namespace std;

    int main(){

    	int n;

    	cin>>n;

    	long long int sum=0;

    	int a[200000];

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

    		cin>>a[i];

    		sum+=a[i];

    	}

    	sum-=a[n-1];

    	long long int k=a[n-1];

    	long long int min=abs(sum-k);

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

    		sum-=a[i];

    		k+=a[i];

    		if(abs(sum-k)<min){

    			min=abs(sum-k);

    		}

    		

    	}

    	cout<<min;

    

    }

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

using namespace std;

#include <cmath>

int A[200000];



int main()

{

int N;

cin >> N ;

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

{

	cin >> A[i];

}	

long long b=A[0];

long long c=0;

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

{

	c = c+A[i]; 

}

long long min = abs(c-b);	

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

b= b+A[i];

c= c-A[i]; 

if(abs(c-b)<min) min=abs(c-b); 

} 

cout << min << endl; 

return 0;	

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

#include<cmath>

#include<cstring>

#include<algorithm>

#define M 200010

#define inf 2000000010

using namespace std;

int n,a[M];

long long ans,t,sum;

int main()

{

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

    {

        sum = 0; ans = inf; t = 0;

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

        {

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

            sum+=a[i];

        }

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

       {

            t += a[i];

            if(ans > abs(2 * t - sum))

                ans = abs(2 * t - sum);

       }

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

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 200020

#define ll long long

using namespace std;

inline ll read(){

	ll x=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());

	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return f?x:-x;

}

ll a[N], sum, ans = 1ll << 60;

int main(int argc, char const *argv[]) {

	int n = read();

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

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

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

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

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

	}

	cout << ans << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

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

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

#define ll long long

#define inf 1e8

using namespace std;

inline ll read()

{

	ll t=0,f=1;char c=getchar();

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

	while(c>='0'&&c<='9')	t=t*10+c-48,c=getchar();

	return t*f;

}

ll a[200001],sum[200001],ans=1e17,n;

int main()

{

	n=read();

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

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

	Dow(i,1,n-1)

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

	cout<<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define int long long

using namespace std;

int read(){

	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();

	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();

	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;

}int n,a[1000000],ans;

signed main(){

	n=read();for (int i=1;i<=n;i++)a[i]=read()+a[i-1];

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

	cout<<ans<<endl;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()

{

	cin.tie(0);

	cout.tie(0);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	ll *a = new ll[n];

	ll* b = new ll[n];

	int tmp = 0;

	while (n--)

		cin >> a[tmp++];

	b[0] = a[0];

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

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

	ll min = abs(b[tmp-1] - 2 * b[0]);

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

		min =((min > abs(b[tmp-1] - 2 * b[i])) ? (abs(b[tmp-1] - 2 * b[i])) : min);

	cout << min << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef set<int> si;



const int SIZE = 2e5 + 10;



ll s[SIZE] = {0};



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    int n;

    ll t;

    cin >> n;

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

    {

        cin >> t;

        s[i] = s[i - 1] + t;

    }

    ll res = LONG_MAX;

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

        res = min(res, abs(s[n] - 2 * s[i]));



    cout << res << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

#include<cmath>

using namespace std;

long long a[200050];

int main(){



	int n,i,j;

	long long x=0,y=0,sum=0;

	cin>>n;

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

		cin>>a[i];

		y+=a[i];

	}

	sum = abs(y-a[0]*2);

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

		x+=a[i];

		y-=a[i];

		if(abs(x-y)<sum) sum=abs(x-y);

	}

	cout<<sum;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	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>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

#include <cmath>

#include<algorithm>

using namespace std;

int a[200005];

long long int s[200005],r[200005],m[200005],sum=0;

int main()

{

	int n;

	r[0]=0;

	scanf("%d",&n);

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

	    {

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

	    sum=sum+a[i];

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

	    }

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

	{

		r[j]=sum-s[j];

		m[j]=abs(s[j]-r[j]);

	}

	sort(m,m+n);

	printf("%d\n",m[1]);

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>



//记得修改scanf_s

int main()

{

	long int n,*a;

	scanf("%ld", &n);

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

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

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



	double sum = 0, sum1 = 0;

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

		sum += a[i];



	long int min = fabs(2 * a[0] - sum);

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

	{

		sum1 += a[i];

		if (min > fabs(2 * sum1 - sum))

			min = fabs(2 * sum1 - sum);

	}

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

	return 0;

}

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

#include <vector>

#include <algorithm>

#include <string>

#include <map>

#include <cmath>

#include <queue>

#include <numeric>

#include <climits>

#include <iterator>

#include <iomanip>

#include <stack>

#include <bitset>

#include <functional>

using namespace std;

const constexpr int INF = 1e9;

//typedef std::pair<std::string,double> P;



typedef long long ll;

typedef vector<int> VI;



#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)



//グラフの隣接リスト

VI g[200010];

//頂点の入次数を管理

int h[100010];

ll N;



int a[200010];

ll sum[200010];

signed main(void) {

    cin >> N;

    REP(i, N) cin >> a[i];

    FOR(i, 0, N) sum[i+1] = sum[i]+a[i];

    

    ll ans=10000000000;

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

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

    }

    cout << ans << endl;

	return 0;

}


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

#include <vector>

#include <algorithm>

#include <string>

#include <queue>

using namespace std;

using ll = long long;

#define INF 1LL << 59

//西暦⇒時代の歴



ll a[201000];

ll N;

int main()

{

    cin >> N;

    ll l = 0LL;

    ll r = 0;

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

    {

        cin >> a[i];

    }

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

        r += a[i];



    ll minV = INF;



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

    {

        l += a[i];

        r -= a[i];

        minV = min(minV, abs(l - r));

    }

    cout << minV << endl;

    return 0;

}

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

}

// 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 <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);

}

// 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):
//周♂雨扬是最强的！！！

//大佬祝您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

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

// 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;



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;

}

// 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 <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);

}
















// 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 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;

}

// 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: