Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll,ll> MPll;
typedef set<ll> setl;

const ll INF = 1ll << 60;
const ld EPS = 1e-10;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mods = 1000000007;

//for文
#define FOR(i,a,b) for(ll i = (ll)a;i < (ll)b;i++)
#define FORE(i,a,b) for(ll i = (ll) a;i <= (ll) b;i++ )
#define REP(i,size)  for(ll i =(ll)0;i<size;i++)
#define REPE(i,size)  for(ll i =(ll)0;i<=size;i++)
#define REPR(i,size)  for(ll i =(ll)size;i>=0;i--)
#define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++)

//ソート
#define ALL(vec) (vec).begin(),(vec).end()
#define SORT(vec) sort(ALL(vec))
#define SORTA(arr) sort(arr,arr + (sizeof(arr) / sizeof(ll)))
#define INVSORT(vec) sort((vec).rbegin(),(vec).rend())
#define REV(vec) reverse(ALL(vec))
#define REVA(arr) reverse(arr,arr + (sizeof(arr) / sizeof(ll)))
#define INVSORTA(arr) sort(arr,arr + (sizeof(arr) / sizeof(ll))),REVA(arr)

//最大値最小値
#define MAX(vec) *max_element(ALL(vec))
#define UNIQ(vec) SORT(vec);vec.erase(unique(ALL(vec)),vec.end())
#define MIN(vec) *min_element(ALL(vec))

//出力
#define printl(a) cout << a << "\n"
#define print(a) cout << a
#define OUT(a) printf("%lld\n",a)
#define OUTA(array) REP(i,sizeof(array)/sizeof(ll)) printf("%lld\n",array[i])
#define OUTV(vec) REP(i,vec.size()) printf("%lld\n",vec[i])
#define SP printf(" ")

//入力
#define IN(x) scanf("%lld",&x)
#define INV(vec) REP(i,vec.size()) scanf("%lld",&vec[i])
#define INA(array) REP(i,sizeof(array)/sizeof(ll)) scanf("%lld",array + i)
#define INS(x) cin >> x
#define INCH(x) scanf(" %c",&x)

//型
#define P pair
#define vp vector<P>
#define F first
#define S second

//その他
#define PB push_back
#define MP make_pair
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define INFI(a) memset(a,INF,sizeof(a))
#define MEM(a,b) memset(a,(b),sizeof(a))

//関数
template<class T> inline void amax(T &a,const T &b) { if(a < b) a = b; }
template<class T> inline void amin(T &a, const T &b) { if(a > b) a = b; }
/*
struct structure{
    ll num1,num2,string s;
    bool operator<(const rest &another) const{
        return this->s < another.s;
    }
    structure(ll a,ll b,string s){
        this->num1 = a,this->num2=b,this->s=s;
    }
};a
*/
//特殊
//#define int ll
#define _CRT_SECURE_NO_WARNINGS



/*
template <typename T>
struct UnionFindTree{

    vector<T> par;

    UnionFindTree(T n) : par(n+1){
        for (int i = 1; i <= n; ++i) {
            par[i] = i;
        }
    }

    T root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }

    void unite(T x,T y){
        if(!same(x,y)) par[root(x)] = root(par[y]);
    }

    T same(T x,T y){
        return root(x) == root(y);
    }

};
*/

//#define DEBUG

#ifdef DEBUG
#define debugl(x) cerr << #x << ":" << x<<"\n"
    #define debug(x)  cerr << #x<<":"<<x<<endl;
    #define  debugV(V) REP(i,V.size()){cerr << i << ":" << V[i]<<endl;}
    #define  debugA(A) REP(i,sizeof(A)/sizeof(ll)){cerr << i << ":" << V[i]<<endl;}
#else
#define debug(x)
#define debugV(x)
#define debugA(x)
#define debugl(x)
#endif

#define ZERO(a) memset(a,0,sizeof(a))
#define ALL(vec) (vec).begin(),(vec).end()
#define SORT(vec) sort(ALL(vec))



ll binary(ll key,vec &a){
    ll ok = a.size();ll dame = -1;
    while(abs(ok - dame) > 1){
        ll mid = (ok + dame) /2;
        if(a[mid] <= key) ok = mid;
        else dame = mid;
    }

    return ok;
}


