Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
L=[]
for i in range(N):
    if len(A)>=3:
        a=A.pop(0)
        b=A.pop(-1)
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.insert(0,a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.pop(0)
        b = A.pop(-1)
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')


Fixed submission:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
A=deque(A)
L=deque([])
for i in range(N):
    if len(A)>=3:
        a=A.popleft()
        b=A.pop()
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.appendleft(a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.popleft()
        b = A.pop()
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
L=[]
for i in range(N):
    if len(A)>=3:
        a=A.pop(0)
        b=A.pop(-1)
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.insert(0,a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.pop(0)
        b = A.pop(-1)
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')


Fixed submission:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
A=deque(A)
L=deque([])
for i in range(N):
    if len(A)>=3:
        a=A.popleft()
        b=A.pop()
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.appendleft(a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.popleft()
        b = A.pop()
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
L=[]
for i in range(N):
    if len(A)>=3:
        a=A.pop(0)
        b=A.pop(-1)
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            A.sort()
            L.append([b,a])
        else:
            A.append(a-b)
            A.sort()
            L.append([a,b])
    elif len(A)==2:
        a = A.pop(0)
        b = A.pop(-1)
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')


Fixed submission:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
A=deque(A)
L=deque([])
for i in range(N):
    if len(A)>=3:
        a=A.popleft()
        b=A.pop()
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.appendleft(a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.popleft()
        b = A.pop()
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')