atcoder#DIVERTA20192C. Successive Subtraction

Successive Subtraction

Score : 500500 points

Problem Statement

There are NN integers, A1,A2,...,ANA_1, A_2, ..., A_N, written on a blackboard.

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

  • Choose two integers xx and yy on the blackboard and erase these two integers. Then, write a new integer xyx-y.

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

Constraints

  • 2N1052 \leq N \leq 10^5
  • 104Ai104-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:

NN

A1A_1 A2A_2 ...... ANA_N

Output

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

Here xix_i and yiy_i represent the integers xx and yy chosen in the ii-th operation, respectively.

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

MM

x1x_1 y1y_1

::

xN1x_{N-1} yN1y_{N-1}

3
1 -1 2
4
-1 1
2 -2

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

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

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

3
1 1 1
1
1 1
1 0