ll n;
ll m;
ll k;
ll l;
ll temp;
ll x,y;

signed main(){
    IN(n);
    vector<ll> a;
    ll pos = 0;
    ll neg = 0;
    ll ans = 0;
    FOR(i,0,n){
        IN(temp);
        a.PB(temp);
        ans += abs(temp);
        if(temp >= 0) pos++;
        else neg++;
    }

    SORT(a);

    if(pos == n) {
        x = a.front();
        OUT(ans - abs(x) * 2);
        a.pop_front();
        y = a.back();
        a.pop_back();
        a.push_front(x-y);
        printf("%lld %lld\n", x, y);
        while(a.size() != 2){
            x = a.front();
            a.pop_front();
            y = a.front();
            a.pop_front();
            a.push_front(x-y);
            printf("%lld %lld\n", x, y);
        }
        y = a.front();
        a.pop_front();
        x = a.front();
        a.pop_front();
        printf("%lld %lld\n", x, y);
    }else if(neg == n){
        x = a.front();
        OUT(ans - abs(x) * 2);
        a.pop_front();
        y = a.back();
        a.pop_back();
        a.push_back(x-y);
        while(!a.empty()){
            x = a.back();
            a.pop_back();
            y = a.front();
            a.pop_front();
            a.push_back(x-y);
            printf("%lld %lld\n", x, y);
        }
    }else if(neg > pos){
        OUT(ans);
        while(pos != 1){
            x = a.front();
            a.pop_front();
            y = a.back();
            a.pop_back();
            a.push_front(x-y);
            pos--;
            printf("%lld %lld\n", x, y);
        }
        while(a.size() != 1){
            x = a.back();
            a.pop_back();
            y = a.front();
            a.pop_front();
            a.push_back(x-y);
            printf("%lld %lld\n", x, y);
        }
    }else{
        while(neg != 1){
            x = a.front();
            a.pop_front();
            y = a.back();
            a.pop_back();
            a.push_back(y-x);
            neg--;
            printf("%lld %lld\n", y, x);
        }
        while(a.size() != 2){
            x = a.front();
            a.pop_front();
            y = a.front();
            a.pop_front();
            a.push_front(x-y);
            printf("%lld %lld\n", x, y);
        }
        y = a.front();
        a.pop_front();
        x = a.front();
        a.pop_front();
        printf("%lld %lld\n", x, y);
    }

}


Compiler output:
a.cc: In function 'int main()':
a.cc:197:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  197 |         a.pop_front();
      |           ^~~~~~~~~
a.cc:200:11: error: 'class std::vector<long long int>' has no member named 'push_front'
  200 |         a.push_front(x-y);
      |           ^~~~~~~~~~
a.cc:204:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  204 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:206:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  206 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:207:15: error: 'class std::vector<long long int>' has no member named 'push_front'
  207 |             a.push_front(x-y);
      |               ^~~~~~~~~~
a.cc:211:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  211 |         a.pop_front();
      |           ^~~~~~~~~
a.cc:213:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  213 |         a.pop_front();
      |           ^~~~~~~~~
a.cc:218:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  218 |         a.pop_front();
      |           ^~~~~~~~~
a.cc:226:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  226 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:234:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  234 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:237:15: error: 'class std::vector<long long int>' has no member named 'push_front'
  237 |             a.push_front(x-y);
      |               ^~~~~~~~~~
a.cc:245:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  245 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:252:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  252 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:261:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  261 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:263:15: error: 'class std::vector<long long int>' has no member named 'pop_front'
  263 |             a.pop_front();
      |               ^~~~~~~~~
a.cc:264:15: error: 'class std::vector<long long int>' has no member named 'push_front'
  264 |             a.push_front(x-y);
      |               ^~~~~~~~~~
a.cc:268:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  268 |         a.pop_front();
      |           ^~~~~~~~~
a.cc:270:11: error: 'class std::vector<long long int>' has no member named 'pop_front'
  270 |         a.pop_front();
      |           ^~~~~~~~~