#include<bits/stdc++.h>
using namespace std;

int main(){

	int long long n;
	int long long suma1 = 0;
	int long long suma2 = 0;
	cin>>n;
	int vec[n];
	for( int i=0 ; i<n ; i++ ){
		cin>>vec[i];
	}

	int k = n-1;
	int i = 0;
	suma1 = vec[i];
	suma2 = vec[k];
	k--;
	i++;
	while( k>=i ){
		if( (suma1 + vec[i]) > (suma2 + vec[k]) ){
			suma2 = suma2 + vec[k];
			k--;
		}else{
			suma1 = suma1 + vec[i];
			i++;
		}
	}

	if( suma1>suma2 ){
		cout<<suma1-suma2<<endl;
	}else{
		cout<<suma2-suma1<<endl;
	}

	return 0;
}