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):
import bisect

N = int(input())
A = sorted(map(int,input().split()))

i = bisect.bisect_left(A, 0)
j = bisect.bisect_right(A, 0)
if i == j:
    if i == 0:
        negatives = A[:1]
        positives = A[1:]
    elif i == N:
        negatives = A[:-1]
        positives = A[-1:]
    else:
        negatives = A[:i]
        positives = A[i:]

else:
    m = max((i+j)//2, 1)
    negatives = A[:m]
    positives = A[m:]


score = sum(positives) - sum(negatives)
print(score)

def it():

    def balanced(pos, neg):
        y = neg.pop()
        x = pos.pop()
        yield (x,y)
        y = x-y
        while pos and neg:
            x = neg.pop()
            yield (x,y)
            y = x-y
            x = pos.pop()
            yield (x,y)
            y = x-y

    if len(positives) < len(negatives):

        x = positives.pop()

        while len(positives)+1 < len(negatives):
            y = negatives.pop()
            yield (x,y)
            x -= y
        positives.append(x)
    elif len(positives) > len(negatives):
        x = negatives.pop()

        while len(negatives)+1 < len(positives):
            y = positives.pop()
            yield (x,y)
            x -= y
        negatives.append(x)

    for x,y in balanced(positives, negatives):
        yield x,y


for x,y in it():
    print(x,y)

Solution (Python):
import sys
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
a = A[0]
b = A[-1]
if N == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    sys.exit()
ans = []
for x in A[1:-1]:
    if x <= 0:
        ans.append([b, x])
        b = b - x
    else:
        ans.append([a, x])
        a = a - x
ans.append([b,a])
M = b-a
print(M)
for x in ans:
    print(x[0], x[1])

Solution (Python):

if __name__=='__main__':
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    k = N-1
    x = 0
    for i in range(1,N):
        if A[i]>0:
            k = i
            break
    M = sum(A[k:])-sum(A[:k])
    print(M)
    x = A[k-1]
    for i in range(k,N-1):
        print('{} {}'.format(x,A[i]))
        x = x - A[i]
    print('{} {}'.format(A[N-1],x))
    x = A[N-1] - x
    for i in range(k-1):
        print('{} {}'.format(x,A[i]))
        x = x -A[i]

Solution (Python):
import sys
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
a = A[0]
b = A[-1]
if N == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    sys.exit()
ans = []
for x in A[1:-1]:
    if x <= 0:
        ans.append([b, x])
        b = b - x
    else:
        ans.append([a, x])
        a = a - x
ans.append([b,a])
M = b-a
print(M)
for x in ans:
    print(x[0], x[1])

Solution (Python):
n = input()
a_ls = list(map(int, input().split()))
a_ls.sort()
min_value = a_ls.pop(0)
max_value = a_ls.pop(len(a_ls)-1)
output_ls = []
for i in range(len(a_ls)):
    hoge = []
    if a_ls[i] > 0:
        hoge.append(min_value)
        hoge.append(a_ls[i])
        output_ls.append(hoge)
        min_value = min_value - a_ls[i]
    else:
        hoge.append(max_value)
        hoge.append(a_ls[i])
        output_ls.append(hoge)
        max_value = max_value - a_ls[i]
hoge = []
hoge.append(max_value)
hoge.append(min_value)
output_ls.append(hoge)
print(max_value - min_value)
for j in range(len(output_ls)):
    print(str(output_ls[j][0]) + ' ' + str(output_ls[j][1]))

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

ans = a[0]
ans_l = []
ans_e = a[-1]


if n > 2:
    if ans_e >= 0:
        for i in range(1,n-1):
            if a[i] < 0:
                ans_l += [(ans_e, a[i])]
                ans_e -= a[i]
            if a[i] >= 0:
                ans_l += [(ans, a[i])]
                ans -= a[i]

        ans_l += [(ans_e,ans)]
        ans = ans_e - ans

    else:
        ans = ans_e
        for i in range(0,n-1):
            ans_l += [(ans, a[i])]
            ans -= a[i]

else:
    ans_l += [(ans_e,ans)]
    ans = ans_e - ans

print(ans)

for x, y in ans_l:
    print(x,y)

Solution (Python):
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = deque(A)
if A[0] <= 0 and A[-1] >= 0:
    print(sum(map(abs, A)))
    while len(d) > 2:
        while d[1] < 0:
            x = d.pop()
            y = d.popleft()
            print(x, y)
            d.append(x - y)
        x = d.popleft()
        y = d.pop()
        if d:
            print(x, y)
        else:
            print(y, x)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])

