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

xy = [0]*(N-1)
idx = 0

for i in range(N-1):
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy[idx] = [x,y]

        A[0] = x-y

    else:
        x = A.pop()
        y = A.pop(0)

        xy[idx] = [x,y]

        A.append(x-y)
    
    idx += 1

print(A[0])
for x, y in xy:
    print(x,y)

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)

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

xy = [0]*N-1
idx = 0

for i in range(N-1):
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy[idx] = [x,y]

        A[0] = x-y

    else:
        x = A.pop()
        y = A.pop(0)

        xy[idx] = [x,y]

        A.append(x-y)
    
    idx += 1

print(A[0])
for x, y in xy:
    print(x,y)

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)

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

xy = []

while N >= 2:
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy.append([x,y])

        A[0] = x-y

    else:
        while N >= 2:
            x = A.pop()
            y = A.pop(0)

            xy.append([x,y])

            A.append(x-y)
            N -= 1
        break
    
    N -= 1

print(A[0])
for x, y in xy:
    print(x,y)

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)

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

xy = []

while N >= 2:
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy.append([x,y])

        A[0] = x-y

    else:
        x = A.pop()
        y = A.pop(0)

        xy.append([x,y])

        A.append(x-y)
    
    N -= 1

print(A[0])
for x, y in xy:
    print(x,y)

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)

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

xy = []

while N >= 2:
    if A[-2] > 0:
        y = A.pop()
        x = A.pop(0)

        xy.append([x,y])

        A = [x-y] + A

    else:
        x = A.pop()
        y = A.pop(0)

        xy.append([x,y])

        A.append(x-y)
    
    N -= 1

print(A[0])
for x, y in xy:
    print(x,y)

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)