ZhenlongDai/ACPR huggingface dataset:
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ps = []
mis = []
for _ in input().split():
  item = int(_)
  if item >= 0:
    ps.append(item)
  else:
    mis.append(item)
  
mis.sort(reverse = True)
ps.sort()
if len(mis) == 0:
  mis = [ps[0]]
  ps = ps[1:]
if len(ps) == 0:
  ps = [mis[0]]
  mis = mis[1:]
print(sum(ps) - sum(mis))

pre = mis[0]
for p in ps[:len(ps) - 1]:
  print(pre, p)
  pre -= p
print(ps[-1], pre)
pre -= ps[-1]
for m in mis[1:]:
  print(pre, m)
  pre -= m




Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
3 -1
-4 -2


Fixed submission (verdict: Accepted):
n = int(input())
ps = []
mis = []
for _ in input().split():
  item = int(_)
  if item >= 0:
    ps.append(item)
  else:
    mis.append(item)
  
mis.sort(reverse = True)
ps.sort()
if len(mis) == 0:
  mis = [ps[0]]
  ps = ps[1:]
if len(ps) == 0:
  ps = [mis[0]]
  mis = mis[1:]
print(sum(ps) - sum(mis))

pre = mis[0]
for p in ps[:len(ps) - 1]:
  print(pre, p)
  pre -= p
print(ps[-1], pre)
pre = ps[-1] - pre
for m in mis[1:]:
  print(pre, m)
  pre -= m

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

A.sort()
xy=[]
l=0
r=N-1
for i in range(N-1):
    if (N-1-i)&1:
        
        x=A[l+1]
        y=A[l]
        A[l+1]-=y
        l+=1
    else:
        
        x=A[l]
        y=A[r]
        A[l]-=y
        r-=1
    xy.append((x,y))

print(A[r])
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Failing test case input:
3
1 -2 11

Expected output:
14
-2 1
11 -3


Actual output:
14
-2 11
1 -13


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

A.sort()
xy=[]
for i in range(N-2,0,-1):
    y=A[i]
    if y>0:
        x=A[0]
        A[0]-=y
    else:
        x=A[N-1]
        A[N-1]-=y
    xy.append((x,y))

print(A[N-1]-A[0])
xy.append((A[N-1],A[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=sorted(map(int,input().split()))
m,M=A[0],A[-1]
L=[]

for i in range(1,N-1):
    v=A[i]
    if v>=0:
        L.append((m,v))
        m-=v
    else:
        L.append((M,v))
        M+=v
L.append((M,m))
ans=M-m

print(ans)
for a,b in L:
    print(a,b)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
3 -1
2 -2


Fixed submission (verdict: Accepted):
N=int(input())
A=sorted(map(int,input().split()))
m,M=A[0],A[-1]
L=[]

for i in range(1,N-1):
    v=A[i]
    if v>=0:
        L.append((m,v))
        m-=v
    else:
        L.append((M,v))
        M-=v
L.append((M,m))
ans=M-m

print(ans)
for a,b in L:
    print(a,b)
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def c_successive_subtraction(N, A):
    a = sorted(A, reverse=True)

    operation = []
    while len(a) > 2:
        x = a.pop()
        y = a.pop()
        a.append(x - y)
        operation.append('{} {}'.format(x, y))
    operation.append('{} {}'.format(a[0], a[1]))
    return str(a[0] - a[1]) + '\n' + '\n'.join(operation)

N = int(input())
A = [int(i) for i in input().split()]
print(c_successive_subtraction(N, A))

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
def c_successive_subtraction(N, A):
    A.sort()
    maximum = A.pop()
    minimum = A.pop(0)

    
    
    
    
    
    operation = []
    for a in A:
        if a >= 0:
            operation.append('{} {}'.format(minimum, a))
            minimum -= a
        else:
            operation.append('{} {}'.format(maximum, a))
            maximum -= a
    operation.append('{} {}'.format(maximum, minimum))
    return str(maximum - minimum) + '\n' + '\n'.join(operation)

N = int(input())
A = [int(i) for i in input().split()]
print(c_successive_subtraction(N, A))

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(s) for s in input().split(' ')]
A.sort()
print(sum([abs(a) for a in A[1:]]) - A[0])
answer = ''
for i in range(1, len(A) - 1):
    answer += "{} {}\n".format(A[0], A[i])
    A[0] -= A[i]
answer += "{} {}\n".format(A[N - 1], A[0])
print(answer)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
-2 -1
3 -1



Fixed submission (verdict: Accepted):
N = int(input())
A = [int(s) for s in input().split(' ')]
A.sort()
print(A[N - 1] + sum([abs(a) for a in A[1:N - 1]]) - A[0])
answer = ''
for i in range(1, len(A) - 1):
    if(A[i] > 0):
        answer += "{} {}\n".format(A[0], A[i])
        A[0] -= A[i]
    else:
        answer += "{} {}\n".format(A[N - 1], A[i])
        A[N - 1] -= A[i]
answer += "{} {}\n".format(A[N - 1], A[0])
print(answer)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
import heapq
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = bisect.bisect_left(A, 0)
j = bisect.bisect_right(A, 0)
now = A[0]
ans = []
for a in A[j:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[-1], now]]
now = A[-1] - now
for a in A[1:i]:
    ans += [[now, a]]
    now -= a
print(now)
for xy in ans:
    print(*xy)


Failing test case input:
3
8 3 1

Expected output:
10
1 3
8 -2


Actual output:
11
1 1
0 3
8 -3


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = bisect.bisect_left(A, 0)
if i == N:
    i -= 2
elif i:
    i -= 1
now = A[i]
ans = []
for a in A[i + 1:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[N - 1], now]]
now = A[N - 1] - now
for a in A[:i]:
    ans += [[now, a]]
    now -= a
