#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N), sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}
	ll res = sum[N];
	for (int i = 1; i < N; i++) {
		res = min(res, abs(sum[i] * 2 - sum[N]));
	}
	cout << res << endl;
	return 0;
}
