Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
minus,plus = [],[]
for num in lis:
    if num >= 0:
        plus.append(num)
    elif num < 0:
        minus.append(num)
plus.sort()
minus.sort()
ans = []
if len(plus) == 0:
    now = minus.pop()
    for num in minus:
        ans.append([now,num])
        now -= num
    print(now)
elif len(minus) == 0:
    now = plus.pop()
    last_num = plus.pop()
    for num in minus:
        ans.append([now,num])
        now -= num
    ans.append([last_num,now])
    print(now)
elif len(plus) == 1:
    now = plus.pop()
    for num in minus:
        ans.append([now,num])
        now -= num
    print(now)
else:
    now = minus.pop()
    last_num = plus.pop()
    for num in plus:
        ans.append([now,num])
        now -= num
    for num in minus:
        ans.append([last_num,num])
        last_num -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
for i in range(n-1):
    print(*ans[i])

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
minus,plus = [],[]
for num in lis:
    if num >= 0:
        plus.append(num)
    elif num < 0:
        minus.append(num)
plus.sort()
minus.sort(reverse=True)
ans = []
if len(plus) == 0:
    now = minus.pop(0)
    for num in minus:
        ans.append([now,num])
        now -= num
    print(now)
elif len(minus) == 0:
    now = plus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
else:
    now = minus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    for num in minus:
        ans.append([last_num,num])
        last_num -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
for i in range(n-1):
    print(*ans[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse = True)
for i in range(n):
  if lis[i] < 0:
    lia = lis[:i]
    lib = lis[i:]
    break
  if i == n-1:
    lia = lis
    lib = []
num = 0
m = len(lia)
if m > 1:
  if m % 2 == 0:
    print(abs(sum(lia[:m//2]))-abs(sum(lia[m//2:])))-sum(lib)
    print(lia[0],lia[-1])
    num = lia[0]-lia[-1]
    for i in range(1,m//2):
      print(lia[-(i+1)],num)
      num = lia[-(i+1)]-num
      print(lia[i],num)
      num = lia[i]-num

  else:
    print(sum(lia[:m//2])-sum(lia[m//2+1:])+abs(lia[m//2]))-sum(lib)
    print(lia[-1],lia[0])
    num = lia[-1]-lia[0]
    for i in range(1,m//2):
      print(lia[i],num)
      num = lia[i]-num
      print(lia[-(i+1)],num)
      num = lia[-(i+1)]-num     
    print(lia[m//2],num)
elif m == 1:
  print(lia[0] -sum(lib))
  print(lia[0],lib[0])
  num = lia[0]-lib[0]
else:
  print(-sum(lib)+lib[0] * 2)
  num = lib[0]
for i in range(len(lib)-1):
  print(num,lib[i+1])
  num -= lib[i+1]

Fixed submission:
n = int(input())
lis = list(map(int,input().split()))
minus,plus = [],[]
for num in lis:
    if num >= 0:
        plus.append(num)
    elif num < 0:
        minus.append(num)
plus.sort()
minus.sort(reverse=True)
ans = []
if len(plus) == 0:
    now = minus.pop(0)
    for num in minus:
        ans.append([now,num])
        now -= num
    print(now)
elif len(minus) == 0:
    now = plus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
else:
    now = minus.pop(0)
    last_num = plus.pop(0)
    for num in plus:
        ans.append([now,num])
        now -= num
    for num in minus:
        ans.append([last_num,num])
        last_num -= num
    ans.append([last_num,now])
    last_num -= now
    print(last_num)
for i in range(n-1):
    print(*ans[i])