print(now)
[print(*xy) for xy in ans]
Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort()
lst2 = []
l,r = lst1[0],lst1[-1]
for i in range(1,n-1):
    mid = lst1[i]
    if mid < 0:
        lst2.append([r,mid])
        r -= mid
    else:
        lst2.append([l,mid])
        l -= mid
lst2.append([l,r])
print(abs(r-l))
for i in lst2:
    print(*i)

Failing test case input:
3
2 0 2

Expected output:
4
0 2
2 -2


Actual output:
4
0 2
-2 2


Fixed submission (verdict: Accepted):

import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort()
lst2 = []
l,r = lst1[0],lst1[-1]
for i in range(1,n-1):
    mid = lst1[i]
    if mid < 0:
        lst2.append([r,mid])
        r -= mid
    else:
        lst2.append([l,mid])
        l -= mid
lst2.append([r,l])
print(r-l)
for i in lst2:
    print(*i)

Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())						
A = sorted(list( map(int, input().split()) ))	

ans=0
ANS=[]

for i in range(N-1):
	x=A[i]
	y=A[i+1]
	if i==N-2:
		x,y=y,x
		ans = x-y
	else:
		A[i+1]=x-y

	ANS.append((x,y))


print(ans)
for a in ANS:
	print(*a)


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


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

ANS=[]

a=A[0]
z=A[-1]

s=0
t=0

for i in A[1:-1]:
	if i>=0:
		ANS.append((a,i))
		a = a-i
	else:
		ANS.append((z,i))
		z = z-i


ANS.append((z,a))

print(z-a)
for a in ANS:
	print(*a)

Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort()
lst2 = []
l,r = lst1[0],lst1[-1]
for i in range(1,n-1):
    mid = lst1[i]
    if mid < 0:
        lst2.append([r,mid])
        r -= mid
    else:
        lst2.append([l,mid])
        l -= mid
lst2.append([l,r])
print(r-l)
for i in lst2:
    print(*i)

Failing test case input:
3
3 -4 12

Expected output:
19
-4 3
12 -7


Actual output:
19
-4 3
-7 12


Fixed submission (verdict: Accepted):

import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))

lst1.sort()
lst2 = []
l,r = lst1[0],lst1[-1]
for i in range(1,n-1):
    mid = lst1[i]
    if mid < 0:
        lst2.append([r,mid])
        r -= mid
    else:
        lst2.append([l,mid])
        l -= mid
lst2.append([r,l])
print(r-l)
for i in lst2:
    print(*i)
Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)


if A[-1] > 0 :
    a = A.pop()
    b = A.pop()
    print(a, b)
    A.append(a - b)

elif A[0] < 0 :
    a = A.pop(0)
    b = A.pop()
    print(a, b)
    A = [a-b] + A
    
i = 1
while A[i] > 0 :
    a = A.pop()
    print(a, A[i])
    A.append(a-A[i])
    i += 1
    
print(A[0], A[-1])
print(A[0]-A[-1])
    

Failing test case input:
3
14 1 4

Expected output:
17
1 4
14 -3


Actual output:
1 4
14 -3
17


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)

log = []


if A[-1] > 0 :
    a = A.pop()
    b = A.pop()
    log.append([a, b])
    A.append(a - b)

elif A[0] < 0 :
    a = A.pop(0)
    b = A.pop()
    log.append([a, b])
    A = [a-b] + A
    
i = 1
while A[i] > 0 :
    a = A.pop()
    log.append([a, A[i]])
    A.append(a-A[i])
    i += 1
    
while i < len(A) :
    log.append([A[0], A[i]])
    A[0] -= A[i]
    i += 1
    
print(A[0])
for l in log :
    print(l[0], l[1])

Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())

a = list(map(int,input().split()))

a.sort()

query = []

high = a[-1]

low = a[0]

for i in range(1,n-1):
    if a[i] > 0:
        query.append([low, a[i]])
        low -= a[i]
    else:
        query.append([high, a[i]])
        high += a[i]

query.append([high, low])

print(high-low)

for x,y in query:
    print(x,y)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
3 -1
2 -2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))

ans = []
a.sort()
low = a[0]
high = a[-1]
for i in a[1:-1]:
    if i>0:
        ans.append([low,i])
        low = low - i
    else:
        ans.append([high,i])
        high = high - i

ans.append([high,low])
print(high-low)
for x,y in ans:
    print('{0} {1}'.format(x,y))

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
import heapq
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = min(N - 1, bisect.bisect_left(A, 0))
j = max(1, bisect.bisect_right(A, 0))
now = A[0]
ans = []
for a in A[j:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[-1], now]]
now = A[-1] - now
for a in A[1:i]:
    ans += [[now, a]]
    now -= a
print(now)
for xy in ans:
    print(*xy)
for _ in range(N - 1 - len(xy)):
    print(now, 0)


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
3 -2
5 -1


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = bisect.bisect_left(A, 0)
if i == N:
    i -= 2
elif i:
    i -= 1
now = A[i]
ans = []
for a in A[i + 1:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[N - 1], now]]
now = A[N - 1] - now
for a in A[:i]:
    ans += [[now, a]]
    now -= a
print(now)
[print(*xy) for xy in ans]
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = input().split()
for i in range(len(a)):
    a[i]=int(a[i])

a.sort()


hashi1 = a[0]
hashi2 = a[-1]
a.remove(a[0])
a.remove(a[-1])

minus_list = []
plus_list = []
for i in range(len(a)):
    if a[i]>0:
        plus_list.append(a[i])
    else:
        minus_list.append(a[i])


