#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  long long s = 0;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    s += A[i];
  }
  long long t = 0, ans = 1e18;
  for(int i = 0; i < N; ++i){
    t += A[i];
    ans = min(ans,abs(t-(s-t)));
  }
  cout << ans << endl;
}
