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