import heapq

import os

import sys



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(2147483647)

INF = float("inf")



N = int(sys.stdin.readline())

A = list(map(int, sys.stdin.readline().split()))



# ans = []

# while len(A) > 2:

#     x = max(A)

#     y = min(A)

#     A = A[1:-1]

#     next_max = max(A)

#     next_min = min(A)

#     if abs(x - y - next_min) < abs(y - x - next_max):

#         x, y = y, x

#     bisect.insort_left(A, x - y)

#     ans.append((x, y))

# x, y = max(A), min(A)

# ans.append((x, y))

# print(x - y)

# for a in ans:

#     print(*a)





enable = [True] * N

mins = [(a, i) for i, a in enumerate(A)]

maxes = [(-a, i) for i, a in enumerate(A)]

heapq.heapify(mins)

heapq.heapify(maxes)



ans = []

for _ in range(N - 2):

    x, xi = heapq.heappop(maxes)

    x *= -1

    y, yi = heapq.heappop(mins)

    enable[xi] = False

    enable[yi] = False

    while not enable[maxes[0][1]]:

        heapq.heappop(maxes)

    while not enable[mins[0][1]]:

        heapq.heappop(mins)

    next_max = -maxes[0][0]

    next_min = mins[0][0]

    if abs(x - y - next_min) < abs(y - x - next_max):

        x, y = y, x

    enable.append(True)

    heapq.heappush(mins, (x - y, len(enable) - 1))

    heapq.heappush(maxes, (y - x, len(enable) - 1))

    ans.append((x, y))



x = -maxes[0][0]

y = mins[0][0]

ans.append((x, y))

print((x - y))

for a in ans:

    print((*a))

import bisect

import os

from collections import Counter, deque

from fractions import gcd

from functools import lru_cache

from functools import reduce

import functools

import heapq

import itertools

import math

import numpy as np

import re

import string

import sys



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(2147483647)

INF = float("inf")



N = int(sys.stdin.readline())

A = list(map(int, sys.stdin.readline().split()))



plus = []

minus = []



for a in A:

    if a >= 0:

        plus.append(a)

    else:

        minus.append(a)

if not plus:

    mm = max(minus)

    plus.append(mm)

    minus.remove(mm)

if not minus:

    mp = min(plus)

    minus.append(mp)

    plus.remove(mp)



hist = []

x = minus.pop()

while len(plus) > 1:

    y = plus.pop()

    hist.append((x, y))

    x = x - y

minus.append(x)



x = plus.pop()

while len(minus) > 1:

    y = minus.pop()

    hist.append((x, y))

    x = x - y

y = minus.pop()

hist.append((x, y))



print((x - y))

for h in hist:

    print((*h))

import heapq
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
# ans = []
# while len(A) > 2:
#     x = max(A)
#     y = min(A)
#     A = A[1:-1]
#     next_max = max(A)
#     next_min = min(A)
#     if abs(x - y - next_min) < abs(y - x - next_max):
#         x, y = y, x
#     bisect.insort_left(A, x - y)
#     ans.append((x, y))
# x, y = max(A), min(A)
# ans.append((x, y))
# print(x - y)
# for a in ans:
#     print(*a)
enable = [True] * N
mins = [(a, i) for i, a in enumerate(A)]
maxes = [(-a, i) for i, a in enumerate(A)]
heapq.heapify(mins)
heapq.heapify(maxes)
ans = []
for _ in range(N - 2):
    x, xi = heapq.heappop(maxes)
    x *= -1
    y, yi = heapq.heappop(mins)
    enable[xi] = False
    enable[yi] = False
    while not enable[maxes[0][1]]:
        heapq.heappop(maxes)
    while not enable[mins[0][1]]:
        heapq.heappop(mins)
    next_max = -maxes[0][0]
    next_min = mins[0][0]
    if abs(x - y - next_min) < abs(y - x - next_max):
        x, y = y, x
    enable.append(True)
    heapq.heappush(mins, (x - y, len(enable) - 1))
    heapq.heappush(maxes, (y - x, len(enable) - 1))
    ans.append((x, y))
x = -maxes[0][0]
y = mins[0][0]
ans.append((x, y))
print((x - y))
for a in ans:
    print((*a))

import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
plus = []
minus = []
for a in A:
    if a >= 0:
        plus.append(a)
    else:
        minus.append(a)
if not plus:
    mm = max(minus)
    plus.append(mm)
    minus.remove(mm)
if not minus:
    mp = min(plus)
    minus.append(mp)
    plus.remove(mp)
hist = []
x = minus.pop()
while len(plus) > 1:
    y = plus.pop()
    hist.append((x, y))
    x = x - y
minus.append(x)
x = plus.pop()
while len(minus) > 1:
    y = minus.pop()
    hist.append((x, y))
    x = x - y
y = minus.pop()
hist.append((x, y))
print((x - y))
for h in hist:
    print((*h))

+import bisect +import os +from collections import Counter, deque +from fractions import gcd +from functools import lru_cache +from functools import reduce +import functools -import os +import itertools +import math +import numpy as np +import re +import string -# ans = [] -# while len(A) > 2: -#     x = max(A) -#     y = min(A) -#     A = A[1:-1] -#     next_max = max(A) -#     next_min = min(A) -#     if abs(x - y - next_min) < abs(y - x - next_max): -#         x, y = y, x -#     bisect.insort_left(A, x - y) -#     ans.append((x, y)) -# x, y = max(A), min(A) -# ans.append((x, y)) -# print(x - y) -# for a in ans: -#     print(*a) -enable = [True] * N -mins = [(a, i) for i, a in enumerate(A)] -maxes = [(-a, i) for i, a in enumerate(A)] -heapq.heapify(mins) -heapq.heapify(maxes) -ans = [] -for _ in range(N - 2): -    x, xi = heapq.heappop(maxes) -    x *= -1 -    y, yi = heapq.heappop(mins) -    enable[xi] = False -    enable[yi] = False -    while not enable[maxes[0][1]]: -        heapq.heappop(maxes) -    while not enable[mins[0][1]]: -        heapq.heappop(mins) -    next_max = -maxes[0][0] -    next_min = mins[0][0] -    if abs(x - y - next_min) < abs(y - x - next_max): -        x, y = y, x -    enable.append(True) -    heapq.heappush(mins, (x - y, len(enable) - 1)) -    heapq.heappush(maxes, (y - x, len(enable) - 1)) -    ans.append((x, y)) -x = -maxes[0][0] -y = mins[0][0] -ans.append((x, y)) +plus = [] +minus = [] +for a in A: +    if a >= 0: +        plus.append(a) +    else: +        minus.append(a) +if not plus: +    mm = max(minus) +    plus.append(mm) +    minus.remove(mm) +if not minus: +    mp = min(plus) +    minus.append(mp) +    plus.remove(mp) +hist = [] +x = minus.pop() +while len(plus) > 1: +    y = plus.pop() +    hist.append((x, y)) +    x = x - y +minus.append(x) +x = plus.pop() +while len(minus) > 1: +    y = minus.pop() +    hist.append((x, y)) +    x = x - y +y = minus.pop() +hist.append((x, y)) -for a in ans: -    print((*a)) +for h in hist: +    print((*h))