#include <bits/stdc++.h>
#define int int64_t
using namespace std;

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for (int i=0; i<n; ++i){
		 cin >> v[i];
		sum += v[i];
	}
	int crt = 0,maxi = sum;
	for (int i=0; i<n; ++i){
		crt += v[i];
		sum -= v[i];
		maxi = min(maxi,abs(crt-sum));
	}
	cout << maxi;
	return 0;
}
