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 (Python):
N=int(input())
A=list(map(int,input().split()))
plus=[a for a in A if a>0]
mainus=[a for a in A if a<=0]
plus.sort()
mainus.sort(reverse=True)
if len(mainus)==0:
    print(sum(plus)-2*plus[0])
    now=plus[0]
    for i in range(1,len(plus)-1):
        print(str(now)+" "+str(plus[i]))
        now-=plus[i]
    print(str(plus[-1])+" "+str(now))
elif len(plus)==0:
    print(-1*sum(mainus)+2*mainus[0])
    now=mainus[0]
    for i in range(1,len(mainus)):
        print(str(now)+" "+str(mainus[i]))
        now-=mainus[i]
else:
    print(sum(plus)-sum(mainus))
    now=mainus[0]
    for i in range(len(plus)-1):
        print(str(now)+" "+str(plus[i]))
        now-=plus[i]
    if len(plus)>0:
        print(str(plus[-1])+" "+str(now))
        now=plus[-1]-now
    for i in range(1,len(mainus)):
        print(str(now)+" "+str(mainus[i]))
        now-=mainus[i]

Solution (Python):
import collections

def solve():
  n = int(input())
  a = collections.deque(sorted(list(int(i) for i in input().split())))
  big = a.pop()
  mini = a.popleft()
  queue = collections.deque([])
  
  while (a):
    if a[0] <= 0:
      tmp = a.popleft()
      queue.append((big,tmp))
      big -= tmp
    else:
      tmp = a.pop()
      queue.append((mini,tmp))
      mini -= tmp
  print(big-mini)
  queue.append((big,mini))
  for i in range(len(queue)):
    print(*queue[i])
  
solve()

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
B = [abs(a) for a in A]

for i in range(N):
    if A[i] > 0:
        po = i
        break
else:
    po = -1
for i in range(N):
    if A[i] < 0:
        ne = i
        break
else:
    ne = -1
mi = min(B)
for i in range(N):
    if B[i] == mi:
        mii = i
        break
else:
    mii = -1

if po >= 0 and ne >= 0:
    print(sum(B))
    t1, t2 = A[po], A[ne]
    if po > ne:
        po, ne = ne, po
    
    if po == ne:
        del A[ne]
        A = [0] + A
    else:
        del A[ne]
        del A[po]
        A = [t1, t2] + A
else:
    print(sum(B) - 2 * mi)
    t = A[mii]
    del A[mii]
    A = [t] + A

prev = A[0]
for i in range(1, N):
    a, b = max(prev, A[i]), min(prev, A[i])
    if i == N-1 or A[i+1] < 0:
        print(a, b)
        prev = a - b
    else:
        print(b, a)
        prev = b - a

Solution (Python):
import bisect
m = int(input())
a = list(map(int,input().split()))
a.sort()

if a[-1] <= 0: 
    a1 = -(sum(a)) + 2 * a[-1]
    print(a1)
    p = a[-1]
    q = a[-2]
    for i in range(-1,-(len(a)),-1):
        print(str(p)+ " " + str(q))
        if i == -(len(a) -1):
            break
        p = p - q
        q = a[i-2]
elif a[0] >= 0:
    print(sum(a[1:]) - a[0])
    p = a[0]
    q = a[1]
    for i in range(len(a)-1):
        print(str(p)+" "+str(q))
        p = p - q
        if i + 2 > len(a) - 2:
            break 
        q = a[i+2]
    print(str(a[-1])+" "+str(p))
else:
    c = bisect.bisect_left(a,0)
    c1 = 0
    for x in a:
        c1 += abs(x)
    print(c1)
    p = a[c-1]
    q = a[c]
    for i in range(c,m-1):
        print(str(p)+" "+str(q))
        p = p - q
        q = a[i+1]
    p1 = a[-1]
    q1 = a[0]
    for i in range(c-1):
        print(str(p1)+" "+str(q1))
        p1 = p1 - q1
        q1 = a[i+1]
    print(str(p1)+ " "+str(p))

Solution (Python):
import bisect

N = int(input())
a_list = list(map(int, input().split()))

a_list.sort()

