#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n,a[1000001],sum,ans=1e18,sum2;
int main()
{
  cin>>n;
  for (int i=1;i<=n;++i)
    {
      cin>>a[i];
      sum+=a[i];
    }
  for (int i=1;i<=n;++i)
    {
      sum2+=a[i];
      ans=min(ans,(long long)(abs(sum2*2-sum)));
    }
  cout<<ans<<endl;
  return 0;
}