Problem:
Score : 500 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on a blackboard.

We will repeat the following operation N-1 times so that we have only one integer on the blackboard.

Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.

Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.

Constraints

2 \leq N \leq 10^5

-10^4 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.

Here x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.

If there are multiple sequences of operations that maximize the final integer, any of them will be accepted.

M
x_1 y_1
:
x_{N-1} y_{N-1}

Sample Input 1

3
1 -1 2

Sample Output 1

4
-1 1
2 -2

If we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).

Then, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).

In this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.

Sample Input 2

3
1 1 1

Sample Output 2

1
1 1
1 0

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

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> pos, neg;
    int ans = 0;
    int lf, rf;
    rep(i, 0, n){
        if(a[i] < 0){
            neg.push_back(a[i]);
        }else{
            pos.push_back(a[i]);
        }
    }
    reverse(neg.begin(), neg.end());
    if(neg.size() == 0){
        rf = pos[0];
        lf = pos[1];
        pos.erase(pos.begin());
        pos.erase(pos.begin());
    }else if(pos.size() == 0){
        lf = neg[0];
        rf = neg[1];
        neg.erase(neg.begin());
        neg.erase(neg.begin());
    }else{
        lf = pos[0];
        rf = neg[0];
        pos.erase(pos.begin());
        neg.erase(neg.begin());
    }
    ans -= rf;
    ans += lf;
    rep(i, 0, pos.size()) ans += pos[i];
    rep(i, 0, neg.size()) ans -= neg[i];
    cout << ans << endl;
    // right
    int rtmp = rf;
    rep(i, 0, pos.size()){
        cout << rtmp << ' ' << pos[i] << endl;
        rtmp = rtmp - pos[i];
    }
    // left
    int ltmp = lf;
    rep(i, 0, neg.size()){
        cout << ltmp << ' ' << neg[i] << endl;
        ltmp = ltmp - neg[i];
    }
    cout << ltmp << ' ' << rtmp << endl;
    int tmp = ltmp - rtmp;
    assert(tmp == ans);
}