M = 0
commands = []
item_max = a_list.pop()
item_min = a_list.pop(0)

cur_x = item_min
while a_list and a_list[-1] > 0:
	cur_y = a_list.pop()
	commands.append((cur_x, cur_y))
	cur_x -= cur_y

commands.append((item_max, cur_x))
cur_x = item_max - cur_x
while a_list:
	cur_y = a_list.pop()
	commands.append((cur_x, cur_y))
	cur_x -= cur_y

print(cur_x)
for x, y in commands:
	print(x, y)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
Ans_list = [[] for i in range(N-1)]
A.sort(reverse = True)
count = 0

for i in A[1:-1]:
    if i >= 0:
        Ans_list[count] = [A[-1],i]
        A[-1] -= i
    else:
        Ans_list[count] = [A[0],i]
        A[0] -= i
    count += 1

Ans_list[-1] = [A[0],A[-1]]
print(A[0]-A[-1])
for i,j in Ans_list:
    print(i,j)

Solution (Python):
def all_positive(values):
  m = []
  x = values[0]

  for v in values[1:-1]:
    m.append((x, v))
    x = x - v

  m.append((values[-1], x))
  x = values[-1] - x

  return x, m


def all_negative(values):
  m = []
  x = values[-1]

  for v in values[:-1]:
    m.append((x, v))
    x = x - v

  return x, m


def run(values):
  m = []
  x1 = values[0]
  x2 = values[-1]

  for v in values[-2::-1]:
    if v < 0:
      break

    m.append((x1, v))
    x1 = x1 - v

  for v in values[1:]:
    if v >= 0:
      break

    m.append((x2, v))
    x2 = x2 - v

  m.append((x2, x1))

  return x2 - x1, m


def main():
  input()
  values = list(map(int, input().split()))
  values.sort()

  if values[1] >= 0:
    x, m = all_positive(values)
  elif values[-2] <= 0:
    x, m = all_negative(values)
  else:
    x, m = run(values)

  print(x)
  for v in m:
    print('{} {}'.format(*v))


if __name__ == '__main__':
  main()

Solution (Python):
import sys
import bisect

input = sys.stdin.readline
N = int(input().strip())
A = sorted(map(int, input().strip().split()))

if A[0] < 0:
    zero_i = bisect.bisect_left(A, 0)
    if zero_i == N:
        print(A[N-1] - sum(A[0:N-1]))
        i = 0
        now = A[N-1]
        while i < N-1:
            print(now, A[i])
            now -= A[i]
            i += 1
    else:
        print(sum(A[zero_i:N])-sum(A[0:zero_i]))
        i = zero_i
        now = A[0]
        while i < N-1:
            print(now, A[i])
            now -= A[i]
            i += 1
        print(A[N-1], now)
        now = A[N-1] - now
        i = 1
        while i < zero_i:
            print(now, A[i])
            now -= A[i]
            i += 1
else:
    print(sum(A[1:N])-A[0])
    i = 1
    now = A[0]
    while i < N-1:
        print(now, A[i])
        now -= A[i]
        i += 1
    print(A[N-1], now)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)

Ans = []
for a in A[1:-1]:
    if a >= 0:
        Ans.append([A[-1],a])
        A[-1] -= a
    else:
        Ans.append([A[0],a])
        A[0] -= a
ans = [A[0],A[-1]]
Ans.append(ans)
print(ans[0] - ans[1])
for answ in Ans:
    print(*answ, sep = " ")

Solution (Python):
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
k=bisect.bisect_left(A,0)
a=-sum(A[:k])+sum(A[k:])
if N==2:
  a-=2*A[0]
elif k==0:
  a-=2*A[0]
elif k==N:
  a+=2*A[N-1]
print(a)
if N==2:
  print(A[1],A[0])
elif k>=N-1:
  x=A[N-1]
  for i in range(N-1):
    print(x,A[i])
    x-=A[i]
else:
  
    x=A[0]
    
    for i in range(max(k,1),N-1):
      print(x,A[i])
      x-=A[i]
    print(A[-1],x)
    x=A[-1]-x
    for i in range(1,k):
      print(x,A[i])
      x-=A[i]

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,k = LI()
    print(n%k)
    return


