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 (Clang 3.8.0) (judge verdict: Runtime Error)

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i32_asc(const void* a, const void* b) {
    return *((int32_t*)a) < *((int32_t*)b) ? -1 : 1;
}

int compare_i32_desc(const void* a, const void* b) {
    return *((int32_t*)a) > *((int32_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static int32_t A[100000];
static int32_t x[100000], y[100000];

int main(void) {
    size_t N;

    scanf("%zu", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%"PRId32, &(A[i]));
        if (i < N - 1) {
            scanf("\n");
        }
    }

    qsort(A, N, sizeof(int32_t), compare_i32_desc);

    size_t numPlus = 0;
    while (true) {
        if (A[numPlus] < 0) {
            break;
        }

        numPlus++;
    }

    int32_t M;

    if (0 < numPlus) {
        qsort(A, numPlus, sizeof(int32_t), compare_i32_asc);

        if (numPlus % 2 == 0) {
            M = A[0];
        }
        else {
            M = A[numPlus - 1];
        }

        for (size_t i = 0; i < numPlus - 1; i++) {
            if ((numPlus - i) % 2 == 0) {
                x[i] = A[numPlus - (i + 1) / 2 - 1];
                y[i] = M;
            }
            else {
                x[i] = A[(i + 1) / 2];
                y[i] = M;
            }

            M = x[i] - y[i];
        }
    }
    else {
        M = A[0];
        numPlus++;
    }

    for (size_t i = numPlus - 1; i < N - 1; i++) {
        x[i] = M;
        y[i] = A[i + 1];

        M = x[i] - y[i];
    }

    printf("%"PRId32"\n", M);
    for (size_t i = 0; i < N - 1; i++) {
        printf("%"PRId32" %"PRId32"\n", x[i], y[i]);
    }

    return 0;
}