#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto& x : A) cin >> x;
	long long sum = 0;
	for (auto& x : A) sum += x;
	long long r = 1LL<<60;
	long s = 0;
	for (auto& x : A) {
		s += x;
		r = min(r, abs(sum - s - s));
	}
	cout << r << endl;
}
