Problem p03007 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split(' ')))
a.sort(reverse=True)

process = []
p_seed = a.pop(0)
n_seed = a.pop(-1)
for e in a:
    if e >= 0:
        process.append((n_seed, e))
        n_seed -= e
    else:
        process.append((p_seed, e))
        p_seed -= e
process.append((p_seed, n_seed))
m = p_seed - n_seed
print(m)
for x, y in process:
    print(str(x) + ' ' + str(y))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split(' ')))
a.sort(reverse=True)

process = []
p_seed = a.pop(0)
n_seed = a.pop(-1)
for e in a:
  	if e >= 0:
    	process.append((n_seed, e))
    	n_seed -= e
  	else:
    	process.append((p_seed, e))
    	p_seed -= e
process.append((p_seed, n_seed))
m = p_seed - n_seed
print(m)
for x, y in process:
    print(str(x) + ' ' + str(y))

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

p = [i for i in a if i >= 0]
n = [i for i in a if i < 0]

process = []
if len(p) > 0 and len(n) > 0:
    p_seed = p.pop(0)
    n_seed = n.pop(0)
    while len(n) > 0:
        sub = n.pop(0)
        process.append((p_seed, sub))
        p_seed -= sub
    while len(p) > 0:
        sub = p.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    m = p_seed - n_seed
    print(m)
    for x, y in process:
        print(f'{x} {y}')
else:
    target = p if len(p) > 0 else n
    target.sort(reverse=True)
    p_seed = target.pop(0)
    n_seed = target.pop(-1)
    while len(target) > 0:
        sub = target.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    m = p_seed - n_seed
    print(m)
    for x, y in process:
        print(f'{x} {y}')

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

p = [i for i in a if i >= 0]
n = [i for i in a if i < 0]

process = []
if len(p) > 0 and len(n) > 0:
    p_seed = p.pop(0)
    n_seed = n.pop(0)
    while len(n) > 0:
        sub = n.pop(0)
        process.append((p_seed, sub))
        p_seed -= sub
    while len(p) > 0:
        sub = p.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    print(p_seed - n_seed)
    for x, y in process:
        print(f'{x} {y}')
else:
    target = p if len(p) > 0 else n
    target.sort(reverse=True)
    p_seed = target.pop(0)
    n_seed = target.pop(-1)
    while len(target) > 0:
        sub = target.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    print(p_seed - n_seed)
    for x, y in process:
        print(f'{x} {y}')

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

p = [i for i in a if i >= 0]
n = [i for i in a if i < 0]

process = []
if len(p) > 0 and len(n) > 0:
    p_seed = p.pop(0)
    n_seed = n.pop(0)
    while len(n) > 0:
        sub = n.pop(0)
        process.append((p_seed, sub))
        p_seed -= sub
    while len(p) > 0:
        sub = p.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    print(p_seed - n_seed)
    for x, y in process:
        print(f'{x} {y}')
else:
    target = p if len(p) > 0 else n
    target.sort(reverse=True)
    p_seed = target.pop(0)
    n_seed = target.pop(-1)
    while len(target) > 0:
        sub = target.pop(0)
        process.append((n_seed, sub))
        n_seed -= sub
    process.append((p_seed, n_seed))
    print(p_seed - n_seed)
    for x, y in process:
        print(f'{x} {y}')