elif A[0] > 0:
    print(sum(A) - 2 * A[0])
    x = d.popleft()
    y = d.pop()
    if not d:
        print(y, x)
    else:
        print(x, y)
    d.appendleft(x - y)
    while len(d) > 2:
        x = d.popleft()
        y = d.pop()
        print(x, y)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])
else:
    print(-sum(A) + 2 * A[-1])
    x = d.pop()
    y = d.popleft()
    print(x, y)
    d.append(x - y)
    while len(d) > 2:
        while d[1] < 0 and len(d) > 2:
            x = d.pop()
            y = d.popleft()
            print(x, y)
            d.append(x - y)
        x = d.pop()
        y = d.popleft()
        print(x, y)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])

Solution (Python):
n = int(input())
a = list(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))
  for i in range(len(a1)-1):
    print(a2[0],a1[i])
    a2[0] = a2[0] - a1[i]
  acur = a1[len(a1)-1] - a2[0]
  print(a1[len(a1)-1],a2[0])
  for i in range(1,len(a2)):
    print(acur,a2[i])
    acur = acur - a2[i]
elif a1:
  a1.sort()
  print(sum(a1)-2*a1[0])
  for i in range(1,n-1):
    print(a1[0],a1[i])
    a1[0] -= a1[i]
  print(a1[n-1],a1[0])
else:
  a2.sort()
  print(2*a2[n-1]-sum(a2))
  for i in range(n-1):
    print(a2[n-1],a2[i])
    a2[n-1] -= a2[i]

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

a.sort()
l=[]
sum=-a[0]+a[n-1]
for i in range(n-2):
    sum+=abs(a[i+1])
print(sum)

x=a[n-1]-a[0]
for i in range(n-1):
    if i==0:
        l.append([a[n-1],a[0]])
    else:
        if a[i]<0:
            l.append([x,a[i]])
            x+=abs(a[i])
        else:
            s=l[i-1][0]
            t=l[i-1][1]
            l[i-1][0]=t
            l[i-1][1]=s
            l.append([a[i],-x])
            x+=a[i]

for y in l:
    print(y[0],y[1])

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
a.sort()
d = deque(a)
seq = []
for i in range(n-2):
    l = d.popleft()
    r = d.pop()
    r2 = d.pop()
    if r2>0:
        seq.append((l,r2))
        d.appendleft(l-r2)
        d.append(r)
    else:
        seq.append((r,r2))
        d.appendleft(l)
        d.append(r-r2)

bb = d.pop()
aa = d.pop()
seq.append((bb,aa))
print(bb-aa)
for i in range(n-1):
    print("{} {}".format(seq[i][0], seq[i][1]))

Solution (Python):
from collections import deque
N = int(input())
A = [int(i) for i in input().split()]

pos = [a for a in A if a >= 0]
neg = [a for a in A if a < 0]


pos.sort()
neg.sort()

pd = deque(pos)
nd = deque(neg)

buf = []

while len(pd) + len(nd) > 2:  
    
    if len(nd) == 0:
        y, x = pd.pop(), pd.popleft()
        buf.append((x, y))
        nd.append(x - y)
        continue
    
    if len(pd) == 0:
        x, y = nd.pop(), nd.popleft()
        buf.append((x, y))
        pd.append(x - y)
        continue
    
    if len(pd) > 1:
        x, y = nd.pop(), pd.pop()
        buf.append((x, y))
        nd.append(x - y)
        continue
    
    if len(pd) == 1:
        x, y = pd.pop(), nd.pop()
        buf.append((x, y))
        pd.append(x - y)
        continue

merge = []
merge.extend(nd)
merge.extend(pd)

