#include<bits/stdc++.h>
#define ll long long

using namespace std;

const ll N = 1700000, M = 1e5 + 3;
const ll BIG = 9e18, CH = 27;
const double EPS = 1e-5;

int compr(double a, double b) {
	if (abs(a - b) < EPS)
		return 0;
	if (a < b)
		return -1;
	return 1;
}

struct line;

struct point {
	double x, y;
	point() {
	}
	point(double xx, double yy) {
		x = xx, y = yy;
	}
	point operator-(point p2) {
		point p1;
		p1.x = x - p2.x;
		p1.y = y - p2.y;
		return p1;
	}
	bool operator<(const point &p2) const {
		return y < p2.y || (y == p2.y && x < p2.x);
	}
	friend istream& operator>>(istream& is, point &p1) {
		is >> p1.x >> p1.y;
		return is;
	}
	friend ostream& operator<<(ostream& os, point &p1) {
		os << p1.x << " " << p1.y << " ";
		return os;
	}
};

struct segment {
	point a, b;
	segment() {
	}
	segment(point p1, point p2) {
		a = p1, b = p2;
	}
};

struct circle {
	point o;
	double r;
	circle() {
	}
	circle(point p1, double rr) {
		o = p1, r = rr;
	}
	friend istream& operator>>(istream& is, circle &c1) {
		is >> c1.o >> c1.r;
		return is;
	}
};

struct line {
	//a * x + b * y + c = 0
	double a, b, c;
	line() {
	}
	line(double aa, double bb, double cc) {
		a = aa, b = bb, c = cc;
	}
	line(point p1, point p2) {
		a = p2.y - p1.y;
		b = p1.x - p2.x;
		c = -(a * p1.x + b * p1.y);
	}
	friend istream& operator>>(istream& is, line &l1) {
		is >> l1.a >> l1.b >> l1.c;
		return is;
	}
	friend ostream& operator<<(ostream& os, line &l1) {
		os << l1.a << l1.b << l1.c;
		return os;
	}
};

const point zero = point(0, 0);

double cross_product(point p1, point p2) {
	// |a| * |b| * sin ab
	return p1.x * p2.y - p1.y * p2.x;
}

double dot_product(point p1, point p2) {
	// |a| * |b| * cos ab
	return p1.x * p2.x + p1.y * p2.y;
}

double dist(point p1, point p2) {
	return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

double area(point p1, point p2, point p3) {
	p2.x -= p1.x;
	p3.x -= p1.x;
	p2.y -= p1.y;
	p3.y -= p1.y;
	return cross_product(p2, p3) / 2;
}

point crossing(line l1, line l2) {
	double det = l1.a * l2.b - l2.a * l1.b;
	point p;
	p.x = -(l1.c * l2.b - l2.c * l1.b) / det;
	p.y = -(l1.a * l2.c - l2.a * l1.c) / det;
	return p;
}

bool lines_parallel(line l1, line l2) {
	return abs(l1.a * l2.b - l2.a * l1.b) < EPS;
}

double dist_to_line(point p1, line l1) {
	return abs(l1.a * p1.x + l1.b * p1.y + l1.c)
			/ sqrt(l1.a * l1.a + l1.b * l1.b);
}

vector<segment> fig;

bool between(point a, point o, point b, point p) {
	a = a - o;
	b = b - o;
	p = p - o;
	if (cross_product(a, p) >= 0 && cross_product(p, b) >= 0
			&& cross_product(a, b) >= 0) {
		return true;
	}

	if (cross_product(a, p) <= 0 && cross_product(p, b) <= 0
			&& cross_product(a, b) <= 0) {
		return true;
	}
	return false;
}

bool in_fig(point fr) {
	point to = point(rand(), rand());
//  cout << fr << "- fr, " << to << "- to\n";
	int num_cross = 0;
	for (int i = 0; i < (int) fig.size(); i++) {
		if (between(fig[i].a, fr, fig[i].b, to)) {
//          cout << fig[i].a << " " << fig[i].b << "\n";
			num_cross++;
		}
	}
//  cout << num_cross << "\n\n";

	return num_cross % 2 == 1;
}

bool point_in_segment(point p1, segment s1) {
	line l1 = line(s1.a, s1.b);
	if (compr(p1.x * l1.a + p1.y * l1.b + l1.c, 0) == 0) {
		if (compr(dist(s1.a, s1.b), dist(s1.a, p1) + dist(s1.b, p1)) == 0) {
			return true;
		}
	}
	return false;
}

double dist_to_segm(point p1, segment s) {
	point a = s.a, b = s.b;
	if (dot_product(b - a, p1 - a) < 0 || dot_product(a - b, p1 - b) < 0)
		return min(dist(p1, a), dist(p1, b));
	else
		return dist_to_line(p1, line(a, b));
}

int main() {
	//freopen("distance.in", "r", stdin), freopen("distance.out", "w", stdout);
	cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
	ll n, sum = 0, ans = 1e18, frst = 0;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	for (int i = 0; i < n - 1; i++) {
		frst += a[i];
		ans = min(ans, abs(frst - (sum - frst)));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792