#include<stdio.h>
int main()
{
	int a[200000];
	int i, j, n;
	long sum1 = 0, min = 2e9,sum2=0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum1 += a[i];
	}
	for (i = 0; i < n; i++)
	{
		sum2 += a[i];
		if (sum1>2 * sum2)
		{
			j = sum1 - 2 * sum2;
			min = min < j ? min : j;
		}
		else
		{
			j =  2 * sum2 - sum1;
			min = min < j ? min : j;
		}
	}
	printf("%d", min);
	return 0;
}