val = merge[1] - merge[0]
buf.append((merge[1], merge[0]))


print(val)
for b in buf:
    print(b[0], b[1])

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

a.sort()
if a[0] >= 0:
    m = sum(a[1:]) - a[0]
    print(m)
    tmp = a[0]
    for i in range(1, n-1):
        print(tmp, a[i])
        tmp -= a[i]
    print(a[n-1], tmp)
elif a[-1] <= 0:
    m = -sum(a[:-1]) + a[-1]
    print(m)
    tmp = a[n-1]
    for i in range(n-1):
        print(tmp, a[i])
        tmp -= a[i]
else:
    m = 0
    pos = []
    neg = []
    for ai in a:
        m += abs(ai)
        if ai >= 0:
            pos.append(ai)
        else:
            neg.append(ai)
    print(m)
    tmp = 0
    ni = 0
    pi = 0

    if len(pos) > 1:
        print(neg[ni], pos[pi])
        tmp = neg[ni] - pos[pi]
        ni += 1
        pi += 1

        while pi < len(pos) - 1:
            print(tmp, pos[pi])
            tmp = tmp - pos[pi]
            pi += 1
        print(pos[pi], tmp)
        tmp = pos[pi] - tmp
        while ni < len(neg):
            print(tmp, neg[ni])
            tmp -= neg[ni]
            ni += 1
    else:
        print(pos[pi], neg[ni])
        tmp = pos[pi] - neg[ni]
        ni += 1
        while ni < len(neg):
            print(tmp, neg[ni])
            tmp -= neg[ni]
            ni += 1

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



lst = []

  
nmi = min(x)
nma = max(x)
del x[x.index(nmi)]
del x[x.index(nma)]

mainus = [i for i in x if i < 0]
plus = [i for i in x if i >= 0]
for i in mainus:
  lst.append(str(nma)+" "+str(i))
  nma -= i
for i in plus:
  lst.append(str(nmi)+" "+str(i))
  nmi -= i
lst.append(str(nma)+" "+str(nmi))
print(nma-nmi)
for i in lst:
  print(i)
"""
while max(x) > -1 and len(x) > 1:
  mi = min(x)
  ma = max(x)
  lst.append(str(mi)+" "+str(ma))
  del x[x.index(mi)]
  del x[x.index(ma)]
  x.append(mi - ma)

for i in range(len(x)):
  lst.append(str(nma)+" "+str(i))
  nma += i
print(nmi - nma)
for i in range(len(lst)):
  print(lst[i])
print(nmi,nma)
"""

Solution (Python):


from sys import stdin
from collections import deque


def main():
  
  N = int(input())
  An = list(map(int, stdin.readline().rstrip().split()))
  An = sorted(An)
  Bn_p,Bn_n = [deque(),deque()]
  for a in An:
    if a >= 0:
      Bn_p.append(a)
    else:
      Bn_n.append(a)
  Bn_n = deque(sorted(Bn_n,reverse=True))

  xy = deque()
  ans = 0
  if len(Bn_p)==0:
    
    ans = Bn_n[0]
    for i in range(1,len(Bn_n)):
      x = ans
      y = Bn_n[i]
      xy.append([x,y])
      ans = x-y
  elif len(Bn_n)==0:
    
    ans = Bn_p[0]
    for i in range(1,len(Bn_p)-1):
      x = min([Bn_p[i],ans])
      y = max([Bn_p[i],ans])
      xy.append([x,y])
      ans = x-y
    xy.append([Bn_p[-1],ans])
    ans = Bn_p[-1]-ans
  else:
    
    ans_n = Bn_p.popleft()
    ans_p = Bn_n.popleft()
    
    for i in range(len(Bn_p)):
      x = ans_p
      y = Bn_p[i]
      xy.append([x,y])
      ans_p = x-y

    Bn_n.append(ans_p)
    
    for i in range(len(Bn_n)):
      x = ans_n
      y = Bn_n[i]
      xy.append([x,y])
      ans_n = x-y
    ans = ans_n

  print(ans)
  for x,y in xy:
    print(x,y)

