#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
  int N; cin>>N;
  vector<ll> d(N+1,0);
  for(int i=0;i<N;i++){
    ll x; cin>>x;
    d.at(i+1)=d.at(i)+x;
  }
  ll SUM=d.at(N);
  ll ans=BIG;
  for(int i=0;i<N;i++) ans=min(abs(SUM-2*d.at(i)),ans);
  cout<<ans<<endl;
}