for j in range(len(minus_list)):
    hashi2 = hashi2-minus_list[j]
for l in range(len(plus_list)):
    hashi1 = hashi1 - plus_list[l]

print(hashi2-hashi1)


Failing test case input:
3
1 -2 4

Expected output:
7
-2 1
4 -3


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
a = input().split()
for i in range(len(a)):
    a[i]=int(a[i])

a.sort()


hashi1 = a[0]
hashi2 = a[-1]
a.remove(a[0])
a.remove(a[-1])

minus_list = []
plus_list = []
printlist = []
for i in range(len(a)):
    if a[i]>0:
        plus_list.append(a[i])
    else:
        minus_list.append(a[i])


for j in range(len(minus_list)):
    printlist.append(hashi2)
    printlist.append(minus_list[j])
    hashi2 = hashi2-minus_list[j]
    
for l in range(len(plus_list)):
    printlist.append(hashi1)
    printlist.append(plus_list[l])
    hashi1 = hashi1 - plus_list[l]
    
printlist.append(hashi2)
printlist.append(hashi1)
print(hashi2-hashi1)

for n in range(0,len(printlist),2):
    print(printlist[n],printlist[n+1])

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

def solve():
  n = int(input())
  a = collections.deque(sorted(list(int(i) for i in input().split())))
  big = a.pop()
  mini = a.popleft()
  queue = collections.deque([])
  
  while (a):
    if a[0] <= 0:
      tmp = a.popleft()
      queue.append((big,tmp))
      big -= tmp
    else:
      tmp = a.pop()
      queue.append((tmp,mini))
      mini -= tmp
  print(big-mini)
  queue.append((big,mini))
  for i in range(len(queue)):
    print(*queue[i])
  
solve()


Failing test case input:
3
4 3 0

Expected output:
7
0 3
4 -3


Actual output:
7
3 0
4 -3


Fixed submission (verdict: Accepted):
import collections

def solve():
  n = int(input())
  a = collections.deque(sorted(list(int(i) for i in input().split())))
  big = a.pop()
  mini = a.popleft()
  queue = collections.deque([])
  
  while (a):
    if a[0] <= 0:
      tmp = a.popleft()
      queue.append((big,tmp))
      big -= tmp
    else:
      tmp = a.pop()
      queue.append((mini,tmp))
      mini -= tmp
  print(big-mini)
  queue.append((big,mini))
  for i in range(len(queue)):
    print(*queue[i])
  
solve()
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from collections import deque

n = int(input())
lis = list(map(int,input().split()))
lis.sort()
lis = deque(lis)
x = 0

ans_lis = []
while len(lis) != 1:
    mi = lis.popleft()
    ma = lis.pop()
    lis.append(mi - ma)
    ans_lis.append([mi,ma,mi-ma])
    x += 1
print(lis[0])
for x in ans_lis:
    print(x[0],x[1])




Failing test case input:
3
2 -2 10

Expected output:
14
-2 2
10 -4


Actual output:
14
-2 10
2 -12


Fixed submission (verdict: Accepted):

n = int(input())
lis = list(map(int,input().split()))
lis.sort()
m = lis[0]
M = lis[-1]
ans_lis = []

for now in lis[1:-1]:
    if now > 0:
        ans_lis.append([m,now])
        m -= now
    else:
        ans_lis.append([M,now])
        M -= now
ans_lis.append([M,m])
print(M-m)
for x in ans_lis:
    print(x[0],x[1])

Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)
ans = [[]] * (n - 1)
for i in range(1, n):
    mi = a.popleft()
    ma = a.pop()
    if (n - i) % 2 == 0:
        ans[i - 1] = [mi, ma]
        a.appendleft(mi - ma)
    else:
        ans[i - 1] = [ma, mi]
        a.append(ma - mi)
print(a.pop())
for x, y in ans:
    print(x, y)

Failing test case input:
3
5 0 2

Expected output:
7
0 2
5 -2


Actual output:
7
0 5
2 -5


Fixed submission (verdict: Accepted):
n = int(input())
s = n % 2
a = list(map(int, input().split()))
a.sort()
mi = a[0]
ma = a[n - 1]
l = []
for i in range(1, n - 1):
    if a[i] < 0:
        l.append((ma, a[i]))
        ma -= a[i]
    else:
        l.append((mi, a[i]))
        mi -= a[i]
l.append((ma, mi))
print(ma - mi)
for x, y in l:
    print(x, y)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)

left = a.popleft()
right = a.pop()

ans = []
for i in a:
    if i > 0:
        ans.append((left, i))
        left -= i
    else:
        ans.append((right, i))
        right -= i
else:
    ans.append((right, left))

for x, y in ans:
    print(x, y)


Failing test case input:
3
2 2 -2

Expected output:
6
-2 2
2 -4


Actual output:
-2 2
2 -4


Fixed submission (verdict: Accepted):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = deque(a)

left = a.popleft()
right = a.pop()

ans = []
for i in a:
    if i > 0:
        ans.append((left, i))
        left -= i
    else:
        ans.append((right, i))
        right -= i
else:
    ans.append((right, left))

print(right-left)
for x, y in ans:
    print(x, y)
Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

A.sort()

amax = A.pop(-1)
amin = A.pop(0)
neg = [a for a in A if a < 0]
pos = [a for a in A if a >= 0]

log = []

m = amin
for a in pos:
    log.append((m, a))
    m = m - a

M = amax
for a in neg:
    log.append((m, a))
    M = M - a

log.append((M, m))
ans = M - m

print(ans)
for l, r in log:
    print('{} {}'.format(l, r))
    

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
-2 -1
4 -2


Fixed submission (verdict: Accepted):
import sys

readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