if __name__ == "__main__":
  main()

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

if n == 2:
    print(a[1] - a[0])
    print("{} {}".format(a[1], a[0]))
    exit()

if a[0] <= 0 and 0 <= a[-1]:
    import bisect
    print(sum(map(lambda x: abs(x), a)))
    x0 = bisect.bisect_left(a,0)

    
    if a[-2] >= 0:
        if x0 == 0:
            x0 += 1
        print("{} {}".format(a[0], a[x0]))
        res = a[0] - a[x0]

        for x in a[x0+1:-1]:
            print("{} {}".format(res, x))
            res -= x
    else:
        res = a[0]

    
    print("{} {}".format(a[-1], res))
    res = a[-1] - res
    for x in a[1:x0]:
        print("{} {}".format(res,x))
        res -= x

elif a[0] > 0:
    print(sum(a) - 2*a[0])

    print("{} {}".format(a[0],a[1]))
    res = a[0] - a[1]
    for x in a[2:-1]:
        print("{} {}".format(res, x))
        res -= x
    
    print("{} {}".format(a[-1], res))
else:
    print(-sum(a) + 2*a[-1])

    print("{} {}".format(a[-1],a[-2]))
    res = a[-1] - a[-2]
    for x in a[:-2]:
        print("{} {}".format(res, x))
        res -= x

Solution (Python):
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict
import bisect

sys.setrecursionlimit(1000000000)

n = SI()
a_list = LI()

a_list =  sorted(a_list)
minus = bisect.bisect_left(a_list, 0)
minus_list = a_list[:minus]

plus_list = a_list[minus:]

ans = 0
p_i = 0
m_i = 0
if minus == 0:
    print(sum(plus_list) - 2*plus_list[0])
    minus_list = plus_list[0:1]
    plus_list = plus_list[1:]


elif minus == n:
    print(-sum(minus_list) + 2*minus_list[-1])
    plus_list = minus_list[-1:]
    minus_list = minus_list[:-1]

else:
    print(sum(plus_list) - sum(minus_list))

ans = minus_list[m_i]
m_i += 1
minus = len(minus_list)
plus = len(plus_list)


while p_i != (plus-1):
    print(ans, plus_list[p_i])
    ans = ans - plus_list[p_i]
    p_i += 1

print(plus_list[p_i], ans)
ans = plus_list[p_i] - ans

while m_i != minus:
    print(ans, minus_list[m_i])
    ans = ans - minus_list[m_i]
    m_i += 1

Solution (Python):
from collections import deque
def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    pos = []
    neg = []
    for a in As:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(a)
    pos = deque(sorted(pos))
    neg = deque(sorted(neg))
    x = 0
    y = 0
    ops = []
    while True:
        if len(pos) > 0 and len(neg) > 0:
            if len(pos) > len(neg):
                x = neg.popleft()
                y = pos.pop()
            else:
                x = pos.pop()
                y = neg.popleft()
        elif len(pos) > 1 and len(neg) == 0:
                x = pos.popleft()
                y = pos.pop()
        elif len(neg) > 1 and len(pos) == 0:
                x = neg.pop()
                y = neg.popleft()
        else:
            raise Exception("Unreachable?")
        
        ops.append("{} {}".format(x, y))
        xmy = x - y

        if len(pos) == 0 and len(neg) == 0:
            print(xmy)
            break

        if xmy >= 0:
            pos.append(xmy)
        else:
            neg.appendleft(xmy)
        
    [print(i) for i in ops]

if '__main__' == __name__:
    resolve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
check = -1
for i in range(N):
    if A[i] > 0:    
        break
    check += 1

ans = 0
if 0 <= check < N-1:
    ans = 0
    for i in range(N):
        if i <= check:
            ans -= A[i]
        else:
            ans += A[i]
else:
    ans = abs(sum(A)) - 2*min(abs(A[0]),abs(A[N-1]))
print(ans)
tmp = A[0]
i = 0
while N-i-2 > max(0,check):
    print(str(tmp) + " " + str(A[N-i-1]))
    tmp -= A[N-i-1]
    i += 1
