#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<long long> a(n);
	long long sum = 0, cur = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	long long ans = sum;
	for(int i = 0; i < n; i++){
		cur += a[i];
		ans = min(ans, abs(sum - 2 * cur));
	}
	cout << ans << endl;
	return 0;
}