A.sort()

amax = A.pop(-1)
amin = A.pop(0)
neg = [a for a in A if a < 0]
pos = [a for a in A if a >= 0]

log = []

m = amin
for a in pos:
    log.append((m, a))
    m = m - a

M = amax
for a in neg:
    log.append((M, a))
    M = M - a

log.append((M, m))
ans = M - m

print(ans)
for l, r in log:
    print('{} {}'.format(l, r))

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(s) for s in input().split(' ')]
A.sort()
print(sum(A[1:]) - A[0])
answer = ''
for i in range(1, len(A) - 1):
    answer += "{} {}\n".format(A[0], A[i])
    A[0] -= A[i]
answer += "{} {}\n".format(A[N - 1], A[0])
print(answer)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1



Fixed submission (verdict: Accepted):
N = int(input())
A = [int(s) for s in input().split(' ')]
A.sort()
print(A[N - 1] + sum([abs(a) for a in A[1:N - 1]]) - A[0])
answer = ''
for i in range(1, len(A) - 1):
    if(A[i] > 0):
        answer += "{} {}\n".format(A[0], A[i])
        A[0] -= A[i]
    else:
        answer += "{} {}\n".format(A[N - 1], A[i])
        A[N - 1] -= A[i]
answer += "{} {}\n".format(A[N - 1], A[0])
print(answer)

Problem: p03007
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
q=collections.deque(A)
process = []
for i in range(N-2):
    maxA = q.pop()
    minA = q.popleft()
    tmp = minA-maxA
    q.appendleft(tmp)
    process.append(list(q))
maxA = q.pop()
minA = q.popleft()
print(maxA-minA)
for pro in process:
    print(*pro)


Failing test case input:
3
3 -4 12

Expected output:
19
-4 3
12 -7


Actual output:
19
-16 3


Fixed submission (verdict: Accepted):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
process = []
for i in range(N-2):
    tmp = A.pop()
    y=A.pop()
    A.append(tmp)
    if y>=0:
        process.append([A[0],y])
        A[0]-=y
    else:
        process.append([A[-1],y])
        A[-1]-=y
process.append([A[-1],A[0]])
print(A[-1]-A[0])
for pro in process:
    print(*pro)
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)

Ans = []
temp = A[-1]
for a in A[1:-1]:
    Ans.append([temp,a])
    temp -= a
ans = [A[0],temp]
Ans.append(ans)
print(ans[0] - ans[1])
for answ in Ans:
    print(*answ, sep = " ")

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


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

A.sort(reverse = True)

Ans = []
for a in A[1:-1]:
    if a >= 0:
        Ans.append([A[-1],a])
        A[-1] -= a
    else:
        Ans.append([A[0],a])
        A[0] -= a
ans = [A[0],A[-1]]
Ans.append(ans)
print(ans[0] - ans[1])
for answ in Ans:
    print(*answ, sep = " ")

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from collections import deque

n = int(input())
lis = list(map(int,input().split()))
x = 0
ans_lis = []
while len(lis) != 1:
    lis = list(lis)
    lis.sort()
    lis = deque(lis)
    mi = lis.popleft()
    ma = lis.pop()
    lis.append(mi - ma)
    ans_lis.append([mi,ma])
    x += 1
print(abs(lis[0]))
for x in ans_lis:
    print(x[1],x[0])

Failing test case input:
3
4 -4 26

Expected output:
34
-4 4
26 -8


Actual output:
34
26 -4
4 -30


Fixed submission (verdict: Accepted):

n = int(input())
lis = list(map(int,input().split()))
lis.sort()
m = lis[0]
M = lis[-1]
ans_lis = []

for now in lis[1:-1]:
    if now > 0:
        ans_lis.append([m,now])
        m -= now
    else:
        ans_lis.append([M,now])
        M -= now
ans_lis.append([M,m])
print(M-m)
for x in ans_lis:
    print(x[0],x[1])

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
import heapq
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = min(N - 1, bisect.bisect_left(A, 0))
j = max(1, bisect.bisect_right(A, 0))
now = A[0]
ans = []
for a in A[j:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[-1], now]]
now = A[-1] - now
for a in A[1:i]:
    ans += [[now, a]]
    now -= a
print(now)
for xy in ans:
    print(*xy)


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
3 -2
5 -1


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
A = sorted([int(_) for _ in input().split()])
i = bisect.bisect_left(A, 0)
if i == N:
    i -= 2
elif i:
    i -= 1
now = A[i]
ans = []
for a in A[i + 1:N - 1]:
    ans += [[now, a]]
    now -= a
ans += [[A[N - 1], now]]
now = A[N - 1] - now
for a in A[:i]:
    ans += [[now, a]]
    now -= a
print(now)
[print(*xy) for xy in ans]
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

A.sort()
xy=[]
l=0
r=N-1
for i in range(N-1):
    if (N-1-i)&1:
        
        x=A[r]
        y=A[l]
        A[l+1]-=y
        l+=1
    else:
        
        x=A[l]
        y=A[r]
        A[l]-=y
        r-=1
    xy.append((x,y))

print(A[r])
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Failing test case input:
3
8 -4 10

Expected output:
22
-4 8
10 -12


Actual output:
22
-4 10
8 -14


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

A.sort()
xy=[]
for i in range(N-2,0,-1):
    y=A[i]
    if y>0:
        x=A[0]
        A[0]-=y
    else:
        x=A[N-1]
        A[N-1]-=y
    xy.append((x,y))

