stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


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

#include <climits>

#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <cmath>

#include <stack>

#include <algorithm>

#include <random>

#include <iomanip>

#include <unordered_map>

#include <map>

#include <queue>

#include <functional>

#include <numeric>

#include <chrono>

#include <cstdlib>

using ll = long long;

using namespace std;



const ll MOD = 1e9 + 7;

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

const double pi = acos(-1);

typedef pair<int, int> P;

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

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

#define EPS 1e-4

#define OUTPUT(i) (cout << (ll)i << endl)

#define ALL(a) ((a).begin(), (a).end())



bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)

{



    if (a.first == b.first)

        return a.second < b.second;



    return a.first < b.first;

}



ll arr[200010];



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(10);



    ll N;

    cin >> N;

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

    {

        cin >> arr[i];

        if (i > 0)

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

    }



    ll ans = 10000000000;

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

    {

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

    }

    cout << ans << endl;

    return 0;

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

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

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

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

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

#include<cstdio>

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<cassert>

#include<algorithm>

#include<cmath>



#include<cstring>

#include<string>

#include<cctype>

#include<utility>

#include<vector>

#include<stack>

#include<queue>

#include<deque>

#include<map>

#include<set>

#include<list>



typedef long long ll;

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

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

typedef std::vector<int> vi;



const int OO=(int)2e9;

const ll INF=(ll)4e18;

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



#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front



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

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

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

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

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

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

using namespace std;



int n;

ll dat[200005];

ll res;



int main(){

	scanf("%d",&n);

	dat[0]=0;

	REP(i,1,n){

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

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

	}

	res=INF;

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

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

	return 0;

}

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

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

using namespace std;

typedef long long ll;

const int MAXSIZE=30000020;

const ll INF=0x3f3f3f3f3f3f3f3fLL;

int bufpos;

char buf[MAXSIZE];

#define NEG 1

void init(){

	#ifdef LOCAL

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

	#endif

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

	bufpos=0;

}

#if NEG

int readint(){

	bool isneg;

	int val=0;

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

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

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

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

	return isneg?-val:val;

}

#else

int readint(){

	int val=0;

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

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

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

	return val;

}

#endif

char readchar(){

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

	return buf[bufpos++];

}

int readstr(char* s){

	int cur=0;

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

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

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

	s[cur]='\0';

	return cur;

}

ll sum[200002];

ll myabs(ll x){

	return x>0?x:-x;

}

int main(){

	init();

	int n=readint();

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

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

	ll ans=INF;

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

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

	printf("%lld",ans);

}

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

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

//大佬祝您AK

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

#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<fstream>

using namespace std;

//ifstream fin(.in);

//ofstream fout(.out);

long long n,num[400003];

int main(){

	cin>>n;

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

		cin>>num[i];

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

	}

	long long ans=999999999999;

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

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

	}

	cout<<ans<<endl;

	return 0;

}

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

//大佬祝您AK

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

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

}
// 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.2898391000830225x):
#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;

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

#include <cstdlib>

#include <cmath>

#include <cstring>

#include <string>

#include <algorithm>

#include <iostream>

#include <iomanip>

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

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

#define LL long long

using namespace std ;



inline LL read() {

	LL x = 0 , f = 1 ;

	char ch = getchar() ;

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

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

	return x * f ;

}



const int N = 2e5+11;

int n;

int a[N];

LL ans;

LL L[N],R[N];



int main() {

	n=read();

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

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

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

	ans = 1e18;

	For(i, 1, n-1) 

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

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

}
















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

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

using namespace std;



int main()

{

	int N;

	long long int * a;

	long long int sum=0, min;

	cin >> N;

	a = new long long int[N];

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

		cin >> a[i];

		sum += a[i];

	}

	sum -= 2 * a[0];

	min = abs(sum) ;

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

		sum -= 2 * a[i];

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

	}

	cout << min;

    return 0;

}

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

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

#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cmath>



using namespace std;



