Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()

# A[cut-1] < 0 and A[cut] >= 0
cut = 0
while A[cut] < 0:
    cut += 1

if cut == 0:
    M = sum(A[1:]) - A[0]
    print(M)
    pair = [A[0], A[1]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[i+2]]
    print(' '.join(map(str, pair)))

elif cut == N-1:
    M = A[-1] - sum(A[:N-1])
    print(M)
    pair = [A[N-1], A[0]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[i+1]]
    print(' '.join(map(str, pair)))

else:
    M = sum(A[cut:]) - sum(A[:cut])
    print(M)
    pair = [A[cut-1], A[N-1]]
    for i in range(N - cut - 2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[N-i-2]]
    print(' '.join(map(str, pair)))
    
    rem = pair[0] - pair[1]
    if cut == 1:
        pair = [A[cut], rem]
        print(' '.join(map(str, pair)))
    else:
        pair = [A[cut], A[0]]
        for i in range(cut - 2):
            print(' '.join(map(str, pair)))
            pair = [pair[0] - pair[1], A[i+1]]
        print(' '.join(map(str, pair)))
        pair = [pair[0]- pair[1], rem]
        print(' '.join(map(str, pair)))

Fixed submission:
from collections import deque

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

# A[cut-1] < 0 and A[cut] >= 0
cut = 0
while cut < N and A[cut] < 0:
    cut += 1

if cut == 0:
    M = sum(A[1:]) - A[0]
    print(M)
    pair = [A[0], A[N-1]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[N-i-2]]
    pair.reverse()
    print(' '.join(map(str, pair)))

elif cut == N:
    M = A[-1] - sum(A[:N-1])
    print(M)
    pair = [A[N-1], A[0]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[i+1]]
    print(' '.join(map(str, pair)))

else:
    M = sum(A[cut:]) - sum(A[:cut])
    print(M)

    B = deque(A[cut:]) # Aの正の部分
    C = deque(A[:cut]) # Aの負の部分

    while len(B) != 1:
        pair = [C[-1], B[-1]]
        print(' '.join(map(str, pair)))
        b = B.pop()
        C[-1] = C[-1] - b
    
    b = B.pop()

    while len(C) != 0:
        pair = [b, C[0]]
        print(' '.join(map(str, pair)))
        c = C.popleft()
        b = b - c

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input()split()))
A.sort()

if N % 2 == 0:
    A_neg = A[:N//2]
    A_pos = A[N//2:]
    M = sum(A_pos) - sum(A_neg)
    print(M)
    print(' '.join(map(str, [A[-1], A[0]])))
    num = A[-1] - A[0]
    for i in range(N-2):
        print(' '.join(map(str, [num, A[i+1]])))

if N % 2 == 1:
    A_neg = A[:N//2]
    A_pos = A[N//2:]
    M = sum(A_pos) - sum(A_neg)
    print(M)
    print(' '.join(map(str, [A[-1], A[0]])))
    num = A[-1] - A[0]
    for i in range(N-2):
        print(' '.join(map(str, [num, A[i+1]])))

Fixed submission:
from collections import deque

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

# A[cut-1] < 0 and A[cut] >= 0
cut = 0
while cut < N and A[cut] < 0:
    cut += 1

if cut == 0:
    M = sum(A[1:]) - A[0]
    print(M)
    pair = [A[0], A[N-1]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[N-i-2]]
    pair.reverse()
    print(' '.join(map(str, pair)))

elif cut == N:
    M = A[-1] - sum(A[:N-1])
    print(M)
    pair = [A[N-1], A[0]]
    for i in range(N-2):
        print(' '.join(map(str, pair)))
        pair = [pair[0] - pair[1], A[i+1]]
    print(' '.join(map(str, pair)))

else:
    M = sum(A[cut:]) - sum(A[:cut])
    print(M)

    B = deque(A[cut:]) # Aの正の部分
    C = deque(A[:cut]) # Aの負の部分

    while len(B) != 1:
        pair = [C[-1], B[-1]]
        print(' '.join(map(str, pair)))
        b = B.pop()
        C[-1] = C[-1] - b
    
    b = B.pop()

    while len(C) != 0:
        pair = [b, C[0]]
        print(' '.join(map(str, pair)))
        c = C.popleft()
        b = b - c