Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
for i in range(N-1):
    if A[-2] <= 0:
        al = A.pop(-1)
        ar = A.pop(-1)
        tmp = al - ar
        ans_op.append([al, ar])
        A.append(tmp)
    else:
        al = A.pop(0)
        ar = A.pop(-1)
        tmp = al - ar
        ans_op.append([al, ar])
        A.insert(0, tmp)

print(A[0])
for op in ans_op:
    print(op[0], op[1])


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(0)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
tmp = A.pop(-1)
if N >= 2:
    tmpl = A.pop(0)
else:
    tmpl = 0
    
for i in range(N-2):
    if A[-1] <= 0:
        ar = A.pop(-1)
        ans_op.append([tmp, ar])
        tmp = tmp - ar
    else:
        ans_op.append([tmpl, tmp])
        tmpl = tmpl - tmp
        tmp = A.pop(-1)
        # A.insert(0, tmp)
ans_op.append([tmp, tmpl])
print(tmp-tmpl)
for op in ans_op:
    print(op[0], op[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    tmp = A[-1] - A[-2]
    ans_op.append([A[-1], A[-2]])
    A = A[:-2]
    A.append(tmp)
elif A[0] > 0 and A[-1] > 0:
    tmp = A[0] - A[1]
    ans_op.append([A[0], A[1]])
    A = A[2:]
    A.insert(tmp, 0)
while len(A) != 1:
    if A[-2] <= 0:
        tmp = A[-1] - A[-2]
        ans_op.append([A[-1], A[-2]])
        A = A[:-2]
        A.append(tmp)
    else:
        tmp = A[0] - A[-1]
        ans_op.append([A[0], A[-1]])
        A = A[1:-1]
        A.insert(0, tmp)

print(A[0])
for op in ans_op:
    print(op[0], op[1])


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(0)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
tmp = A.pop(-1)
if N >= 2:
    tmpl = A.pop(0)
else:
    tmpl = 0
    
for i in range(N-2):
    if A[-1] <= 0:
        ar = A.pop(-1)
        ans_op.append([tmp, ar])
        tmp = tmp - ar
    else:
        ans_op.append([tmpl, tmp])
        tmpl = tmpl - tmp
        tmp = A.pop(-1)
        # A.insert(0, tmp)
ans_op.append([tmp, tmpl])
print(tmp-tmpl)
for op in ans_op:
    print(op[0], op[1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    tmp = A[-1] - A[-2]
    ans_op.append([A[-1], A[-2]])
    A = A[:-2]
    A.append(tmp)
elif A[0] > 0 and A[-1] > 0:
    tmp = A[0] - A[1]
    ans_op.append([A[0], A[1]])
    A = A[2:]
    A.insert(tmp, 0)
while len(A) != 1:
    if A[-2] <= 0:
        tmp = A[-1] - A[-2]
        ans_op.append([A[-1], A[-2]])
        A = A[:-2]
        A.append(tmp)
    else:
        tmp = A[0] - A[-1]
        ans_op.append([A[0], A[-1]])
        A = A[1:-1]
        A.insert(0, tmp)

print(A[0])
for op in ans_op:
    print(op[0], op[1])


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
max_ans = 0
ans_op = []
if A[0] < 0 and A[-1] < 0:
    al = A.pop(-1)
    ar = A.pop(-1)
    tmp = al - ar
    ans_op.append([al, ar])
    A.append(tmp)
    N -= 1
elif A[0] > 0 and A[-1] > 0:
    al = A.pop(0)
    ar = A.pop(0)
    tmp = al - ar
    ans_op.append([al, ar])
    A.insert(0, tmp)
    N -= 1
tmp = A.pop(-1)
if N >= 2:
    tmpl = A.pop(0)
else:
    tmpl = 0
    
for i in range(N-2):
    if A[-1] <= 0:
        ar = A.pop(-1)
        ans_op.append([tmp, ar])
        tmp = tmp - ar
    else:
        ans_op.append([tmpl, tmp])
        tmpl = tmpl - tmp
        tmp = A.pop(-1)
        # A.insert(0, tmp)
ans_op.append([tmp, tmpl])
print(tmp-tmpl)
for op in ans_op:
    print(op[0], op[1])