#include "bits/stdc++.h"
using namespace std;

int main() {
	static long long N, A[200000], SUM = 0, ANS = 1000000000000000;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], SUM += A[i];
	long long Cur = 0;
	for (int i = 0; i < N; i++) {
		ANS = min(ANS, abs(SUM - Cur * 2));
		Cur += A[i];
	}
	cout << ANS << endl;
}