if N-i-2 <= check or N-i-2 == 0:
    print(str(A[N-i-1]) + " " + str(tmp))
    tmp = A[N-i-1] - tmp
    i += 1
while N-i-1 > 0:
    print(str(tmp) + " " + str(A[N-i-1]))
    tmp -= A[N-i-1]
    i += 1

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
K = N-1
ans = []
while(K>1):
    if A[K-1] < 0:
        break
    l = A[0] - A[K]
    ans.append(str(A[0])+" "+str(A[K]))
    A[0] = l
    K -= 1
if K == 1:
    ans.append(str(A[1])+" "+str(A[0]))
    print(A[1]-A[0])
else:
    b = A[K]
    for i in range(K-1,0,-1):
        c = A[i]
        ans.append(str(b)+" "+str(c))
        b = b-c
    ans.append(str(b)+" "+str(A[0]))
    print(b-A[0])
for p in ans:
    print(p)

Solution (Python):
import sys

inf = 10 ** 18

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

from collections import deque

A = deque(sorted(A))

pm = N % 2
ans = []
for i in range(N - 2):
    
    A_min = A.popleft()
    A_max = A.pop()
    
    A_dif = A_max - A_min
    if A_dif - A[0] > A[-1] - (-A_dif):
        ans.append((A_max, A_min))
        A.append(A_max - A_min)
    else:
        ans.append((A_min, A_max))
        A.appendleft(A_min - A_max)
    
ans.append((A[1], A[0]))

print(A[1] - A[0])
for x, y in ans: print(x, y)

Solution (Python):
import sys
n = int(input())
a = list(map(int,sys.stdin.readline().split()))
a.sort()
minA = a[0]
mx = a[-1]
ans = []
t = ''

s =0

if a[0]<0 and a[-1]>-1:
    l = a[0]
    h = a[-1]
    for i in range(1,n-1):
        if a[i]<0:
            ans.append([h,a[i]])
            h = h-a[i]
        else:
            ans.append([l,a[i]])
            l = l-a[i]
    ans.append([h,l])
    s = h-l
elif a[0]>-1 and a[-1]>-1:
    c = a[0]-a[-1]
    ans.append([a[0],a[-1] ])
    for i in range(1, n - 2):
        ans.append([c,a[i]])
        c = c - a[i]
    if n>2:
        ans.append([a[-2],c])
        s = a[-2]-c
    else:
        s=c
else:
    c = a[-1]-a[0]
    ans.append([a[-1],a[0]])
    for i in range(1, n-1):
        ans.append([c,a[i]])
        c= c-a[i]
    s=c

print(s)

for v,w in ans:
    print(v,w)

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

from collections import deque

deq = deque(a_list)
res = []
while len(deq) > 2:
    min_num = deq.popleft()
    max_num = deq.pop()
    if min_num < 0 and max_num > 0:
        ne = deq.pop()
        if ne >= 0:
            res.append((min_num, ne))
            min_num -= ne
            deq.appendleft(min_num)
            deq.append(max_num)
        else:
            res.append((max_num, ne))
            max_num -= ne
            deq.append(max_num)
            deq.appendleft(min_num)
    else:
        if max_num <= 0:
            res.append((max_num, min_num))
            max_num = max_num - min_num
            deq.append(max_num)
        else:
            res.append((min_num, max_num))
            min_num = min_num - max_num
            deq.appendleft(min_num)

tmp1 = deq[0]
tmp2 = deq[1]
res.append((max(tmp1, tmp2), min(tmp2, tmp1)))
ans = max(tmp1, tmp2) - min(tmp2, tmp1)
print(ans)
for x,y in res:
    print(x, y)

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

switch=0
counter=0
mazu=newlist[0]
if newlist[0]>=0:
    seihu=1
else:
    seihu=-1
konzai=0

for nl in newlist:
    if mazu!=nl:
        switch=1