def B():

    n = I()
    po = LIR(n)
    return


def C():
    n = I()
    a = LI()
    a.sort()
    if a[0] >= 0:
        print(sum(a)-2*a[0])
        for i in range(1,n-1):
            print(a[0],a[i])
            a[0] -= a[i]
        print(a[n-1],a[0])
    else:
        if a[-1] < 0:
            print(2*a[-1]-sum(a))
            for i in range(n-1):
                print(a[-1],a[i])
                a[-1] -= a[i]
        else:
            m = bisect.bisect_left(a,0)
            p = n-m
            ans = -sum(a[:m])+sum(a[m:])
            print(ans)
            if p > m:
                l = a[-1]
                a = a[:-1]
                a = a[::-1]
                p -= 1
                p,m = m,p
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
                print(l,k)
            else:
                k = a[m]-a[m-1]
                print(a[m],a[m-1])
                for i in range(p-1):
                    print(a[m-i-2],k)
                    k = a[m-i-2]-k
                    print(a[m+i+1],k)
                    k = a[m+i+1]-k
                for i in range(m-p):
                    print(k,a[i])
                    k -= a[i]
    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return


def G():
    n = I()

    return


def H():
    n = I()

    return


def I_():
    n = I()

    return


def J():
    n = I()

    return


if __name__ == "__main__":
    C()

Solution (Python):
n = int(input())
As = list(map(int, input().split()))

ans_list = list()

v_min = min(As)
v_max = max(As)
As.remove(v_max)
As.remove(v_min)
for a in As:
    if a >= 0:
        ans_list.append((v_min, a))
        v_min = v_min - a
    else:
        ans_list.append((v_max, a))
        v_max = v_max - a

ans_list.append((v_max, v_min))
ans = v_max - v_min

print(ans)
for a in ans_list:
    print(a[0], a[1])

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    A.sort()

    if A[0] >= 0:
        ret = sum(A) - 2 * A[0]
        print(ret)
        tmp = A[0]
        for i in range(N - 2):
            print(tmp, A[i + 1])
            tmp -= A[i + 1]
        print(A[-1], tmp)

    elif A[-1] <= 0:
        ret = -sum(A[:-1]) + A[-1]
        print(ret)
        tmp = A[-1]
        for i in range(N - 1):
            idx = -1 - i - 1
            print(tmp, A[idx])
            tmp -= A[idx]

    else:
        ret = 0
        cnt = 0
        for a in A:
            if a < 0:
                ret += -a
                cnt += 1
            else:
                ret += a
        print(ret)
        idx = cnt - 1
        tmp = A[idx]
        for i in range(idx, N - 2):
            print(tmp, A[i + 1])
            tmp -= A[i + 1]
        tmp2 = A[-1]
        for i in range(0, cnt - 1):
            print(tmp2, A[i])
            tmp2 -= A[i]
        print(tmp2, tmp)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()

Anega = [a for a in A if a<=0]
Aposi = [a for a in A if a>0]

if Anega and Aposi:
  print(sum(Aposi)-sum(Anega))
  temp = Anega[-1]
  for a in Aposi[:-1]:
    print(*(temp,a))
    temp = temp-a
  print(*(Aposi[-1],temp))
  temp = Aposi[-1]-temp
  for a in Anega[:-1]:
    print(*(temp,a))
    temp = temp-a

elif Aposi:
  print(sum(A[1:]) - A[0])
  a = A[0]
  for i in range(1,N-1):
    print(*(a, A[i]))
    a = a-A[i]
  print(*(A[-1],a))

else:
  print(A[-1] - sum(A[:-1]))
  temp = A[-1]
  for a in A[:-1]:
    print(*(temp,a))
    temp = temp-a

Solution (Python):
m = int(input())
a = list(map(int, input().split()))
s = sorted([c for c in a if c <= 0], key=lambda c: -c)
p = sorted([c for c in a if c > 0])
c = p.pop(0) if len(s) == 0 else s.pop(0)
ans = []
if len(p) > 0:
    for v in p[1:]:
        ans.append((c, v))
        c = c - v
    ans.append((p[0], c))
    c = p[0] - c
