Problem:
Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.

They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

Constraints

2 \leq N \leq 2 \times 10^5

-10^{9} \leq a_i \leq 10^{9}

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Print the answer.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	vi d;
	
	rep(kk , 9){
		int l = 0 , r = 9;
		while(r - l > 1){
			int mid = (r + l) / 2;
			cout << flush << "? ";
			rep(i , 12){
				cout << (i < sz(d) ? d[i] : (i == sz(d) ? mid : 9));
			}
			cout << nl << flush;
			string ans;
			cin >> ans;
			if(ans == "Y"){
				r = mid;
			}else{
				l = mid;
			}
		}
		d.pb(r);
		if(kk == 8)break;
		cout << flush << "? ";
		for(int e : d)cout << e;
		cout << "0" << nl << flush;
		string ans;
		cin >> ans;
		bool ck1 = ans == "Y";
		cout << flush << "? ";
		for(int e : d)cout << e;
		cout << "9" << nl << flush;	
		cin >> ans;
		bool ck2 = ans == "Y";
		if((ck1 || ck2) == 0)break;
	}
	cout << flush << "! ";
	for(int e : d)cout << e;

	return 0;
}