Problem:
Score : 500 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on a blackboard.

We will repeat the following operation N-1 times so that we have only one integer on the blackboard.

Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.

Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.

Constraints

2 \leq N \leq 10^5

-10^4 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below.

Here x_i and y_i represent the integers x and y chosen in the i-th operation, respectively.

If there are multiple sequences of operations that maximize the final integer, any of them will be accepted.

M
x_1 y_1
:
x_{N-1} y_{N-1}

Sample Input 1

3
1 -1 2

Sample Output 1

4
-1 1
2 -2

If we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2).

Then, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4).

In this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4.

Sample Input 2

3
1 1 1

Sample Output 2

1
1 1
1 0

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			long[] a = cin.ArrayLong(n);
			var ms = new PriorityQueue<long>(n);
			var ps = new PriorityQueue<long>(n, true);
			var zs = new PriorityQueue<long>(n);
			for (int i = 0; i < n; i++) {
				if (a[i] == 0) {
					zs.Enqueue(a[i]);
				} else if (a[i] > 0) {
					ps.Enqueue(a[i]);
				} else {
					ms.Enqueue(a[i]);
				}
			}

			long ppp = 0;
			long mmm = 0;
			StringBuilder sb = new StringBuilder();

			if (ms.Count == 0 && ps.Count == 0) {
				long z1 = zs.Dequeue();
				long z2 = zs.Dequeue();
				sb.AppendLine($"{z1} {z2}");
			} else if (ms.Count == 0) {
				if (zs.Count > 0) {
					long p = ps.Dequeue();
					long z = zs.Dequeue();
					mmm = 0 - p;
					sb.AppendLine($"{z} {p}");
				} else {
					long p1 = ps.Dequeue();
					long p2 = ps.Dequeue();
					mmm = p1 - p2;
					sb.AppendLine($"{p1} {p2}");
				}
			} else if (ps.Count == 0) {
				if (zs.Count > 0) {
					long m = ms.Dequeue();
					long z = zs.Dequeue();
					ppp = z - m;
					sb.AppendLine($"{z} {m}");
				} else {
					long m1 = ms.Dequeue();
					long m2 = ms.Dequeue();
					ppp = m1 - m2;
					sb.AppendLine($"{m1} {m2}");
				}
			} else {
				if (ms.Count > ps.Count) {
					long p = ps.Dequeue();
					long m = ms.Dequeue();
					ppp = p - m;
					sb.AppendLine($"{p} {m}");
				} else {
					long p = ps.Dequeue();
					long m = ms.Dequeue();
					mmm = m - p;
					sb.AppendLine($"{m} {p}");
				}
			}

			while (ms.Count > 0 || ps.Count > 0 || zs.Count > 0) {
				if (ms.Count == 0 && ps.Count == 0) {
					long z = zs.Dequeue();
					sb.AppendLine($"{ppp} {z}");
				} else if (ms.Count >= ps.Count) {
					long m = ms.Dequeue();
					sb.AppendLine($"{ppp} {m}");
					ppp = ppp - m;
				} else {
					long p = ps.Dequeue();
					if (ps.Count == 0) {
						sb.AppendLine($"{p} {mmm}");
						ppp = p - mmm;
					} else {
						sb.AppendLine($"{mmm} {p}");
						mmm = mmm - p;
					}
				}
			}

			Console.WriteLine(ppp);
			Console.WriteLine(sb.ToString());
		}
	}

	public class PriorityQueue<T>
	{
		private readonly List<T> heap_;
		private readonly Comparison<T> comparison_;
		private readonly bool reverses_;

		public T Top => heap_[0];
		public int Count => heap_.Count;

		public PriorityQueue(bool reverses = false)
			: this(Comparer<T>.Default, reverses) { }

		public PriorityQueue(int capacity, bool reverses = false)
			: this(capacity, Comparer<T>.Default.Compare, reverses) { }

		public PriorityQueue(IComparer<T> comparer, bool reverses = false)
			: this(16, comparer.Compare, reverses) { }

		public PriorityQueue(Comparison<T> comparison, bool reverses = false)
			: this(16, comparison, reverses) { }

		public PriorityQueue(
			int capacity,
			Comparison<T> comparison,
			bool reverses = false)
		{
			heap_ = new List<T>(capacity);
			comparison_ = comparison;
			reverses_ = reverses;
		}

		public void Enqueue(T item)
		{
			int c = heap_.Count;
			heap_.Add(item);
			while (c > 0) {
				int p = (c - 1) >> 1;
				if (Compare(p, c) > 0) {
					Swap(p, c);
				} else {
					break;
				}

				c = p;
			}
		}

		public T Dequeue()
		{
			T ret = heap_[0];
			int n = heap_.Count - 1;

			heap_[0] = heap_[n];
			heap_.RemoveAt(n);
			for (int p = 0, c; (c = (p << 1) + 1) < n; p = c) {
				if (c != n - 1 && Compare(c + 1, c) < 0) {
					++c;
				}

				if (Compare(p, c) > 0) {
					Swap(p, c);
				} else {
					break;
				}
			}

			return ret;
		}

		private int Compare(int x, int y)
			=> comparison_(heap_[x], heap_[y]) * (reverses_ ? -1 : 1);

		private void Swap(int x, int y)
		{
			var t = heap_[x];
			heap_[x] = heap_[y];
			heap_[y] = t;
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}