if switch==1:
    wa=0
    list2=[]
    for nl in range(n):
        list2.append([newlist[nl], abs(newlist[nl])])
        if seihu*newlist[nl]<0:
            konzai=1
            numb=nl
            numba=newlist[numb]
    if konzai==1:
        wa=0
        for nl in range(n):
            wa+=abs(newlist[nl])
        print(wa)
        now=newlist[numb]
        
        newlist.remove(numba)
        
        
        
        if newlist[1]>0:
            if now>=0:
                
                print(newlist[0], now)
            else:
                
                print(now,newlist[0])
        else:
            if now>=0:
                print(now, newlist[0])
            else:
                print(newlist[0], now)
            
        now=abs(now)+abs(newlist[0])
        if newlist[1]>0:
            now=now*(-1)
        for xi in range(n-3):
            
            if newlist[xi+2]>0:
                if now>=0:
                    print(newlist[xi+1], now)
                else:
                    print(now, newlist[xi+1])
                now=-abs(now)-abs(newlist[xi+1])
            else:
                if now>=0:
                    print(now, newlist[xi+1])
                else:
                    print(newlist[xi+1], now)
                now=abs(now)+abs(newlist[xi+1])
        if newlist[-1]>0:
            print(newlist[-1], now)
        else:
            print(now, newlist[-1])
    elif seihu==1:
        newlist=sorted(newlist)
        wa=0
        for nl in range(n):
            wa+=abs(newlist[nl])
        wa-=newlist[0]*2
        print(wa)
        print(newlist[0], newlist[1])
        now=newlist[0]-newlist[1]
        for ll in range(n-2):
            if counter==n-3:
                print(newlist[ll+2], now)
                now=-(abs(now)+abs(newlist[ll+2]))
            else:
                print(now, newlist[ll+2])
                now=-(abs(now)+abs(newlist[ll+2]))
            counter+=1
    elif seihu==-1:
        newlist=sorted(newlist, reverse=True)
        wa=0
        for nl in range(n):
            wa+=abs(newlist[nl])
        wa+=newlist[0]*2
        print(wa)
        print(newlist[0], newlist[1])
        now=newlist[0]-newlist[1]
        for ll in range(n-2):
            if counter==n-3:
                print(now, newlist[ll+2])
                now=(abs(now)+abs(newlist[ll+2]))
            else:
                print(now, newlist[ll+2])
                now=(abs(now)+abs(newlist[ll+2]))
            counter+=1
    
else:
    print(abs(mazu*(len(newlist)-2)))
    for i in range(len(newlist)-2):
        print(mazu*(1-i), mazu)
    if mazu>=0:
        print(mazu, mazu*(3-len(newlist)))
    else:
        print(mazu*(3-len(newlist)), mazu)

Solution (Python):
n = int(input())
ps = []
mis = []
for _ in input().split():
  item = int(_)
  if item >= 0:
    ps.append(item)
  else:
    mis.append(item)
  
mis.sort(reverse = True)
ps.sort()
if len(mis) == 0:
  mis = [ps[0]]
  ps = ps[1:]
if len(ps) == 0:
  ps = [mis[0]]
  mis = mis[1:]
print(sum(ps) - sum(mis))

pre = mis[0]
for p in ps[:len(ps) - 1]:
  print(pre, p)
  pre -= p
print(ps[-1], pre)
pre = ps[-1] - pre
for m in mis[1:]:
  print(pre, m)
  pre -= m

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

if N == 2:
    y, x = A
    print(x-y)
    print(x, y)
    exit()

XY = []

PLUS = 0
MINUS = 0
for a in A:
    if a >= 0:
        PLUS += 1
    else:
        MINUS += 1

XY = []
tmp = A[0]
if PLUS and MINUS:
    while PLUS >= 2:
        x, y = tmp, A.pop()
        XY.append((x, y))
        tmp = x-y
        PLUS -= 1
    x, y = A.pop(), tmp
    XY.append((x, y))
    tmp = x-y
    N = len(A)
    for i in range(1, N):
        a = A[i]
        x, y = tmp, a
        XY.append((x, y))
        tmp = x-y
elif PLUS:
    for i in range(N-1):
        if i < N-2:
            x, y = tmp, A.pop()
            XY.append((x, y))
            tmp = x-y
        if i == N-2:
            x, y = A.pop(), tmp
            XY.append((x, y))
            tmp = x-y
