#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);

    long long sum=0, minNum=2020202021, sum2=0;

    for(int i=0; i<N; i++){
	cin >> a[i];
	sum += a[i];
    }
    for(int i=0; i<N; i++){
	sum-=a[i];
	sum2+=a[i];

	if(abs(sum-sum2) < minNum)
	    minNum=abs(sum-sum2);
    }
    cout << minNum << endl;
}