for v in s:
    ans.append((c, v))
    c = c - v
print(c)
for a, b in ans:
    print(a, b)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

a.sort()

results = []
x_min = a[0]
x_max = a[-1]
if x_min < 0 and x_max >= 0:
    
    for i in range(1, n-1):
        if a[i] < 0:
            results.append((x_max, a[i]))
            x_max -= a[i]
        else:
            results.append((x_min, a[i]))
            x_min -= a[i]
elif a[0] >= 0:
    
    for i in range(1, n-1):
        results.append((x_min, a[i]))
        x_min -= a[i]
else:
    
    for i in range(1, n-1):
        results.append((x_max, a[i]))
        x_max -= a[i]

results.append((x_max, x_min))
print(x_max - x_min)
for x in results:
    print(str(x[0]) + " " + str(x[1]))

Solution (Python):
N = int(input())
A_array = list(map(int, input().split()))

A_array.sort()

ans_array = []
if A_array[0] >= 0:
    m = A_array[0]
    for i in range(1, N - 1):
        ans_array.append((m, A_array[i]))
        m = m - A_array[i]
    ans_array.append((A_array[-1], m))
    m = A_array[-1] - m
    print(m)
    for ans in ans_array:
        print(ans[0], ans[1])
    exit()

elif A_array[-1] <= 0:
    m = A_array[-1]
    for i in range(N - 2, -1, -1):
        ans_array.append((m, A_array[i]))
        m = m - A_array[i]
    print(m)
    for ans in ans_array:
        print(ans[0], ans[1])
    exit()

else:
    change_index = 0
    m = A_array[-1]
    for i in range(N - 1):
        if A_array[i + 1] < 0:
            ans_array.append((m, A_array[i]))
            m -= A_array[i]
        else:
            change_index = i
            break
    n = A_array[change_index]

    for i in range(change_index + 1, N - 1):
        ans_array.append((n, A_array[i]))
        n -= A_array[i]

    ans_array.append((m, n))
    m = m - n
    print(m)
    for ans in ans_array:
        print(ans[0], ans[1])
    exit()

Solution (Python):
def inverse(a):
    return pow(a, mod - 2, mod)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    if a[0] > 0:
        print(sum(a) - 2 * a[0])
        tmp = a[0]
        for i in range(1, n-1):
            print(tmp, a[i])
            tmp -= a[i]
        print(a[-1], tmp)
        return
    if a[-1] < 0:
        print(-sum(a) + 2 * a[-1])
        tmp = a[-1]
        for i in range(n-1):
            print(tmp, a[i])
            tmp -= a[i]
        return
    mid = lsearch(0, a) + 1
    print(sum(abs(i) for i in a))
    for i in range(mid+1, n):
        print(a[0], a[i])
        a[0] -= a[i]

    for i in range(mid):
        print(a[mid], a[i])
        a[mid] -= a[i]


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def lsearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] < x:
            lft = mid
        else:
            rgt = mid
    return lft


main()

Solution (Python):
n = int(input())
li = list(map(int,input().split()))

li.sort()

if li[0] >= 0:
    print(sum(li)-2*li[0])
    for i in range(n-2):
        print(li[0],li[i+1])
        li[0] -= li[i+1]
    print(li[n-1],li[0])
elif li[n-1] <= 0:
    print(abs(sum(li))+2*li[n-1])
    for i in range(n-1):
        print(li[n-1],li[i])
        li[n-1] -= li[i]
else:
    for i in range(n):
        if li[i] > 0:
            a = i-1
            break
    print(abs(sum(li[:a+1])) + sum(li[a+1:]))
    for i in range(n-a-2):
        print(li[0],li[a+1+i])
        li[0] -= li[a+1+i]
    for i in range(a+1):
        print(li[n-1],li[i])
        li[n-1] -= li[i]

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = [abs(i) for i in a]
a.sort()
if a[0] >= 0:
    print(sum(a[1:])-a[0])
    if n == 2:
        print(a[1],a[0])
    else:
        now = a[0]
        for i in range(n-2):
            print(now,a[i+1])
            now -= a[i+1]
        print(a[-1],now)
            