else:
    for i in range(N-1):
        if i == 0:
            x, y = A.pop(), tmp
            XY.append((x, y))
            tmp = x-y
        else:
            x, y = tmp, A.pop()
            XY.append((x, y))
            tmp = x-y       
ans = tmp
print(ans)
for x, y in XY:
    print(x, y)

Solution (Python):
import sys
import collections

n = int(input())
a = sorted([int(i) for i in input().split()])

top = a.pop(-1)

nega = sorted([i for i in a if i < 0])
posi = sorted([i for i in a if i >= 0])


if len(nega) == 0:
    nega.append(posi.pop(0))

process = []

for _ in range(len(posi)):
    x = nega.pop(0)
    y = posi.pop(0)
    nega.append(x - y)
    process.append([x, y])
x = top
y = nega.pop(0)
process.append([x, y])
x -= y
for _ in range(len(nega)):
    y = nega.pop(0)
    process.append([x, y])
    x -= y
ans = x

print(ans)
for i in range(len(process)):
    print('{} {}'.format(process[i][0], process[i][1]))

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

left = nums[0]
right = sum(nums[1:])

ans = right - left
arg = 0
for i in range(1, n - 1):
	left += nums[i]
	right -= nums[i]
	if right - left > ans:
		arg = i
		ans = right - left

print(ans)

l_list = nums[:(arg + 1)]
r_list = nums[(arg + 1):]

while len(l_list) > 1:
	x = r_list.pop()
	y = l_list.pop()
	print(str(x) + " " + str(y))
	r_list.append(x - y)

x = l_list.pop()
while len(r_list) > 1:
	y = r_list.pop()
	print(str(x) + " " + str(y))
	x = x - y

print(str(r_list.pop()) + " " + str(x))

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10



N = int(stdin.readline().rstrip())
A = list(map(int, stdin.readline().rstrip().split()))
A_abs = [abs(x) for x in A]




if N == 2:
    x = max(A)
    y = min(A)
    print(x-y)
    print(x, y)
    exit()


result = []

plus_num = []
minus_num = []

for Ai in A:
    if Ai > 0:
        plus_num.append(Ai)
    else:
        minus_num.append(Ai)

plus_num_cnt = len(plus_num)
minus_num_cnt = len(minus_num)

if minus_num_cnt == 0:
    
    plus_num.sort(reverse=True)
    x = plus_num.pop()
    y = plus_num.pop()
    if x > y:
        tmp = x
        x = y
        y = tmp
    
    result.append([x, y])
    minus_num.append(x-y)
    plus_num_cnt -= 2
    minus_num_cnt += 1

elif plus_num_cnt == 0:
    
    minus_num.sort()
    x = minus_num.pop()
    y = minus_num.pop()
    if x < y:
        tmp = x
        x = y
        y = tmp

    result.append([x, y])
    plus_num.append(x-y)
    minus_num_cnt -= 2
    plus_num_cnt += 1

    


if plus_num_cnt > 0 and minus_num_cnt > 0:

    while(plus_num_cnt > 0):
        if plus_num_cnt == 1:
            break

        x = minus_num.pop()
        y = plus_num.pop()

        result.append([x, y])
        minus_num.append(x-y)
        plus_num_cnt -= 1


    while minus_num_cnt > 0:
        x = plus_num.pop()
        y = minus_num.pop()

        result.append([x, y])
        plus_num.append(x-y)
        minus_num_cnt -= 1

    print(plus_num[0])
    for i, j in result:
        print(i, j)

Solution (Python):
n = list(map(int, input().split()))
n = n[0]

a = list(map(int, input().split()))


if(max(a)>0 and min(a)>0):
    a.sort()
    total = sum(a)-2*a[0]
    print(total)
    temp=a[0]
    for i in range(n-2):
        print(temp,a[i+1])
        temp=temp-a[i+1]
    print(a[n-1],temp)
elif(max(a)<0 and min(a)<0):
    b = [abs(a[i]) for i in range(len(a))]
    b.sort()
    total = sum(b)-2*b[0]
    print(total)
    temp= -b[0]
    for i in range(n-2):
        print(temp,-b[i+1])
        temp=temp+b[i+1]
    print(temp, -b[n-1])