print(A[N-1]-A[0])
xy.append((A[N-1],A[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

from collections import deque

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

positives = deque(sorted(a))
negatives = deque([positives.popleft()])
for i in range(n - 2):
    if a[i] < 0:
        negatives.append(positives.popleft())
    else:
        break


print(sum(positives) - sum(negatives))

while len(positives) > 1:
    y = positives.popleft()
    x = negatives.pop()
    print(x, y)
    negatives.append(x - y)

x = positives.popleft()

while len(negatives) > 0:
    y = negatives.pop()
    print(x, y)
    x = x - y

Failing test case input:
3
-1 2 4

Expected output:
7
-1 2
4 -3


Actual output:
3
4 2
2 -1


Fixed submission (verdict: Accepted):

from collections import deque

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

positives = deque(sorted(a))
negatives = deque([positives.popleft()])
while len(positives) > 1:
    if positives[0] < 0:
        negatives.append(positives.popleft())
    else:
        break


print(sum(positives) - sum(negatives))

while len(positives) > 1:
    y = positives.popleft()
    x = negatives.pop()
    print(x, y)
    negatives.append(x - y)

x = positives.popleft()

while len(negatives) > 0:
    y = negatives.pop()
    print(x, y)
    x = x - y

Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

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





ans = []
low = A[0]
high = A[-1]

for a in A[1:-1]:
    if a > 0:
        ans.append((low, a))
        low = low - a
    else:
        ans.append((a, high))
        high = high - a

ans.append((high, low))

print(high - low)
for (x, y) in ans:
    print(x, y)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
-1 3
4 -2


Fixed submission (verdict: Accepted):




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

ans = []
low = A[0]
high = A[-1]

for a in A[1:-1]:
    if a > 0:
        ans.append((low, a))
        low = low - a
    else:
        ans.append((high, a))
        high = high - a

ans.append((high, low))

print(high - low)
for (x, y) in ans:
    print(x, y)
Problem: p03007
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
process = []

maxA = A.pop(A.index(max(A)))
minA = A.pop(A.index(min(A)))
A.append(minA-maxA)
process.append([minA,maxA])

for i in range(len(A)-2):
    maxA = A.pop(A.index(max(A)))
    process.append([maxA,A[-1]])
    A[-1]-=maxA
process.append([A[-1],A[0]])   
print(A[0]-A[-1])
for pro in process:
    print(*pro)


Failing test case input:
3
16 1 4

Expected output:
19
1 4
16 -3


Actual output:
19
1 16
-15 4


Fixed submission (verdict: Accepted):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
process = []
for i in range(N-2):
    tmp = A.pop()
    y=A.pop()
    A.append(tmp)
    if y>=0:
        process.append([A[0],y])
        A[0]-=y
    else:
        process.append([A[-1],y])
        A[-1]-=y
process.append([A[-1],A[0]])
print(A[-1]-A[0])
for pro in process:
    print(*pro)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,*a = map(int,open(0).read().split())
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((i,ap))
    ap += i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-1 3
2 -2


Fixed submission (verdict: Accepted):
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
As = list(map(int, input().split()))

ans_list = list()

v_min = min(As)
ans = max(As)
for i in range(n - 2):
    ans_list.append((v_min, As[i]))
    v_min = v_min - As[i]
ans_list.append((ans, v_min))
ans = ans - v_min

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

Failing test case input:
3
14 1 1

Expected output:
14
1 1
14 0


Actual output:
27
1 14
14 -13


Fixed submission (verdict: Accepted):
n = int(input())
As = list(map(int, input().split()))

ans_list = list()

v_min = min(As)
v_max = max(As)
As.remove(v_max)
As.remove(v_min)
for a in As:
    if a >= 0:
        ans_list.append((v_min, a))
        v_min = v_min - a
    else:
        ans_list.append((v_max, a))
        v_max = v_max - a

ans_list.append((v_max, v_min))
ans = v_max - v_min

print(ans)
for a in ans_list:
    print(a[0], a[1])
Problem: p03007
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
x, y = a[0], a[-1]
l = []
for i in a[1:-1]:
    if i < 0:
        l.append([y, i])
        y -= i
    else:
        l.append([x, i])
        x -= i
print(y - x)
for i in l:
    print(*i)
print(y, x)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
2
-1 3
-2 -4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a.sort()
x, y = a[0], a[-1]
w, z = a[0], a[-1]
for i in a[1:-1]:
    if i < 0:
        y -= i
    else:
        x -= i
print(y - x)
for i in a[1:-1]:
    if i < 0:
        print(z, i)
        z -= i
    else:
        print(w, i)
        w -= i
print(z, w)

Problem: p03007
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    s = a[0]
    ans = []
    for i in range(1,n-1):
        ans.append([s,a[i]])
        s -= a[i]
    ans.append([a[-1],s])
    print(a[-1]-s)
    for an in ans:
        print(an[0],an[1])

if __name__ == "__main__":
    main()


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())))
    ans = []
    for i in range(1,n-1):
        if a[i]>0:
            ans.append([a[0],a[i]])
            a[0] -= a[i]
        else:
            ans.append([a[-1],a[i]])
            a[-1] -= a[i]
    ans.append([a[-1],a[0]])
    print(a[-1]-a[0])
    for x,y in ans:
        print(x,y)

if __name__ == "__main__":
    main()

Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = sorted(map(int, input().split()))

plus, minus = a[0], a[-1]
for ai in a[1:-1]:
    if ai < 0:
        print(minus, ai)
        minus -= ai
    elif ai >= 0:
        print(plus, ai)
        plus -= ai
else:
    print(minus, plus)


Failing test case input:
3
4 -1 26

Expected output:
31
-1 4
26 -5


Actual output:
-1 4
26 -5


Fixed submission (verdict: Accepted):
n = int(input())
a = sorted(map(int, input().split()))