elif a[-1] <= 0:
    print(a[-1]-sum(a[:-1]))
    now = a[-1]
    for i in range(n-1):
        print(now, a[i])
        now -= a[i]
else:
    print(sum(b))
    zero = bisect.bisect_left(a,0)
    now1 = a[-1]
    now2 = a[0]
    for i in range(zero-1):
        print(now1,a[i+1])
        now1 -= a[i+1]
    for j in range(n-zero-1):
        print(now2,a[-(j+2)])
        now2 -= a[-(j+2)]
    print(now1,now2)

Solution (Python):
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = li()
    a_list.sort()

    mode = 1
    if a_list[0] <= 0 <= a_list[n - 1]:
        max_sum = sum(list(map(abs, a_list)))
        print(max_sum)
        min_index = 0
        max_index = n - 1
    elif a_list[0] < 0:
        max_value = a_list[n - 1]
        max2_index = n - 2
        max2_value = a_list[max2_index]

        while max2_index - 1 >= 0 and max_value == max2_value:
            max2_index = max2_index - 1
            max2_value = a_list[max2_index]

        max_sum = sum(list(map(abs, a_list))) - abs(max_value) * 2
        print(max_sum)
        min_index = 0
        max_index = n - 1

        print(a_list[max_index], a_list[max2_index])
        a_list[max_index] = a_list[max_index] - a_list[max2_index]
        a_list.pop(max2_index)
        max_index = max_index - 1
    else:
        min_value = a_list[0]
        min2_index = 1
        min2_value = a_list[min2_index]

        while min2_index + 1 < n and min_value == min2_value:
            min2_index = min2_index + 1
            min2_value = a_list[min2_index]

        max_sum = sum(list(map(abs, a_list))) - abs(min_value) * 2
        print(max_sum)
        min_index = 0
        max_index = n - 1

        print(a_list[min_index], a_list[min2_index])
        a_list[min_index] = a_list[min_index] - a_list[min2_index]
        a_list.pop(min2_index)
        max_index = max_index - 1

    while True:
        if min_index + 1 == max_index:
            print(a_list[max_index], a_list[min_index])
            break
        if a_list[min_index + 1] <= 0:
            print(a_list[max_index], a_list[min_index])
            a_list[max_index] = a_list[max_index] - a_list[min_index]
            min_index = min_index + 1
        else:
            print(a_list[min_index], a_list[max_index])
            a_list[min_index] = a_list[min_index] - a_list[max_index]
            max_index = max_index - 1

Solution (Python):
n=int(input())
a=sorted(map(int, input().split()))
a1=[i for i in a if i>=0]
a2=[i for i in a if i<0]
if a1 and a2:
    print(sum(a1)-sum(a2))
    mx,mn=a1[-1], a2[0]
    for i in a1[:-1]:
        print(mn,i)
        mn-=i
    for i in a2[1:]:
        print(mx,i)
        mx-=i
    print(mx,mn)
elif not a2:
    print(sum(a1[1:])-a1[0])
    mx,mn=a1[-1], a1[0]
    for i in a1[1:-1]:
        print(mn,i)
        mn-=i
    print(mx,mn)
else:
    print(a2[-1]-sum(a2[:-1]))
    mx,mn=a2[-1], a2[0]
    for i in a2[1:-1]:
        print(mx,i)
        mx-=i
    print(mx,mn)

Solution (Python):
from collections import deque

N = int(input())
A = [int(i) for i in input().split()]
p = deque()
m = deque()

A.sort(reverse=True)
for i in A:
    if i > 0:
        p.append(i)
    else:
        m.append(i)

ans = []
for _ in range(N-2):
    if p and m:
        if len(p) < len(m):
            tt = p.popleft()
            zz = m.pop()
            p.appendleft(tt-zz)
            ans.append([tt,zz])
        else:
            tt = m.pop()
            zz = p.popleft()
            m.append(tt-zz)
            ans.append([tt,zz])
    elif p:
        tt = p.pop()
        zz = p.popleft()
        m.append(tt-zz)
        ans.append([tt,zz])

    else:
        tt = m.popleft()
        zz = m.pop()
        p.append(tt-zz)
        ans.append([tt,zz])

