// C - Splitting Pile
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vl X(N+1);//累積和
	rp(i, 1, N+1){
		int a; cin>>a;
		X[i] = X[i-1] + a;
	}
	ll ans = LLONG_MAX;
	rp(i, 1, N) ans = min(ans, abs(X[i]*2 - X[N]));
	cout<< ans <<endl;
}