#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ans=1e18+7;
int a[200007];
ll sum[200007];
int main(){
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",a+i);
	for (int i=0;i<n;i++) sum[i]=(i?sum[i-1]:0)+a[i];
	for (int i=0;i<n;i++){
		ans=min(ans,abs(sum[n-1]-sum[i]-sum[i]));
	}
	printf("%lld\n",ans);
	return 0;
} 