if p and m:
    tt = p.pop()
    zz = m.pop()
    ans.append([tt,zz])
    print(tt-zz)

elif p:
    tt = p.popleft()
    zz = p.pop()
    ans.append([tt,zz])
    print(tt-zz)

else:
    tt = m.popleft()
    zz = m.pop()
    ans.append([tt,zz])
    print(tt-zz)

for i in range(N-1):
    tt,zz = ans[i]
    print(tt,zz)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
b.sort()
if n == 2:
    print(b[-1]-b[0])
    print(b[-1], b[0])
    exit()
if b[0] == 0 and b[-1] == 0:
    print(0)
    for i in range(n-1):
        print(0,0)
elif b[0] > 0 and b[-1] > 0:
    ans = sum(b) - 2*b[0]
    print(ans)
    print(b[1], b[0])
    left = b[1] - b[0]
    right = b[-1]
    for i in range(2, n-1):
        x = left
        y = b[i]
        print(x, y)
        left = x - y
    print(right, left)
elif b[0] < 0 and b[-1] < 0:
    ans = -sum(b) + 2*b[-1]
    print(ans)
    b = b[::-1]
    print(b[0], b[1])
    left = 0
    right = b[0] - b[1]
    for i in range(2, n):
        x = right
        y = b[i]
        print(x, y)
        right = x - y
else:
    ans = abs(sum(abs(i) for i in b))
    print(ans)
    now = 1
    left = b[0]
    right = b[-1]
    while b[now] < 0:
        x = right
        y = b[now]
        print(x, y)
        right = x - y
        now += 1
    for i in range(now, n-1):
        x = left
        y = b[i]
        print(x, y)
        left = x - y
    print(right, left)

Solution (Python):
from copy import deepcopy
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(max(A[0]-A[1],A[1],A[0]))
    print(max(A[0],A[1]),min(A[0],A[1]))
    quit()
A.sort()
ans=10**(-50)
S=sum(A)
for i in range(N-1):
    S=S-A[i]+(-A[i])
    if ans<S:
        ans=S
        j=i
print(ans)
for i in range(j+1,N-1):
    print(A[0],A[i])
    A[0]-=A[i]
for i in range(j+1):
    print(A[N-1],A[i])
    A[N-1]-=A[i]

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  ans=[]
  
  if l[0]>=0:
    a=l[0]
    for i in range(1,n-1):
      b=l[i]
      ans.append([a,b])
      a-=b
    ans.append([l[-1],a])

    print(l[-1]-a)
    for x in ans:
      print(x[0],x[1])

  
  elif l[0]<0 and l[-1]>=0:
    a=l[0] 
    b=l[-1] 

    for x in l[1:-1]:
      if x<=0:
        ans.append([b,x])
        b-=x
      else:
        ans.append([a,x])
        a-=x
    ans.append([b,a])

    print(b-a)
    for x in ans:
      print(x[0],x[1])

  
  else:
    l.reverse()
    a=l[0]
    for i in range(1,n-1):
      b=l[i]
      ans.append([a,b])
      a-=b
    ans.append([a,l[-1]])

    print(a-l[-1])
    for x in ans:
      print(x[0],x[1])

main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
mi,ma=a[0],a[-1]
for i in a[1:-1]:
  if i<0:ma-=i
  else:mi-=i
print(ma-mi)
mi,ma=a[0],a[-1]
for i in a[1:-1]:
  if i<0:print(ma,i);ma-=i
  else:print(mi,i);mi-=i
print(ma,mi)

Solution (Python):
import sys
N=int(input())
A=[int(i) for i in input().split()]
Aabs = [abs(a) for a in A]
zeroarray = []
plusarray = []
minusarray =[]
for n,a in enumerate(A):
    if a==0:
        zeroarray.append(a)
    elif a>0:
        plusarray.append(a)
    else:
        minusarray.append(a)
