Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


void solve(long long N, std::vector<long long> A){
    std::sort(A.begin(),A.end());
    int positive_start_idx = 0;
    for (int i=0;i<N;i++){
        if(A[i]>0) break;
        positive_start_idx++;
    }
    ll n_pos = N-positive_start_idx;
    ll n_neg = N -n_pos;
    if (n_pos==0){
        n_pos==1;
        n_neg==N-1;
    }
    if (n_neg==0){
        n_neg==1;
        n_pos==N-1;
    }
    vector<pair<ll,ll>> ret_print;
    ll x = A[0];
    for (int i = n_neg;i<N-1;i++){
        ret_print.push_back(make_pair(x,A[i]));
        x = x- A[i];
    }
    ret_print.push_back(make_pair(A[N-1],x));
    x = A[N-1] -x ;
    for (int i=1;i<n_neg;i++){
        ret_print.push_back(make_pair(x,A[i]));
        x = x - A[i];
    }
    printf("%lld\n",x);
    for (auto itr=ret_print.begin();itr!=ret_print.end():itr++ ){
        printf("%lld %lld\n",(*itr).first,(*itr).second);
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Compiler output:
a.cc: In function 'void solve(long long int, std::vector<long long int>)':
a.cc:36:37: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   36 |     for (auto itr=ret_print.begin();itr!=ret_print.end():itr++ ){
      |                                     ^~~
a.cc:36:57: error: expected ';' before ':' token
   36 |     for (auto itr=ret_print.begin();itr!=ret_print.end():itr++ ){
      |                                                         ^
      |                                                         ;
a.cc:36:40: warning: ignoring return value of 'bool __gnu_cxx::operator!=(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&) [with _Iterator = std::pair<long long int, long long int>*; _Container = std::vector<std::pair<long long int, long long int> >]', declared with attribute 'nodiscard' [-Wunused-result]
   36 |     for (auto itr=ret_print.begin();itr!=ret_print.end():itr++ ){
      |                                     ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:1232:5: note: declared here
 1232 |     operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
a.cc:40:1: error: expected primary-expression before '}' token
   40 | }
      | ^
a.cc:38:6: error: expected ';' before '}' token
   38 |     }
      |      ^
      |      ;
   39 | 
   40 | }
      | ~     
a.cc:40:1: error: expected primary-expression before '}' token
   40 | }
      | ^
a.cc:38:6: error: expected ')' before '}' token
   38 |     }
      |      ^
      |      )
   39 | 
   40 | }
      | ~     
a.cc:36:9: note: to match this '('
   36 |     for (auto itr=ret_print.begin();itr!=ret_print.end():itr++ ){
      |         ^
a.cc:40:1: error: expected primary-expression before '}' token
   40 | }
      | ^