#include<cstdio>
#include<iostream>
using namespace std;

const int maxN = 2e6 + 10;
int n;
int val[maxN];
pair<long long, int> a,b;
int main(){
	//freopen("b2.txt","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&val[i]);
	}

	a.first = 0; a.second = 1;
	b.first = 0; b.second = n;

	while(a.second <= b.second){
		if ( a.first > b.first ){
			b.first += val[b.second];
			b.second -= 1;
		}else {
			a.first += val[a.second];
			a.second +=1;
		}
	}

	printf("%lld\n",abs(a.first-b.first));


	return 0;
}