Buggy python submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
x = [0]*(N-1)
y = [0]*(N-1)
start_bool = 1 if N % 2 == 0 else -1
for i in range(N-1):
    print(A)
    l = A.pop(0)
    r = A.pop(-1)
    if start_bool < 0:
        if l > r:
            ret = r - l
            x[i] = r
            y[i] = l
        else:
            ret = l - r
            x[i] = l
            y[i] = r
    else:
        if l > r:
            ret = l - r
            x[i] = l
            y[i] = r
        else:
            ret = r - l
            x[i] = r
            y[i] = l
    if ret > 0:
        bisect.insort(A, ret)
    else:
        bisect.insort(A, ret)
    start_bool *= -1
print(A[0])
for i in range(N-1):
    print(x[i], y[i])

Fixed submission:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
plus = 0
minus = 0
for i in range(N):
    if A[i] >= 0:
        plus += 1
    else:
        minus += 1
bb = deque(sorted(A))
x = [0]*(N-1)
y = [0]*(N-1)
for i in range(N-1):
    if len(bb) == 2:
        l = bb.popleft()
        r = bb.pop()
        if l > r:
            ret = l-r
            x[i] = l
            y[i] = r
        else:
            ret = r - l
            x[i] = r
            y[i] = l
    else:
        l = bb.popleft()
        r = bb.pop()

        if plus > minus:
            ret = l - r
            x[i] = l
            y[i] = r
            plus -= 1
        else:
            ret = r - l
            x[i] = r
            y[i] = l
            minus -= 1
    if ret > 0:
        bb.append(ret)
    else:
        bb.appendleft(ret)
print(bb.pop())
for i in range(N-1):
    print(x[i], y[i])

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = list(map(int, input().split()))
bb = deque(sorted(A))
x = [0]*(N-1)
y = [0]*(N-1)
start_bool = 1 if N % 2 == 0 else -1
for i in range(N-1):
    print(bb)
    l = bb.popleft()
    r = bb.pop()
    if start_bool < 0:
        if l > r:
            ret = r - l
            x[i] = r
            y[i] = l
        else:
            ret = l - r
            x[i] = l
            y[i] = r
    else:
        if l > r:
            ret = l - r
            x[i] = l
            y[i] = r
        else:
            ret = r - l
            x[i] = r
            y[i] = l
    if ret > 0:
        bb.append(ret)
    else:
        bb.appendleft(ret)
    start_bool *= -1
print(bb.pop())
for i in range(N-1):
    print(x[i], y[i])

Fixed submission:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
plus = 0
minus = 0
for i in range(N):
    if A[i] >= 0:
        plus += 1
    else:
        minus += 1
bb = deque(sorted(A))
x = [0]*(N-1)
y = [0]*(N-1)
for i in range(N-1):
    if len(bb) == 2:
        l = bb.popleft()
        r = bb.pop()
        if l > r:
            ret = l-r
            x[i] = l
            y[i] = r
        else:
            ret = r - l
            x[i] = r
            y[i] = l
    else:
        l = bb.popleft()
        r = bb.pop()

        if plus > minus:
            ret = l - r
            x[i] = l
            y[i] = r
            plus -= 1
        else:
            ret = r - l
            x[i] = r
            y[i] = l
            minus -= 1
    if ret > 0:
        bb.append(ret)
    else:
        bb.appendleft(ret)
print(bb.pop())
for i in range(N-1):
    print(x[i], y[i])