plus, minus = a[0], a[-1]
ans = []
for ai in a[1:-1]:
    if ai < 0:
        ans.append((minus, ai))
        minus -= ai
    elif ai >= 0:
        ans.append((plus, ai))
        plus -= ai
else:
    ans.append((minus, plus))

print(minus - plus)
for x, y in ans:
    print(x, y)
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N = int(input())
A = sorted(list(map(int,input().split())))

mn = A[0]
mx = A[-1]
if N ==2:
    print(A[1] - A[0])
    print(A[1],A[0])
    sys.exit()
ope = []
for a in A[1:-1]:
    if a <=0:
        ope.append([mx, a])
        mx -= a
    else:
        ope.append([a, mn])
        mn -= a
ope.append([mx,mn])
print(mx-mn)
for o in ope:
    print(o[0],o[1])

Failing test case input:
3
1 -3 1

Expected output:
5
-3 1
1 -4


Actual output:
5
1 -3
1 -4


Fixed submission (verdict: Accepted):
import sys
N = int(input())
A = sorted(list(map(int,input().split())))

mn = A[0]
mx = A[-1]
if N ==2:
    print(A[1] - A[0])
    print(A[1],A[0])
    sys.exit()
ope = []
for a in A[1:-1]:
    if a <=0:
        ope.append([mx, a])
        mx -= a
    else:
        ope.append([mn, a])
        mn -= a
ope.append([mx,mn])
print(mx-mn)
for o in ope:
    print(o[0],o[1])

Problem: p03007
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
q=collections.deque(A)
process = []
for i in range(N-2):
    maxA = q.pop()
    minA = q.popleft()
    tmp = minA-maxA
    q.insert(bisect.bisect_left(A,tmp),tmp)
    process.append(list(q))
maxA = q.pop()
minA = q.popleft()
print(maxA-minA)
for pro in process:
    print(*pro)


Failing test case input:
3
1 -4 8

Expected output:
13
-4 1
8 -5


Actual output:
13
-12 1


Fixed submission (verdict: Accepted):
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

N=int(input())
A=sorted(list(map(int,input().split())))
process = []
for i in range(N-2):
    tmp = A.pop()
    y=A.pop()
    A.append(tmp)
    if y>=0:
        process.append([A[0],y])
        A[0]-=y
    else:
        process.append([A[-1],y])
        A[-1]-=y
process.append([A[-1],A[0]])
print(A[-1]-A[0])
for pro in process:
    print(*pro)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

A.sort()
xy=[]
l=0
r=N-1
for i in range(N-1):
    if (N-1-i)&1:
        
        x=A[r]
        y=A[l]
        A[r]-=y
        l+=1
    else:
        
        x=A[l]
        y=A[r]
        A[l]-=y
        r-=1
    xy.append((x,y))

print(A[r])
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Failing test case input:
3
1 -4 8

Expected output:
13
-4 1
8 -5


Actual output:
13
-4 8
1 -12


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

A.sort()
xy=[]
for i in range(N-2,0,-1):
    y=A[i]
    if y>0:
        x=A[0]
        A[0]-=y
    else:
        x=A[N-1]
        A[N-1]-=y
    xy.append((x,y))

