Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] >= 0:
    M = sum(A[1:])-A[0]
    print(M)
    for i in range(N-1):
        if i <= N-3:
            x = A.pop(0)
            y = A.pop(-1)
            print(x, y)
            A.insert(0, x - y)
        else:
            x = A.pop(1)
            y = A.pop(0)
            print(x, y)
elif A[-1] <= 0:
    M = sum(A[:-1]) * (-1) + A[-1]
    print(M)
    for i in range(N-1):
        if i <= N-3:
            x = A.pop(-1)
            y = A.pop(0)
            print(x, y)
            A.insert(N-i-2,x-y)
        else:
            #print(A)
            x = A.pop(1)
            y = A.pop(0)
            print(x,y)
else:
    absa = [abs(i) for i in A]
    M = sum(absa)
    print(M)
    if A[1] >= 0 :
        for i in range(N - 1):
            if i <= N - 3:
                x = A.pop(0)
                y = A.pop(-1)
                print(x, y)
                A.insert(0, x - y)
            else:
                x = A.pop(1)
                y = A.pop(0)
                print(x, y)
    else:
        for i in range(N - 1):
            if i <= N - 3 and A[1] < 0:
                x = A.pop(-1)
                y = A.pop(0)
                print(x, y)
                A.insert(N - i - 2, x - y)
            elif i <= N-3 :
                x = A.pop(0)
                y = A.pop(-1)
                print(x,y)
                A.insert(0, x - y)
            else:
                # print(A)
                x = A.pop(1)
                y = A.pop(0)
                print(x, y)




Fixed submission:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] >= 0:
    M = sum(A[1:])-A[0]
    print(M)
    for i in range(N-1):
        if i == 0:
            x = A[0]
            y = A[N-1]
            print(x, y)
        elif i <= N - 3:
            x = new
            y = A[N-1-i]
            print(x, y)
        else:
            x = A[N-1-i]
            y = new
            print(x, y)
        new = x - y
elif A[-1] <= 0:
    M = sum(A[:-1]) * (-1) + A[-1]
    print(M)
    for i in range(N-1):
        if i == 0:
            x = A[N-1]
            y = A[0]
            print(x, y)
        elif i <= N-3:
            x = new
            y = A[i]
            print(x, y)
        else:
            x = new
            y = A[i]
            print(x,y)
        new = x- y
else:
    absa = [abs(i) for i in A]
    M = sum(absa)
    print(M)
    if A[1] >= 0 :
        for i in range(N - 1):
            if i == 0:
                x = A[0]
                y = A[N - 1]
                print(x, y)
            elif i <= N - 3:
                x = new
                y = A[N - 1 - i]
                print(x, y)
            else:
                x = A[N - 1 - i]
                y = new
                print(x, y)
            new = x - y
    else:
        A = deque(A)
        for i in range(N - 1):
            if i <= N - 3 and A[1] < 0:
                x = A.pop()
                y = A.popleft()
                print(x, y)
                A.append(x-y)
            elif i <= N-3 :
                x = A.popleft()
                y = A.pop()
                print(x,y)
                A.appendleft(x-y)
            else:
                # print(A)
                x = A.pop()
                y = A.popleft()
                print(x, y)