Language: C++

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<long long> da(n);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
	}
	sort(da.begin(), da.end());
	if (da[0] > 0) {
		long long ans = -da[0];
		for (int i = 1;i < n;i++) {
			ans += da[i];
		}
		cout << ans << endl;
		for (int i = 1;i < n - 1;i++) {
			cout << da[0] << ' ' << da[i] << endl;
			da[0] -= da[i];
		}
		cout << da[n - 1] << ' ' << da[0] << endl;
	}
	else if (da[n - 1] < 0) {
		long long ans = da[n - 1];
		for (int i = 0;i < n - 1;i++) {
			ans -= da[i];
		}
		cout << ans << endl;
		for (int i = 0;i < n - 1;i++) {
			cout << da[n - 1] << ' ' << da[i] << endl;
			da[n - 1] -= da[i];
		}
	}
	else if (da[n - 2] < 0) {
		long long ans = 0;
		for (int i = 0;i < n;i++) {
			ans += abs(da[i]);
		}
		cout << ans << endl;
		for (int i = 0;i < n-1;i++) {
			cout << da[n - 1] << ' ' << da[i] << endl;
			da[n - 1] -= da[i];
		}
	}
	else {
		long long ans = 0;
		for (int i = 0;i < n;i++) {
			ans += abs(da[i]);
		}
		cout << ans << endl;
		long long num = 0;
		while (da[num] < 0) {
			num++;
		}
		long long jio = num;
		num -= 1;
		while (num > 0) {
			cout << da[jio] << ' ' << da[num] << endl;
			da[jio] -= da[num];
			num--;
		}
		while (jio < n - 1) {
			cout << da[0] << ' ' << da[jio] << endl;
			da[0] -= da[jio];
			jio++;
		}
		cout << da[n - 1] << ' ' << da[0] << endl;
		return 0;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:9: error: 'cin' was not declared in this scope
    4 |         cin >> n;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:5:9: error: 'vector' was not declared in this scope
    5 |         vector<long long> da(n);
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:5:16: error: expected primary-expression before 'long'
    5 |         vector<long long> da(n);
      |                ^~~~
a.cc:7:24: error: 'da' was not declared in this scope
    7 |                 cin >> da[i];
      |                        ^~
a.cc:9:14: error: 'da' was not declared in this scope
    9 |         sort(da.begin(), da.end());
      |              ^~
a.cc:9:9: error: 'sort' was not declared in this scope; did you mean 'short'?
    9 |         sort(da.begin(), da.end());
      |         ^~~~
      |         short
a.cc:15:17: error: 'cout' was not declared in this scope
   15 |                 cout << ans << endl;
      |                 ^~~~
a.cc:15:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:15:32: error: 'endl' was not declared in this scope
   15 |                 cout << ans << endl;
      |                                ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
a.cc:27:17: error: 'cout' was not declared in this scope
   27 |                 cout << ans << endl;
      |                 ^~~~
a.cc:27:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:27:32: error: 'endl' was not declared in this scope
   27 |                 cout << ans << endl;
      |                                ^~~~
a.cc:27:32: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:36:32: error: 'abs' was not declared in this scope; did you mean 'ans'?
   36 |                         ans += abs(da[i]);
      |                                ^~~
      |                                ans
a.cc:38:17: error: 'cout' was not declared in this scope
   38 |                 cout << ans << endl;
      |                 ^~~~
a.cc:38:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:38:32: error: 'endl' was not declared in this scope
   38 |                 cout << ans << endl;
      |                                ^~~~
a.cc:38:32: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:47:32: error: 'abs' was not declared in this scope; did you mean 'ans'?
   47 |                         ans += abs(da[i]);
      |                                ^~~
      |                                ans
a.cc:49:17: error: 'cout' was not declared in this scope
   49 |                 cout << ans << endl;
      |                 ^~~~
a.cc:49:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:49:32: error: 'endl' was not declared in this scope
   49 |                 cout << ans << endl;
      |                                ^~~~
a.cc:49:32: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'