#include <bits/stdc++.h>
using namespace std;
int n,i,a[200200];
long long s,cur,r;
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
    s+=a[i];
  }
  r=s;
  for (i=0; i<n; i++) {
    cur+=a[i];
    r=min(r,abs(s-cur-cur));
  }
  printf("%d\n",r);
  return 0;
}