print(A[N-1]-A[0])
xy.append((A[N-1],A[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,*A=map(int, open(0).read().split())
A.sort()
m,M=A[0],A[-1]
B=A[1:-1]
for b in B:
    if b>=0:
        print(m,b)
        m-=b
    else:
        print(M,b)
        M-=b
print(M,m)

Failing test case input:
3
16 1 4

Expected output:
19
1 4
16 -3


Actual output:
1 4
16 -3


Fixed submission (verdict: Accepted):
N,*A=map(int, open(0).read().split())
A.sort()
m,M=A[0],A[-1]
B=A[1:-1]
ans=[]
for b in B:
    if b>=0:
        ans.append((m,b))
        m-=b
    else:
        ans.append((M,b))
        M-=b
ans.append((M,m))
print(M-m)
for x,y in ans:
    print(x,y)

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
li=list(map(int,input().split()))

li.sort()
result=[]
for i in range(len(li)-1):
  result.append([li.pop(0),li.pop(len(li)-2)])
  a=result[i][0]-result[i][1]
  li.insert(0,a)
  
print(-li[0])
a=result[len(result)-1][1]
result[len(result)-1][1]=result[len(result)-1][0]
result[len(result)-1][0]=a
for i in range(len(result)):
  print(result[i][0],result[i][1])
  

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
n=int(input())
li=list(map(int,input().split()))

li.sort()
result1=li[len(li)-1]
result2=li[0]
re=[]
for i in range(1,len(li)-1):
  if li[i]<0:
    re.append([result1,li[i]])
    result1=result1-li[i]
  else:
    re.append([result2,li[i]])
    result2=result2-li[i]
               
re.append([result1,result2])
result1-=result2

print(result1)
for i in range(len(re)):
  print(re[i][0],re[i][1])

Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from heapq import heappush, heappop
Q = []
for a in As:
    heappush(Q, a)

for i in range(N-2):
    x = heappop(Q)
    y = heappop(Q)
    print(x, y)
    heappush(Q, x-y)

x = heappop(Q)
y = heappop(Q)
print(y, x)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
-2 -1
3 -1


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()
mini = As.pop(0)
maxi = As.pop()

ans = []
for a in As:
    if a>=0:
        ans.append((mini, a))
        mini -= a
    else:
        ans.append((maxi, a))
        maxi -= a

print(maxi-mini)
for a in ans:
    print(*a)
print(maxi, mini)
Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import deque


def m():
    M = int(input())
    A = deque(sorted([int(i) for i in input().split()]))
    steps = []
    
    maxA = A.pop()
    minA = A.popleft()
    while len(A) > 0:
        b = A.popleft()
        steps.append("{} {}".format(minA, b))
        minA -= b
    steps.append("{} {}".format(maxA, minA))
    print(maxA - minA)
    for s in steps:
        print(s)


m()


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
from collections import deque


def m():
    M = int(input())
    A = deque(sorted([int(i) for i in input().split()]))
    steps = []
    
    maxA = A.pop()
    minA = A.popleft()
    while len(A) > 0:
        b = A.popleft()
        if b > 0:
            steps.append("{} {}".format(minA, b))
            minA -= b
        else:
            steps.append("{} {}".format(maxA, b))
            maxA -= b
    steps.append("{} {}".format(maxA, minA))
    print(maxA - minA)
    for s in steps:
        print(s)


m()

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort()
xy=[]
for i in range(n-2,0,-1):
  y=a[i]
  if y>0:
    x=a[0]
    a[0]-=y
  else:
    x=a[n-1]
    a[n-1]-=y
    xy.append((x,y))
print(a[n-1]-a[0])
xy.append((a[n-1],a[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Failing test case input:
3
2 -2 10

Expected output:
14
-2 2
10 -4


Actual output:
14
10 -4


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a.sort()
xy=[]
for i in range(n-2,0,-1):
  y=a[i]
  if y>0:
    x=a[0]
    a[0]-=y
  else:
    x=a[n-1]
    a[n-1]-=y
  xy.append((x,y))
print(a[n-1]-a[0])
xy.append((a[n-1],a[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = sorted(map(int, input().split()))
mi = A[0]
ma = A[-1]
Ans = []
for i, a in enumerate(A[1:-1], 1):
    if a < 0:
        ma -= a
    else:
        Ans.append([mi, a])
        mi -= a

print(ma - mi)
for x, y in Ans:
    print(x, y)
print(ma, mi)


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
4 -2


Fixed submission (verdict: Accepted):
N = int(input())
A = sorted(map(int, input().split()))
mi = A[0]
ma = A[-1]
Ans = []
for i, a in enumerate(A[1:-1], 1):
    if a < 0:
        Ans.append([ma, a])
        ma -= a
    else:
        Ans.append([mi, a])
        mi -= a

print(ma - mi)
for x, y in Ans:
    print(x, y)
print(ma, mi)
Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from heapq import heapify, heappop, heappush
N = int(input())
A = list(map(int,input().split()))
heapify(A)
ans = []
for i in range(N-1,0,-1):
    n = i+1
    a,b = A.pop(0),A.pop()
    if n%2==1:
        ans.append([a,b])
        heappush(A,a-b)
    else:
        ans.append([b,a])
        heappush(A,b-a)
print(A[0])
for a in ans:
    print(*a)

Failing test case input:
3
1 -4 8

Expected output:
13
-4 1
8 -5


Actual output:
13
-4 8
1 -12


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
ans = []
A.sort()
a = A.pop(0)
b = A.pop()
N -= 2
k = 1
for i in range(N):
    y = A.pop()
    if y<0:k=0
    if k:
        ans.append([a,y])
        a -= y
    else:
        ans.append([b,y])
        b -= y
ans.append([b,a])
print(b-a)
for a in ans: print(*a)

Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import *
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=deque(a)
ans=[]
aa=a.pop()
tmp=a.popleft()
while a:
    t=a.popleft()
    ans.append((tmp,t))
    tmp-=t
ans.append((aa,tmp))
print(aa-tmp)
for i in ans:
    print(i[0],i[1])

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
from collections import *
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=deque(a)
ans=[]
aa=a.pop()
tmp=a.popleft()
while a:
    t=a.popleft()
    if t<=0:
        ans.append((aa,t))
        aa-=t
    else:
        ans.append((tmp,t))
        tmp-=t
ans.append((aa,tmp))
print(aa-tmp)
for i in ans:
    print(i[0],i[1])

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort()
mi,ma=a[0],a[-1]
for i in a[1:-1]:
  if i<0:print(ma,i);ma-=i
  else:print(mi,i);mi-=i
print(ma,mi)

Failing test case input:
3
5 0 2

Expected output:
7
0 2
5 -2


Actual output:
0 2
5 -2


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a.sort()
mi,ma=a[0],a[-1]
for i in a[1:-1]:
  if i<0:ma-=i
  else:mi-=i
print(ma-mi)
mi,ma=a[0],a[-1]
for i in a[1:-1]:
  if i<0:print(ma,i);ma-=i
  else:print(mi,i);mi-=i
print(ma,mi)
Problem: p03007
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from heapq import heappush, heappop
Q = []
for a in As:
    heappush(Q, a)

ans = []
for i in range(N-2):
    x = heappop(Q)
    y = heappop(Q)
    ans.append((x, y))
    heappush(Q, x-y)

x = heappop(Q)
y = heappop(Q)
ans.append((y, x))
print(y-x)
for a in ans:
    print(*a)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()
mini = As.pop(0)
maxi = As.pop()

ans = []
for a in As:
    if a>=0:
        ans.append((mini, a))
        mini -= a
    else:
        ans.append((maxi, a))
        maxi -= a

print(maxi-mini)
for a in ans:
    print(*a)
print(maxi, mini)

Problem: p03007
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import deque


def m():
    M = int(input())
    A = deque(sorted([int(i) for i in input().split()]))
    steps = []
    
    maxA = A.pop()
    minA = A.popleft()
    while len(A) > 0:
        b = A.pop()
        steps.append("{} {}".format(minA, b))
        minA -= b
    steps.append("{} {}".format(maxA, minA))
    print(maxA - minA)
    for s in steps:
        print(s)


m()


Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
4
-2 -1
3 -1


Fixed submission (verdict: Accepted):
from collections import deque


def m():
    M = int(input())
    A = deque(sorted([int(i) for i in input().split()]))
    steps = []
    
    maxA = A.pop()
    minA = A.popleft()
    while len(A) > 0:
        b = A.popleft()
        if b > 0:
            steps.append("{} {}".format(minA, b))
            minA -= b
        else:
            steps.append("{} {}".format(maxA, b))
            maxA -= b
    steps.append("{} {}".format(maxA, minA))
    print(maxA - minA)
    for s in steps:
        print(s)


m()

Problem: p03007
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,*a = map(int,open(0).read().split())
xy = []
xyap = xy.append
ap = max(a)
am = min(a)
a.remove(ap)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((i,ap))
    ap += 1
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)

Failing test case input:
3
-1 3 -2

Expected output:
6
3 -1
4 -2


Actual output:
6
-1 3
4 -2


Fixed submission (verdict: Accepted):
n= int(input())
a = list(map(int,input().split()))
xy = []
xyap = xy.append
ap = max(a)
a.remove(ap)
am = min(a)
a.remove(am)
for i in a:
  if i>0:
    xyap((am,i))
    am -= i
  else:
    xyap((ap,i))
    ap -= i
xyap((ap,am))
print(ap-am)
for i in xy:
  print(*i)
Problem: p02271
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

sum_list = []
for i in range(n**2):
    b = '{0:0{1}b}'.format(i, n)
    temp = []
    for j in range(n):
        if b[j] == '1':
            temp.append(A[j])
    sum_list.append(sum(temp))


for k in m:
    print('yes' if k in sum_list else 'no')

Failing test case input:
5
2 5 7 3 21
8
0 2 17 11 36 34 010 74

Expected output:
yes
yes
yes
no
yes
no
yes
no


Actual output:
yes
yes
no
no
yes
no
yes
no


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

sum_list = []
for i in range(2**n):
    b = '{0:0{1}b}'.format(i, n)

    temp = []
    for j in range(n):
        if b[j] == '1':
            temp.append(A[j])
    sum_list.append(sum(temp))

for k in m:
    print('yes' if k in sum_list else 'no')

Problem: p02271
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

sum_list = []
for i in range(n**2):
    b = '{0:0{1}b}'.format(i, n)
    temp = []
    for j in range(n):
        if b[j] == '1':
            temp.append(A[j])
    sum_list.append(sum(temp))

for k in m:
    print('yes' if k in sum_list else 'no')

Failing test case input:
5
1 5 7 3 21
8
0 4 2 9 38 21 010 57

Expected output:
yes
yes
no
yes
no
yes
yes
no


Actual output:
yes
yes
no
no
no
yes
yes
no


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

sum_list = []
for i in range(2**n):
    b = '{0:0{1}b}'.format(i, n)

    temp = []
    for j in range(n):
        if b[j] == '1':
            temp.append(A[j])
    sum_list.append(sum(temp))

for k in m:
    print('yes' if k in sum_list else 'no')

Problem: p02271
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
N = int(2**n)
d = []

for i in range(N):
    b = "{:0{}b}".format(i, n)
    d.append(sum(A[j] for j in range(n) if b[j] == '1'))

    

for i in range(q):
    if m[i] in d:
        print("Yes")
    else:
        print("No")

Failing test case input:
5
0 5 11 5 21
8
2 4 17 11 22 14 000 42

Expected output:
no
no
no
yes
no
no
yes
yes


Actual output:
No
No
No
Yes
No
No
Yes
Yes


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
N = int(2**n)
d = []

for i in range(N):
    b = "{:0{}b}".format(i, n)
    d.append(sum(A[j] for j in range(n) if b[j] == '1'))

    

for i in range(q):
    if m[i] in d:
        print("yes")
    else:
        print("no")
Problem: p02271
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))

q = int(input())
m = list(map(int, input().split()))

def f(A, s, res):
  if res[0]:
    return
  if s == 0:
    res[0] = True
    return
  for a in reversed(A):
    if a <= s:
      f(A[0:A.index(a)], s-a, res)

for mi in m:
  res = [False]
  f(A, mi, res)
  if res[0]:
    print("yes")
  else:
    print("no")

Failing test case input:
5
1 7 7 10 21
8
2 4 17 10 22 20 100 35

Expected output:
no
no
yes
yes
yes
no
no
yes


Actual output:
no
no
yes
yes
yes
no
no
no


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
A.sort()
sumA = sum(A)

q = int(input())
m = list(map(int, input().split()))

def f(A, s, res):
  if res[0]:
    return
  if s == 0:
    res[0] = True
    return
  for i, a in enumerate(A):
    if a > s:
      break
    f(A[i+1:], s-a, res)

for mi in m:
  res = [False]

  if mi <= sumA:
    f(A, mi, res)

  if res[0]:
    print("yes")
  else:
    print("no")

Problem: p02271
Buggy submission (Python3, verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())

def solve(i, m):
    if (m == 0):
        return True
    if (i >= n):
        return False
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    return res

for j in range(q):
    if solve(0, j):
        print("yes")
    else:
        print("no")

Failing test case input:
5
0 5 11 3 21
8
2 4 17 11 22 14 000 42

Expected output:
no
no
no
yes
no
yes
yes
no


Actual output:
yes
no
no
yes
no
yes
no
no


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())
t = {}

def solve(i, m):
    if (m == 0):
        return True
    if (i >= n):
        return False
    if (i,m) in t:
        return t[(i,m)]
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    t[(i,m)] = res
    return res

for m in mi:
    if solve(0, m):
        print("yes")
    else:
        print("no")