#define N 200008



int n;

int a[N];

long long sum = 0;



void solve()

{

	long long first = a[1];

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

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

	{

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

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

	}

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

}



void init()

{

	scanf("%d", &n);

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

	{

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

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

	}

}



int main()

{

	init();

	solve();

	return 0;

}

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

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

#include <cmath>

using namespace std;



int main() {

	int length;

	long long sum = 0;

	cin >> length;

	int *a = new int[length];

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

		cin >> a[i];

		sum += a[i];

	}

	long long sum1 = a[0];

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

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

		sum1 += a[i];

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

			min = abs(sum-2*sum1);

	}

	cout << min << endl;

}

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

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

#include<cmath>



using namespace std;



int main()

{

	long long a[200005];

	int n,i;

	long long s(0),min;

	cin>>n;

	a[0]=0;

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

	{

		cin>>a[i];

		s+=a[i];

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

	}

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

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

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

	cout<<min<<endl;

	return 0;

}

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

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

#include<iostream>

#include<algorithm>

using namespace std;



const int maxN = 2e6 + 10;

int n;

long long val[maxN];

long long sum[maxN];



int main(){

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

	scanf("%d",&n);

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

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

	}

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

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

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

	}	

	long long res = 5e18;

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

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



		res = min(res, t);



	}

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





	return 0;

}

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

}
// 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.362147592932565x):
#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;

}
// 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.2245860568996365x):
#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;

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

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

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

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

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

#include<cstdio>

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<cassert>

#include<algorithm>

#include<cmath>



#include<cstring>

#include<string>

#include<cctype>

#include<utility>

#include<vector>

#include<stack>

#include<queue>

#include<deque>

#include<map>

#include<set>

#include<list>



typedef long long ll;

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

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

typedef std::vector<int> vi;



const int OO=(int)2e9;

const ll INF=(ll)4e18;

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



#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front



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

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

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

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

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

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

using namespace std;



int n;

ll dat[200005];

ll res;



int main(){

	scanf("%d",&n);

	dat[0]=0;

	REP(i,1,n){

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

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

	}

	res=INF;

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

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

	return 0;

}

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

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

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

    {

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

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

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

        }



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

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

        {

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

        }

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

    }

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

using namespace std;

typedef long long ll;

const int MAXSIZE=30000020;

const ll INF=0x3f3f3f3f3f3f3f3fLL;

int bufpos;

char buf[MAXSIZE];

#define NEG 1

void init(){

	#ifdef LOCAL

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

	#endif

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

	bufpos=0;

}

#if NEG

int readint(){

	bool isneg;

	int val=0;

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

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

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

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

	return isneg?-val:val;

}

#else

int readint(){

	int val=0;

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

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

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

	return val;

}

#endif

char readchar(){

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

	return buf[bufpos++];

}

int readstr(char* s){

	int cur=0;

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

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

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

	s[cur]='\0';

	return cur;

}

ll sum[200002];

ll myabs(ll x){

	return x>0?x:-x;

}

int main(){

	init();

	int n=readint();

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

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

	ll ans=INF;

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

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

	printf("%lld",ans);

}

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

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

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

    {

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

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

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

        }



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

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

        {

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

        }

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

    }

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

//大佬祝您AK

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

#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<fstream>

using namespace std;

//ifstream fin(.in);

//ofstream fout(.out);

long long n,num[400003];

int main(){

	cin>>n;

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

		cin>>num[i];

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

	}

	long long ans=999999999999;

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

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

	}

	cout<<ans<<endl;

	return 0;

}

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

//大佬祝您AK

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

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

#include<algorithm>

#include<cmath>

using namespace std;

const int maxn = 2e5+10;

long long sum[maxn];

int n;



int main()

{

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

    {

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

        {

            long long a;

            scanf("%lld",&a);

            if(i==1)

            {

                sum[1] = a;

                continue;

            }

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

        }



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

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

        {

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

        }

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

    }

}