from heapq import heapify,heappop,heappush
n = int(input())
a = list(map(int,input().split()))
if max(a) > 0 and min(a) < 0:
  hp = []
  hn = []
  heapify(hp)
  heapify(hn)
  ans = 0
  for i in range(n):
    if a[i] >= 0:
      heappush(hp,a[i])
      ans += a[i]
    else:
      ans -= a[i]
      heappush(hn,a[i])
  print(ans)
  while hp and hn:
    p = heappop(hp)
    q = heappop(hn)
    if hn:
      print(p,q)
      heappush(hp,p-q)
    elif hp:
      print(q,p)
      heappush(hn,q-p)
    else:
      print(p,q)
elif min(a) >= 0:
  ans = sum(a)-2*min(a)
  print(ans)
  heapify(a)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break
elif max(a) <= 0:
  ans = -sum(a)+2*max(a)
  a = [-a[i] for i in range(n)]
  heapify(a)
  print(ans)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break from heapq import heapify,heappop,heappush n = int(input()) n int(input()) int input() input a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split if max(a) > 0 and min(a) < 0:
  hp = []
  hn = []
  heapify(hp)
  heapify(hn)
  ans = 0
  for i in range(n):
    if a[i] >= 0:
      heappush(hp,a[i])
      ans += a[i]
    else:
      ans -= a[i]
      heappush(hn,a[i])
  print(ans)
  while hp and hn:
    p = heappop(hp)
    q = heappop(hn)
    if hn:
      print(p,q)
      heappush(hp,p-q)
    elif hp:
      print(q,p)
      heappush(hn,q-p)
    else:
      print(p,q)
elif min(a) >= 0:
  ans = sum(a)-2*min(a)
  print(ans)
  heapify(a)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break
elif max(a) <= 0:
  ans = -sum(a)+2*max(a)
  a = [-a[i] for i in range(n)]
  heapify(a)
  print(ans)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break max(a) > 0 and min(a) < 0 max(a) > 0 max(a) max a 0 min(a) < 0 min(a) min a 0 hp = [] hp [] hn = [] hn [] heapify(hp) heapify hp heapify(hn) heapify hn ans = 0 ans 0 for i in range(n):
    if a[i] >= 0:
      heappush(hp,a[i])
      ans += a[i]
    else:
      ans -= a[i]
      heappush(hn,a[i])
   i range(n) range n if a[i] >= 0:
      heappush(hp,a[i])
      ans += a[i]
    else:
      ans -= a[i]
      heappush(hn,a[i])
   a[i] >= 0 a[i] a i 0 heappush(hp,a[i]) heappush hp a[i] a i ans += a[i] ans a[i] a i ans -= a[i] ans a[i] a i heappush(hn,a[i]) heappush hn a[i] a i print(ans) print ans while hp and hn:
    p = heappop(hp)
    q = heappop(hn)
    if hn:
      print(p,q)
      heappush(hp,p-q)
    elif hp:
      print(q,p)
      heappush(hn,q-p)
    else:
      print(p,q) hp and hn hp hn p = heappop(hp) p heappop(hp) heappop hp q = heappop(hn) q heappop(hn) heappop hn if hn:
      print(p,q)
      heappush(hp,p-q)
    elif hp:
      print(q,p)
      heappush(hn,q-p)
    else:
      print(p,q) hn print(p,q) print p q heappush(hp,p-q) heappush hp p-q p q elif hp:
      print(q,p)
      heappush(hn,q-p)
     hp print(q,p) print q p heappush(hn,q-p) heappush hn q-p q p print(p,q) print p q elif min(a) >= 0:
  ans = sum(a)-2*min(a)
  print(ans)
  heapify(a)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break min(a) >= 0 min(a) min a 0 ans = sum(a)-2*min(a) ans sum(a)-2*min(a) sum(a) sum a 2*min(a) 2 min(a) min a print(ans) print ans heapify(a) heapify a while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break a p = heappop(a) p heappop(a) heappop a if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break a q = heappop(a) q heappop(a) heappop a if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
     a print(p,q) print p q heappush(a,p-q) heappush a p-q p q print(q,p) print q p break elif max(a) <= 0:
  ans = -sum(a)+2*max(a)
  a = [-a[i] for i in range(n)]
  heapify(a)
  print(ans)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break max(a) <= 0 max(a) max a 0 ans = -sum(a)+2*max(a) ans -sum(a)+2*max(a) -sum(a) sum(a) sum a 2*max(a) 2 max(a) max a -a[i] for i in range(n) for i in range(n) i range(n) range n for i in range(n) -a[i] a[i] a i a = [-a[i] for i in range(n)] a [-a[i] for i in range(n)] heapify(a) heapify a print(ans) print ans while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break a p = heappop(a) p heappop(a) heappop a if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break a q = heappop(a) q heappop(a) heappop a if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
     a print(-p,-q) print -p p -q q heappush(a,p-q) heappush a p-q p q print(-p,-q) print -p p -q q break a = list(map(int,input().split())) list(map(int,input().split())) a ans += a[i] a[i] ans ans = 0 0 ans a = [-a[i] for i in range(n)] [-a[i] for i in range(n)] a p = heappop(a) heappop(a) p q = heappop(hn) heappop(hn) q ans = -sum(a)+2*max(a) -sum(a)+2*max(a) ans ans -= a[i] a[i] ans p = heappop(hp) heappop(hp) p n = int(input()) int(input()) n hn = [] [] hn ans = sum(a)-2*min(a) sum(a)-2*min(a) ans p = heappop(a) heappop(a) p q = heappop(a) heappop(a) q hp = [] [] hp q = heappop(a) heappop(a) q
from heapq import heapify,heappop,heappush
n = int(input())
a = list(map(int,input().split()))
if max(a) > 0 and min(a) < 0:
  hp = []
  hn = []
  heapify(hp)
  heapify(hn)
  ans = 0
  for i in range(n):
    if a[i] >= 0:
      heappush(hp,a[i])
      ans += a[i]
    else:
      ans -= a[i]
      heappush(hn,a[i])
  print(ans)
  while hp and hn:
    p = heappop(hp)
    q = heappop(hn)
    if hn:
      print(p,q)
      heappush(hp,p-q)
    elif hp:
      print(q,p)
      heappush(hn,q-p)
    else:
      print(p,q)
elif min(a) >= 0:
  ans = sum(a)-2*min(a)
  print(ans)
  heapify(a)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(p,q)
        heappush(a,p-q)
      else:
        print(q,p)
    else:
      break
elif max(a) <= 0:
  ans = -sum(a)+2*max(a)
  a = [-a[i] for i in range(n)]
  heapify(a)
  print(ans)
  while a:
    p = heappop(a)
    if a:
      q = heappop(a)
      if a:
        print(-p,-q)
        heappush(a,p-q)
      else:
        print(-p,-q)
    else:
      break