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

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)


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

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope.append((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)

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

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)


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

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope.append((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)

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

BB = A[:]


def dfs(BB, ope):
    if len(BB) == 1:
        return BB[0], ope
    
    ret_list = []
    for i, x in enumerate(BB):
        for j, y in enumerate(BB[i+1:]):
            ret_list.append(dfs(BB[:i]+BB[i+1:i+1+j]+BB[i+1+j+1:]+[x-y], ope[:] + [(x, y)]))
            ret_list.append(dfs(BB[:i]+BB[i+1:i+1+j]+BB[i+1+j+1:]+[y-x], ope[:] + [(y, x)]))
    return max(ret_list)

ans = dfs(BB, [])

print(ans[0])
for a in ans[1]:
    print(a[0], a[1])

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

BB = A[:]

BB_P = []
BB_M = []


for b in BB:
    if b < 0:
        BB_M.append(b)
    else:
        BB_P.append(b)

        
ope = []
if not BB_M:
    BB_P = sorted(BB_P)
    p = BB_P[-1]
    m = BB_P[0]
    for b in BB_P[1:-1]:
        ope.append((m,b))
        m = m-b
    ope.append((p,m))
    ans = p - m
elif not BB_P:
    BB_M = sorted(BB_M)
    p = BB_M[-1]
    for b in BB_M[:-1]:
        ope.append((p, b))
        p = p-b
    ans = p
else:
    p = BB_P.pop()
    m = BB_M.pop()
    for b in BB_P:
        ope.append((m ,b))
        m = m-b
    for b in BB_M:
        ope.append((p ,b))
        p = p-b
    ope.append((p,m))
    ans = p-m
    
print(ans)
for x,y in ope:
    print(x, y)