Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

A.sort()

if (A[0] <= 0 and A[n-1] > 0) or (A[0] < 0 and A[n-1] >= 0):
    print(sum(list(map(abs, A))))
    while A[-2] >= 0:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(atama, ketu)
        new = atama - ketu
        A.insert(0, new)
    while len(A) != 1:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(ketu, atama)
        new = ketu - atama
        A.append(new)
elif A[0] > 0:
    atama = A.pop(0)
    tugi = A.pop(0)
    new = atama - tugi
    A.insert(0, new)
    print(sum(list(map(abs, A))))
    print(atama, tugi)
    while len(A) != 2:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(atama, ketu)
        new = atama - ketu
        A.insert(0, new)
    atama = A.pop(0)
    ketu = A.pop(-1)
    print(ketu, atama)
else:
    ketu = A.pop(-1)
    tugi = A.pop(-1)
    new = ketu - tugi
    A.append(new)
    print(sum(list(map(abs, A))))
    print(ketu, tugi)
    while len(A) != 1:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(ketu, atama)
        new = ketu - atama
        A.append(new)

Fixed submission:
from collections import deque

n = int(input())
A = list(map(int, input().split()))

A.sort()
A_d = deque(A)

if (A_d[0] <= 0 and A_d[n-1] > 0) or (A_d[0] < 0 and A_d[n-1] >= 0):
    print(sum(list(map(abs, A_d))))
    while A_d[-2] >= 0:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)
elif A_d[0] > 0:
    atama = A_d.popleft()
    tugi = A_d.popleft()
    new = atama - tugi
    A_d.appendleft(new)
    print(sum(list(map(abs, A_d))))
    print(atama, tugi)
    while len(A_d) != 2:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    atama = A_d.popleft()
    ketu = A_d.pop()
    print(ketu, atama)
else:
    ketu = A_d.pop()
    tugi = A_d.pop()
    new = ketu - tugi
    A_d.append(new)
    print(sum(list(map(abs, A_d))))
    print(ketu, tugi)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

A.sort()

if (A[0] <= 0 and A[n-1] > 0) or (A[0] < 0 and A[n-1] >= 0):
    print(sum(list(map(abs, A))))
    while A[-2] >= 0:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(atama, ketu)
        new = atama - ketu
        A.insert(0, new)
    while len(A) != 1:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(ketu, atama)
        new = ketu - atama
        A.append(new)
elif A[0] > 0:
    atama = A.pop(0)
    tugi = A.pop(0)
    new = atama - tugi
    A.insert(0, new)
    print(sum(list(map(abs, A))))
    print(atama, tugi)
    while len(A) != 2:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(atama, ketu)
        new = atama - ketu
        A.insert(0, new)
    atama = A.pop(0)
    ketu = A.pop(-1)
    print(ketu, atama)
else:
    ketu = A.pop(-1)
    tugi = A.pop(-1)
    new = ketu - tugi
    A.append(new)
    print(sum(list(map(abs, A))))
    print(ketu, tugi)
    while len(A) != 1:
        atama = A.pop(0)
        ketu = A.pop(-1)
        print(ketu, atama)
        new = ketu - atama
        A.append(new)

Fixed submission:
from collections import deque

n = int(input())
A = list(map(int, input().split()))

A.sort()
A_d = deque(A)

if (A_d[0] <= 0 and A_d[n-1] > 0) or (A_d[0] < 0 and A_d[n-1] >= 0):
    print(sum(list(map(abs, A_d))))
    while A_d[-2] >= 0:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)
elif A_d[0] > 0:
    atama = A_d.popleft()
    tugi = A_d.popleft()
    new = atama - tugi
    A_d.appendleft(new)
    print(sum(list(map(abs, A_d))))
    print(atama, tugi)
    while len(A_d) != 2:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(atama, ketu)
        new = atama - ketu
        A_d.appendleft(new)
    atama = A_d.popleft()
    ketu = A_d.pop()
    print(ketu, atama)
else:
    ketu = A_d.pop()
    tugi = A_d.pop()
    new = ketu - tugi
    A_d.append(new)
    print(sum(list(map(abs, A_d))))
    print(ketu, tugi)
    while len(A_d) != 1:
        atama = A_d.popleft()
        ketu = A_d.pop()
        print(ketu, atama)
        new = ketu - atama
        A_d.append(new)