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: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A;

vector<ll> neg, pos;

vector< pair<ll, ll> > ans_manu;

ll manu() {
    // pos をひとつ取り出す
    ll cand = pos[pos.size()-1];
    pos.pop_back();

    // neg をひとつにする
    while(neg.size() > 1) {
        ans_manu.push_back(make_pair(cand, neg[neg.size()-1]));
        cand -= neg[neg.size()-1];
        neg.pop_back();
    }

    pos.push_back(cand);
    cand = neg[neg.size()-1];
    neg.pop_back();
    assert(neg.size() == 0);
    // pos をひとつにする
    while(pos.size() > 1) {
        ans_manu.push_back(make_pair(cand, pos[pos.size()-1]));
        cand -= pos[pos.size()-1];
        pos.pop_back();
    }

    // さいごのひとつに cand を引く
    ans_manu.push_back(make_pair(pos[pos.size()-1], cand));
    return pos[pos.size()-1] - cand;
}

signed main()
{
    cin >> N;
    A.resize(N);
    REP(i, N) {
        cin >> A[i];
        if(A[i] < 0) {
            neg.push_back(A[i]);
        }
        else {
            pos.push_back(A[i]);
        }
    }
    SORT(neg);
    SORT(pos);

    ll ans = 0;
    if(neg.size() > 0 && pos.size() > 0) {
        ans = manu();
    }
    else if(neg.size() == 0) {
        // すべてが同じ値
        if(pos[0] == pos[pos.size()-1]) {
            if(N == 2) {
                ans = 0;
                ans_manu.push_back(make_pair(pos[0], pos[1]));
            }
            else if(N == 3) {
                ans = pos[0];
                ans_manu.push_back(make_pair(pos[0], pos[1]));
                ans_manu.push_back(make_pair(pos[1], 0));
            }
            else {
                assert(false);
                ans_manu.push_back(make_pair(pos[0], pos[1]));
                ans_manu.push_back(make_pair(0, pos[0]));
                pos.pop_back();
                pos.pop_back();
                pos.pop_back();
                neg.push_back(-pos[0]);
                ans = manu();
            }
        }
        else {
            ll cand = pos[0] - pos[pos.size()-1];
            ans_manu.push_back(make_pair(pos[0], pos[pos.size()-1]));
            pos.pop_back();
            pos.erase(pos.begin());
            neg.push_back(cand);
            ans = manu();
        }
    }
    else if(pos.size() == 0) {
        if(neg[0] == neg[neg.size()-1]) {
            if(N == 2) {
                ans = 0;
                ans_manu.push_back(make_pair(neg[0], neg[1]));
            }
            else if(N == 3) {
                ans = -neg[0];
                ans_manu.push_back(make_pair(neg[0], neg[1]));
                ans_manu.push_back(make_pair(0, neg[1]));
            }
            else {
                assert(false);
                ans_manu.push_back(make_pair(neg[0], neg[1]));
                ans_manu.push_back(make_pair(0, neg[0]));
                neg.pop_back();
                neg.pop_back();
                neg.pop_back();
                pos.push_back(-neg[0]);
                ans = manu();
            }
        }
        else {
            ll cand = neg[0] - neg[neg.size()-1];
            ans_manu.push_back(make_pair(neg[0], neg[neg.size()-1]));
            neg.pop_back();
            neg.erase(neg.begin());
            pos.push_back(cand);
            ans = manu();
        }
    }
    else {
        assert(false);
    }

    //assert(ans_manu.size() == N - 1);
    printf("%lld\n", ans);
    for(auto& p : ans_manu) {
        printf("%lld %lld\n", p.first, p.second);
    }
    return 0;
}