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 int ll;
#define m 1000000007
#define MAXN 1000001
#define satya ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cil(a,b) (((a-1)/b)+1)
//#define init int t;cin>>t;while(t--)
#define in(a) ll a;scanf("%lld",&a)
#define ine(a,b) ll a,b;scanf("%lld lld",&a,&b)



ll spf[MAXN]; 

void sieve1() 
{ 
	spf[1] = 1; 
	for (int i=2; i<MAXN; i++) 

		spf[i] = i; 

	for (int i=4; i<MAXN; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<MAXN; i++) 
	{ 
		if (spf[i] == i) 
		{ 
			for (int j=i*i; j<MAXN; j+=i) 

				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 

ll  getFactorization(int x) 
{ 
	vector<int> ret; 
	long long int p=0;
	while (x != 1) 
	{ 
		ret.push_back(spf[x]); 
		x = x / spf[x]; 
	} 
	sort(ret.begin(),ret.end());
	for(int i=0;i<ret.size()-1;i++) 
	{
	    if(ret[i]!=ret[i+1])
	    p=p+ret[i];
	}
	p=p+ret[ret.size()-1];
	return p;
} 

ll d[1000055],u=0;
void Sieve(int n) 
{ 
	bool prime[n+1]; 
//	ll u=0;
	memset(prime, true, sizeof(prime)); 

	for (int p=2; p*p<=n; p++) 
	{ 
		if (prime[p] == true) 
		{ 
			for (int i=p*2; i<=n; i += p) 
				prime[i] = false; 
		} 
	} 

	for (int p=2; p<=n; p++) 
	if (prime[p]) 
	{
	    d[u]=p;
	    u++;
	}
} 

ll minverse(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return minverse((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*minverse((x*x)%M,(n-1)/2,M))%M;

}
ll prime(ll n){
    ll i;
    if(n==1||n==0)
    return 0;
    for(i=2;i<sqrt(n);i++)
    {
        if(n%i==0)
        return 0;
    }
    return 1;
}
int main() {
       satya;
     //sieve1(); 
     //Sieve(100);
    	   
ll n,k;
cin>>n;
ll a[n],i;
for(i=0;i<n;i++)
cin>>a[i];
if(n==1)
{
    cout<<a[0]<<endl;
}
else if(n==2)
{
    cout<<max(a[0],a[0])-min(a[0],a[1])<<endl;
    cout<<max(a[0],a[1])<<" "<<min(a[0],a[1])<<endl;
}
else
{
    sort(a,a+n);
    vector<pair<ll,ll> >v;
    ll p=0;
    if(a[0]>0)
    {
        v.push_back(make_pair(a[0],a[1]));
        p=a[0]-a[1];
        for(i=3;i<n-1;i++)
        {
            v.push_back(make_pair(p,a[i]));
            p=p-a[i];
        }
                    v.push_back(make_pair(a[n-1],p));
                    p=a[n-1]-p;

    }
    else
    {
        ll b[n],u=0,c[n],c1=0;
        for(i=0;i<n;i++)
        {
            if(a[i]<0)
            {
                b[u]=a[i];
                u++;
            }
            else
            {
                c[c1]=a[i];
                c1++;
            }
        }
        // cout<<c1<<" "<<u<<endl;
        if(u>0&&c1>0)
        {
            for(i=0;i<u;i++)
            {
                if(c1>1){
                v.push_back(make_pair(b[i],c[0]));
                 c[0]=b[i]-c[0];
                }
                else
                {
                v.push_back(make_pair(c[0],b[i]));
                 c[0]=c[0]-b[i];
                    
                }
            }
        }
        else if(u>0&&c1==0)
        {
            p=b[0]-b[1];
                        v.push_back(make_pair(b[0],b[1]));
             for(i=2;i<u;i++)
             {
                 p=p-b[i];
                                        v.push_back(make_pair(p,b[i]));
 
             }
             c[c1]=p;
             c1++;
        }
      if(c1>1){
                    sort(c,c+c1);
                    
            // for(i=0;i<c1;i++)
            // cout<<c[i]<<" ";
            // cout<<endl;
          if(c1==2)
          {
            //   c[0]=c[1]-c[0];
                               v.push_back(make_pair(c[1],c[0]));
               p=c[1]-c[0];
            // cout<<c[1]<<" "<<c[0]<<endl;
              c1=1;
          }
          else{
        p=c[0]-c[1];
                 v.push_back(make_pair(c[0],c[1]));

        for(i=3;i<c1-1;i++)
        {
            v.push_back(make_pair(p,c[i]));
            p=p-a[i];
        }
               if(c1>=3){
                    v.push_back(make_pair(c[c1-1],p));
                    p=a[c1-1]-p;
      }}
      }
    }
    cout<<p<<endl;
    for(i=0;i<v.size();i++)
    cout<<v[i].first<<" "<<v[i].second<<endl;
}
    return 0;
}