Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
for _ in range(n-1):
  if ap == []:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif am == []:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
for i in ans:
  print(i)

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
while len(am + ap) >1:
  if ap == []:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif am == []:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
for i in ans:
  print(i)

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
for _ in range(n-1):
  if ap == []:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif am == []:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
for i in ans:
  print(i)

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Buggy python submission (verdict: Runtime Error):
m,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
for _ in range(m-1):
  if ap == []:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif am == []:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
print("\n".join(ans))

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Buggy python submission (verdict: Runtime Error):
m,*a = map(int,open(0).read().split())
am = []
ap = []
amap = am.append
apap = ap.append
for i in a:
  if i >= 0:
    apap(i)
  else:
    amap(i)
ans = []
ansap = ans.append
for _ in range(m-1):
  if len(ap) == 0:
    x = max(am)
    y = min(am)
    am.remove(x)
    am.remove(y)
    apap(x-y)
  elif len(am) == 0:
    x = min(ap)
    y = max(ap)
    ap.remove(x)
    ap.remove(y)
    amap(x-y)
  elif len(ap) > len(am):
    x = am.pop()
    y = ap.pop()
    amap(x-y)
  else:
    x = ap.pop()
    y = am.pop()
    apap(x-y)
  ansap(" ".join((str(x),str(y))))

print(ap[0])
print("\n".join(ans))

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)