zeros =len(zeroarray)
plus = len(plusarray)
minus = N-zeros-plus
if zeros :
    firstzero = 0
    print(sum(Aabs))
    if plus:
        firstplus = plusarray[0]
        for i in range(1,plus):
            print(firstzero, plusarray[i])
            firstzero-=plusarray[i]
        if minus:
            for m in minusarray:
                print(firstplus,m)
                firstplus-=m
        if zeros>1:
            for i in range(1,zeros):
                print(firstzero,0)
        print(firstplus,firstzero)
    else:
        if zeros>1:
            for z in range(zeros-1):
                print(0,0)
        for m in minusarray:
            print(firstzero,m)
            firstzero-=m
    sys.exit()
    
if (plus and minus):
    firstminus = minusarray[0]
    print(sum(Aabs))
    firstplus = plusarray[0]
    firstminus = minusarray[0]
    for i in range(1,plus):
        print(firstminus, plusarray[i])
        firstminus-=plusarray[i]
    for i in range(1,minus):
        print(firstplus,minusarray[i])
        firstplus-=minusarray[i]
    print(firstplus,firstminus)
    sys.exit()
    
    
if plus:
    plusarray.sort()
    minplus = plusarray[0]
    firstplus = plusarray[1]
    print(sum(Aabs)-2*minplus)
    for i in range(2,plus):
        print(minplus, plusarray[i])
        minplus-=plusarray[i]
    print(firstplus,minplus)
    sys.exit()
   
else:
    minusarray.sort(reverse = True)
    maxminus = minusarray[0]
    print(sum(Aabs)+2*maxminus)
    for i in range(1,minus):
        print(maxminus, minusarray[i])
        maxminus-=minusarray[i]
    sys.exit()

Solution (Python):
import sys

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

pos = []
neg = []
for a in A:
    if a>0:
        pos.append(a)
    else:
        neg.append(a)
if len(neg)>0:
    if len(pos)>0:
        ttl = sum(pos) - sum(neg)
    else:
        ttl = - sum(neg) + 2 * max(neg)
else:
    
    ttl = sum(pos) - 2 * min(pos) - sum(neg)
print(ttl)

acc = 0
if len(neg)>0:
    if len(pos)>0:
        for i in range(len(pos)-1):
            print(neg[0], pos[i])
            neg[0] -= pos[i]
        print(pos[-1], neg[0])
        pos[-1] -= neg[0]
        for i in range(1, len(neg)):
            print(pos[-1], neg[i])
            pos[-1] -= neg[i]
    else:
        neg.sort()
        for i in range(len(neg)-2, -1, -1):
            print(neg[-1], neg[i])
            neg[-1] -= neg[i]
else:
    
    pos.sort()
    if N == 2:
        print(pos[1], pos[0])
    else:
        for i in range(1, len(pos)-1):
            print(pos[0], pos[i])
            pos[0] -= pos[i]
        print(pos[-1], pos[0])

Solution (Python):
N = int(input())

A = list(map(int, input().split()))
A.sort()
pA = []
nA = []
for a in A:
    if a < 0:
        nA.append(a)
    else:
        pA.append(a)

ans=[]
def calc():
    
    if len(pA) > 0 and len(nA) > 0: 
        for i in range(len(pA) -1):
            ans.append([nA[0], pA[i]])
            nA[0] -=  pA[i]

        for i in range(len(nA) -1):
            ans.append([pA[-1], nA[-i-1]])
            pA[-1] -= nA[-i-1]

        ans.append([pA[-1], nA[0]])
        return pA[-1] - nA[0]
    elif not nA:
        for i in range(1,len(pA) -1):
            ans.append([pA[0], pA[i]])
            pA[0] -=  pA[i]

        ans.append([pA[-1], pA[0]])
        return pA[-1] - pA[0]
    elif not pA:
        for i in range(1,len(nA) -1):
            ans.append([nA[-1], nA[-i-1]])
            nA[-1] -=  nA[-i-1]

        ans.append([nA[-1], nA[0]])
        return nA[-1] - nA[0]


x = calc()

print(x)
for a in  ans:
    print(*a)

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = max(a)
min_a = min(a)

if max(a) <= 0:
    count = max_a
    for i in range(n - 1):
        count += abs(a[i])
    print(count)
    for i in range(n - 1):
        print(max_a, a[i])
        max_a -= a[i]