else:
    b = [abs(a[i]) for i in range(len(a))]
    total = sum(b)
    print(total)
    a.sort()
    temp=a[n-1]
    for i in range(n-1):
        if(i==n-2):
            print(max(a[i],temp),min(a[i],temp))
        elif(a[i+1]>=0):
            print(min(a[i],temp),max(a[i],temp))
            temp=min(a[i],temp)-max(a[i],temp)
        else:
            print(max(a[i],temp),min(a[i],temp))
            temp=max(a[i],temp)-min(a[i],temp)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
A.sort()
positive=[x for x in A if x >=0]
negative=[x for x in A if x <0]
ans=[]



if len(negative)>0 and len(positive)>0:
    y=negative[0]
    for i in positive[1:]:
        ans.append([y,i])
        y-=i
        
    x=positive[0]
    for i in negative[1:]:
        ans.append([x,i])
        x-=i

    M=x-y
    ans.append([x,y])

elif len(negative)==0:
    x=positive[N-1]
    y=positive[0]
    for i in positive[1:N-1]:
        ans.append([y,i])
        y-=i
    M=x-y
    ans.append([x,y])

elif len(positive)==0:
    negative.reverse()
    y=negative[N-1]
    x=negative[0]
    for i in negative[1:N-1]:
        ans.append([x,i])
        x-=i
    M=x-y
    ans.append([x,y])
    
print(M)
for i in ans:
    print(i[0],i[1])

Solution (Python):
n = int(input())
a_s = [int(v) for v in input().split()]

a_s.sort()


m = a_s[-1] - a_s[0]
for a in a_s[1:-1]:
  m += abs(a)
  


print(m)

max_a = a_s[-1]
min_a = a_s[0]

for a in a_s[1:-1]:
  if a < 0:
    print("{} {}".format(max_a, a))
    max_a -= a
  else:
    print("{} {}".format(min_a, a))
    min_a -= a
    
print("{} {}".format(max_a, min_a))

Solution (Python):
from collections import deque
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] >= 0:
    M = sum(A[1:])-A[0]
    print(M)
    for i in range(N-1):
        if i == 0:
            x = A[0]
            y = A[N-1]
            print(x, y)
        elif i <= N - 3:
            x = new
            y = A[N-1-i]
            print(x, y)
        else:
            x = A[N-1-i]
            y = new
            print(x, y)
        new = x - y
elif A[-1] <= 0:
    M = sum(A[:-1]) * (-1) + A[-1]
    print(M)
    for i in range(N-1):
        if i == 0:
            x = A[N-1]
            y = A[0]
            print(x, y)
        elif i <= N-3:
            x = new
            y = A[i]
            print(x, y)
        else:
            x = new
            y = A[i]
            print(x,y)
        new = x- y
else:
    absa = [abs(i) for i in A]
    M = sum(absa)
    print(M)
    if A[1] >= 0 :
        for i in range(N - 1):
            if i == 0:
                x = A[0]
                y = A[N - 1]
                print(x, y)
            elif i <= N - 3:
                x = new
                y = A[N - 1 - i]
                print(x, y)
            else:
                x = A[N - 1 - i]
                y = new
                print(x, y)
            new = x - y
    else:
        A = deque(A)
        for i in range(N - 1):
            if i <= N - 3 and A[1] < 0:
                x = A.pop()
                y = A.popleft()
                print(x, y)
                A.append(x-y)
            elif i <= N-3 :
                x = A.popleft()
                y = A.pop()
                print(x,y)
                A.appendleft(x-y)
            else:
                
                x = A.pop()
                y = A.popleft()
                print(x, y)

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

B=[]
for i in range(1,N-1):
    if A[i]>=0:
        B.append([A[0],A[i]])
        A[0]-=A[i]
    else:
        B.append([A[-1],A[i]])
        A[-1]-=A[i]
print(A[-1]-A[0])
for b in B:
    print(b[0],b[1])
print(A[-1],A[0])