Language: C++

#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
struct Node
{
	int data;
	Node *left;
	Node *right;
};
void inorder(Node *ptr){
	if(ptr == NULL)
		 return ;
	inorder(ptr->left);
	cout<<ptr->data<<" ";
	inorder(ptr->right);
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);	
    //cin>>tests;
  while(tests--)
    {
    	int n;
    	cin>>n;
        vector<int> neg,pos;
        for(int i = 0;i<n;i++){
        	ll x;
        	cin>>x;
        	if(x >= 0){
        		pos.pb(x);
        	}
        	else if(x<0)
        	{
        		neg.pb(x);
        	}
        }
        sort(all(neg));
        if(pos.size())
         sort(all(pos));
     //cout<<pos.size();
        if(pos.size() == 0){
        	ll sum = 0;
        	for(int i = 1;i<neg.size()-1;i++){
        		sum = sum+abs(neg[i]);
        	}
        	sum = sum + abs(neg[neg.size()-1] -neg[0]);
        	cout<<sum<<endl;
        	ll x = neg[0];
        	ll y = neg[neg.size()-1];
        	neg.erase(neg.begin()+0);
        	neg.pop_back();
        	cout<<y<<" "<<x<<endl;
        	neg.push_back(x-y);
        	//cout<<neg.size();
        	while(neg.size() > 1){
        		x = neg[neg.size()-1];
        		neg.pop_back();
        		y =  neg[neg.size()-1];
        		neg.pop_back();
        		cout<<x<<" "<<y<<endl;
        		neg.push_back(x-y);
 
        	}
 
           }
        else if(neg.size() && pos.size()){
        	ll sum = 0;
        	for(int i = 0;i<pos.size();i++){
        		sum = sum + pos[i];
        	}
        	for(int i = 0;i<neg.size();i++)
        		sum = sum + abs(neg[i]);
        	cout<<sum << endl;
        	while(neg.size() > 1){
        		ll x =  neg[neg.size()-1];
        		ll y = pos[pos.size()-1];
        		neg.pop_back();
        		pos.pop_back();
        		cout<<y<<" "<<x<<endl;
        		pos.pb(y-x);
 
        	}
        	ll x = neg[0];
        	pos.pb(x);
        	while(pos.size() > 2){
        		 x = pos[pos.size()-1];
        		 pos.pop_back();
        		 ll y = pos[pos.size()-1];
        		 pos.pop_back();
        		 cout<<x<<" "<<y<<endl;
        		 pos.push_back(x-y);
        	}
        	cout<<pos[0]<<" "<<pos[1]<<endl;
 
 
        }
        else{
        	map<int,int>m;
        	for(int i = 0;i<pos.size();i++){
        		m[pos[i]]++;
        	}
        	reverse(all(pos));
        	cout<<accumulate(pos.begin(),pos.end() ,(ll) 0)-2*pos[pos.size()-1]<<endl;
        	while(pos.size() > 2){
        		ll x = pos[pos.size()-1];
        		pos.pop_back();
        		ll y = pos[pos.size()-1];
        		pos.pop_back();
        		cout<<x<<" "<<y<<endl;
        		pos.push_back(x-y);
 
        	}
        	cout<<pos[0]<<" "<<pos[1];		
        }
 
    }
}
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
struct Node
{
	int data;
	Node *left;
	Node *right;
};
void inorder(Node *ptr){
	if(ptr == NULL)
		 return ;
	inorder(ptr->left);
	cout<<ptr->data<<" ";
	inorder(ptr->right);
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);	
    //cin>>tests;
  while(tests--)
    {
    	int n;
    	cin>>n;
        vector<ll> neg,pos;
        for(int i = 0;i<n;i++){
        	ll x;
        	cin>>x;
        	if(x >= 0){
        		pos.pb(x);
        	}
        	else if(x<0)
        	{
        		neg.pb(x);
        	}
        }
        sort(all(neg));
        if(pos.size())
         sort(all(pos));
     //cout<<pos.size();
        if(pos.size() == 0){
        	ll sum = 0;
        	for(int i = 1;i<neg.size()-1;i++){
        		sum = sum+abs(neg[i]);
        	}
        	sum = sum + abs(neg[neg.size()-1] -neg[0]);
        	cout<<sum<<endl;
        	ll x = neg[0];
        	ll y = neg[neg.size()-1];
        	neg.erase(neg.begin()+0);
        	neg.pop_back();
        	cout<<y<<" "<<x<<endl;
        	neg.push_back(x-y);
        	//cout<<neg.size();
        	while(neg.size() > 1){
        		x = neg[neg.size()-1];
        		neg.pop_back();
        		y =  neg[neg.size()-1];
        		neg.pop_back();
        		cout<<x<<" "<<y<<endl;
        		neg.push_back(x-y);

        	}

           }
        else if(neg.size() && pos.size()){
        	ll sum = 0;
        	for(int i = 0;i<pos.size();i++){
        		sum = sum + pos[i];
        	}
        	for(int i = 0;i<neg.size();i++)
        		sum = sum + abs(neg[i]);
        	cout<<sum << endl;
        	while(neg.size() > 1){
        		ll x =  neg[neg.size()-1];
        		ll y = pos[pos.size()-1];
        		neg.pop_back();
        		pos.pop_back();
        		cout<<y<<" "<<x<<endl;
        		pos.pb(y-x);

        	}
        	ll x = neg[0];
        	pos.pb(x);
        	while(pos.size() > 2){
        		 x = pos[pos.size()-1];
        		 pos.pop_back();
        		 ll y = pos[pos.size()-1];
        		 pos.pop_back();
        		 cout<<x<<" "<<y<<endl;
        		 pos.push_back(x-y);
        	}
        	cout<<pos[0]<<" "<<pos[1]<<endl;


        }
        else{
        	map<int,int>m;
        	for(int i = 0;i<pos.size();i++){
        		m[pos[i]]++;
        	}
        	reverse(all(pos));
        	cout<<accumulate(pos.begin(),pos.end() ,(ll) 0)-2*pos[pos.size()-1]<<endl;
        	while(pos.size() > 2){
        		ll x = pos[pos.size()-1];
        		pos.pop_back();
        		ll y = pos[pos.size()-1];
        		pos.pop_back();
        		cout<<x<<" "<<y<<endl;
        		pos.push_back(x-y);

        	}
        	cout<<pos[0]<<" "<<pos[1];		
        }

    }
}


Compiler output:
a.cc:146:8: error: redefinition of 'struct Node'
  146 | struct Node
      |        ^~~~
a.cc:14:8: note: previous definition of 'struct Node'
   14 | struct Node
      |        ^~~~
a.cc:152:6: error: redefinition of 'void inorder(Node*)'
  152 | void inorder(Node *ptr){
      |      ^~~~~~~
a.cc:20:6: note: 'void inorder(Node*)' previously defined here
   20 | void inorder(Node *ptr){
      |      ^~~~~~~
a.cc:159:5: error: redefinition of 'int main()'
  159 | int main()
      |     ^~~~
a.cc:27:5: note: 'int main()' previously defined here
   27 | int main()
      |     ^~~~