elif min(a) >= 0:
    count = -min_a
    for i in range(n - 1):
        count += a[i + 1]
    print(count)
    for i in range(n - 2):
        print(min_a, a[i + 1])
        min_a -= a[i + 1]
    print(max_a, min_a)
else:
    count = 0
    for i in range(n):
        count += abs(a[i])
    print(count)
    num = bisect.bisect(a, 0)
    for i in range(num + 1, n):
        print(min_a, a[i])
        min_a -= a[i]
    a_num = a[num]
    a[0] = min_a
    for i in range(num):
        print(a_num, a[i])
        a_num -= a[i]

Solution (Python):
import sys
input = sys.stdin.readline


N=int(input())
A=list(map(int,input().split()))
A.sort()
ANS=[]

from collections import deque
X=deque(A)

while X[0]>=0 and len(X)>=3:
    x=X.popleft()
    z=X.pop()
    ANS.append([x,z])
    X.appendleft(x-z)

if len(X)==2:
    x=X[0]
    z=X[-1]

    ANS.append([z,x])
    print(z-x)
    for ans in ANS:
        print(*ans)
    sys.exit()
    




if X[0]<0:
    
    
    z=X.popleft()

    Y=[]
    while len(X)>=2:
        x=X.popleft()
        if x<0:
            Y.append(x)
        else:
            ANS.append([z,x])
            z=z-x

    x=X.pop()
    for y in Y:
        ANS.append([x,y])
        x-=y

    ANS.append([x,z])
    x-=z

    print(x)
    for ans in ANS:
        print(*ans)

Solution (Python):
from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
a.sort()
if(a[0]>=0):
    print(sum(a[1:])-a[0])
    ans=a[0]
    for i in a[1:n-1]:
        print(ans,i)
        ans-=i
    print(a[-1],ans)
elif(a[-1]<=0):
    print(a[-1]-sum(a[:n-1]))
    ans=a[-1]
    for i in a[:n-1]:
        print(ans,i)
        ans-=i
else:
    print(sum([abs(i) for i in a]))
    b=bisect_left(a,0)
    ans=a[0]
    tmp=a[-1]
    for i in a[b:n-1]:
        print(ans,i)
        ans-=i
    for i in a[1:b]:
        print(tmp,i)
        tmp-=i
    print(tmp,ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
if(arr[0]>=0):
	sumx=sum(arr)-2*(arr[0])
	ansarr=[]
	if(n==2):
		ansarr.append(arr[1])
		ansarr.append(arr[0])
		val=arr[1]-arr[0]
	else:
		ansarr.append(arr[0])
		ansarr.append(arr[1])
		val=arr[0]-arr[1]
		for i in range(2,n-1):
			ansarr.append(val)
			ansarr.append(arr[i])
			val=val-arr[i]
		ansarr.append(arr[n-1])
		ansarr.append(val)
		val=arr[n-1]-val
	print(val)
	print(*ansarr)

elif(arr[-1]<=0):
	sumx=0
	for i in range(n-1):
		sumx+=abs(arr[i])
	sumx-=abs(arr[n-1])
	ansarr=[]
	if(n==2):
		ansarr.append(arr[1])
		ansarr.append(arr[0])
		val=arr[1]-arr[0]
	else:
		ansarr.append(arr[n-1])
		ansarr.append(arr[n-2])
		val=arr[n-1]-arr[n-2]
		for i in range(n-3,-1,-1):
			ansarr.append(val)
			ansarr.append(arr[i])
			
			val=val-arr[i]

	print(val)
	print(*ansarr)
else:
	val=0
	index=-1
	for i in range(n):
		if(arr[i]>0):
			index=i
			break
	val=arr[0]
	ansarr=[]
	for i in range(index,n-1):
		ansarr.append(val)
		ansarr.append(arr[i])
		
		val-=arr[i]

	ansarr.append(arr[n-1])
	ansarr.append(val)
	val=arr[n-1]-val
	for i in range(1,index):
		ansarr.append(val)
		ansarr.append(arr[i])
		
		val-=arr[i]

	print(val)
	print(*ansarr)