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)

#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) ((int)x.size())
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> pos;
    vector<ll> neg;
    vector<ll> zer;
    F0R(i, n)
    {
        int tmp;
        cin >> tmp;
        if(tmp > 0) pos.pb(tmp);
        if(tmp < 0) neg.pb(tmp);
        if(tmp == 0) zer.pb(tmp);
    }
    vector<ll> v;
    int p = sz(pos), ne = sz(neg), z = sz(zer);
    F0R(i, sz(pos)) v.pb(pos[i]);
    F0R(i, sz(neg)) v.pb(-1 * neg[i]);
    F0R(i, sz(zer)) v.pb(0);
    ll xres = 0;
    if(p > 0 && ne > 0 || z > 0)
    {
        F0R(i, n)
        {
            xres += v[i];
        }
    }
    else
    {
        sort(v.begin(), v.end());
        FOR(i, 1, n)
        {
            xres += v[i];
        }
        xres -= v[0];
    }
    cout << xres << "\n";
    if(sz(neg) == 0 && sz(zer) != 0) neg = zer;
    else
    {
        F0R(i, sz(zer)) pos.pb(zer[i]);
    }
    if(sz(pos) > 0 && sz(neg) > 0)
    {
        ll pres = neg[0], nres = pos[0];
        FOR(i, 1, sz(pos))
        {
            cout << pres << " " << pos[i] << "\n";
            pres -= pos[i];
        }
        FOR(i, 1, sz(neg))
        {
            cout << nres << " " << neg[i] << "\n";
            nres -= neg[i]; 
        }
        cout << nres << " " << pres;
    }
    else
    {
        if(sz(pos) > 0)
        {
            sort(pos.begin(), pos.end());
            ll res = pos[0];
            FOR(i, 1, sz(pos) - 1)
            {  
                cout << res << " " << pos[i] << "\n";
                res -= pos[i];
            }
            cout << pos[sz(pos) - 1] << " " << res << "\n";
        }
        else
        {
            sort(neg.begin(), neg.end(), greater<int>());
            ll res = neg[0];
            FOR(i, 1, sz(neg))
            {  
                cout << res << " " << neg[i] << "\n";
                res -= neg[i];
            }
        }
    }
    return 0;
}