/*
    ASEEN AAN 
            PINDAN AALE JATT!!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,x,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    ll a[n+1];
    lli s=0;
    lli ff=0;
    lli f=0;
    lli b[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].first;
        b[i]=a[i].first;
        a[i].second=i;
        if(a[i].first>0)
        ff=1;
        if(a[i].first<0)
        f=1;
    }
    sort(a+1,a+n+1);
    vector<ll> v;
    if(f&&ff)
    {
        lli s=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i].first>=0&&i<n)
            {
                v.push_back({a[1].first,a[i].first});
                a[1].first-=a[i].first;
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(a[i].first<0&&i<n)
            {
                v.push_back({a[n].first,a[i].first});
                a[n].first-=a[i].first;
            }
        }
        s+=a[n].first;
        cout<<s<<endl;
        for(auto &i: v)
        cout<<i.first<<" "<<i.second<<endl;
    }
    else if(f)
    {
        lli s=0;
        for(int i=1;i<n;i++)
        {
            if(a[i].first<=0)
            {
                v.push_back({a[n].first,a[i].first});
                a[n].first-=a[i].first;
            }
        }
        s=a[n].first;
        cout<<s<<endl;
        for(auto &i: v)
        cout<<i.first<<" "<<i.second<<endl;
    }
    else
    {
        lli s=0;
        for(int i=2;i<n;i++)
        {
            if(a[i].first>=0)
            {
                v.push_back({a[1].first,a[i].first});
                a[1].first-=a[i].first;
            }
        }
        v.push_back({a[n].first,a[1].first});
        a[n].first-=a[1].first;
        s=a[n].first;
        cout<<s<<endl;
        for(auto &i: v)
        cout<<i.first<<" "<<i.second<<endl;
    }
}

Measured memory_bytes: 6000