#include <iostream>
#include <math.h>

using namespace std;

int main(){
  int i, N;
  cin >> N;
  long long n[N];
  
  for(i = 0 ; i < N ; i++){
	cin >> n[i];
  }
  
  long long sum_f = 0, sum_r = 0;
  for(i = 0 ; i < N ; i++){
    sum_r += n[i];
  }
  
  long long min = sum_r, min_f, min_r;
  int flag = 1;
  for(i = 1 ; i <= N ; i++){
    sum_f += n[i-1];
    sum_r -= n[i-1];
    if(sum_f == sum_r){
      flag = 0;
      break;
    }else if(min > abs((sum_f - sum_r)) ){
      min_f = i;
      min_r = N - i;
      min = abs((sum_f - sum_r));
    }
  }
    
  if(flag == 1){
    cout << min << endl;
  }else{
    cout << 0 << endl;
  }
 
  
  
  return 0;
}
  