TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
h,w = list(map(int, input().split()))
L = [input() for _ in range(h)]

ans=[]
for row in range(len(L)):
    LINE=[]
    for col in range(len(L[row])):
        print('row=',row,'col=',col,L[row][col])
        if L[row][col]=='.':
            cnt=0
            for shiftX, shiftY in [(i,j) for i in [-1,0,1] for j in [-1,0,1] if i!=0 or j!=0]:
                if 0<=row+shiftY<h and 0<=col+shiftX<w:
                    if L[row+shiftY][col+shiftX]=='#':
                        cnt+=1
            LINE.append(str(cnt))
        else:
            LINE.append('#')
    ans.append(LINE)

for a in ans:
    print(''.join(a))

Fixed, accepted submission:
h,w = list(map(int, input().split()))
L = [input() for _ in range(h)]

ans=[]
for row in range(len(L)):
    LINE=[]
    for col in range(len(L[row])):
        if L[row][col]=='.':
            cnt=0
            for shiftX, shiftY in [(i,j) for i in [-1,0,1] for j in [-1,0,1] if i!=0 or j!=0]:
                if 0<=row+shiftY<h and 0<=col+shiftX<w:
                    if L[row+shiftY][col+shiftX]=='#':
                        cnt+=1
            LINE.append(str(cnt))
        else:
            LINE.append('#')
    ans.append(LINE)

for a in ans:
    print(''.join(a))
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

Incorrect submission (verdict: Wrong Answer):
a, b, x = map(int, input().split())
if a <= x and a + b >= x:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
a, b, x = map(int, input().split())
if a <= x and a + b >= x:
    print('YES')
else:
    print('NO')
Problem:
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.

Incorrect submission (verdict: Wrong Answer):
a,b,c = map(int,input().split())
if a <= c <= b:
  print('yes')
else:
  print('no')

Fixed, accepted submission:
a,b,c = map(int,input().split())
if a <= c <= b:
  print('Yes')
else:
  print('No')
Problem:
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value:    * Operation A: The displayed value is doubled.   * Operation B: The displayed value increases by K.  Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
K = int(input())
ans = 1
for i in range(N + K):
    if i <= N -1:
        ans *= 2
    else:
        ans += K
print(ans)

Fixed, accepted submission:
N = int(input())
K = int(input())
ans = 1
for i in range(N):
    if ans * 2 <= ans + K:
        ans *= 2
    else:
        ans += K
print(ans)
Problem:
Print all the integers that satisfies the following in ascending order:    * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Incorrect submission (verdict: Wrong Answer):
A,B,K = map(int,input().split())

s=set()

for i in range(K):
  s.add(A+i)
  s.add(B-i)
#print(s)

lis=sorted(s)
print(lis)

Fixed, accepted submission:
A,B,K = map(int,input().split())

s=set()

for i in range(K):
  if A+i<=B:
    s.add(A+i)
  if B-i>=A:
    s.add(B-i)
#print(s)

lis=sorted(s)
for item in lis:
  print(item)
Problem:
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.  You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106

Incorrect submission (verdict: Wrong Answer):

def main():
    l = input().split(' ')

    s = []

    for el in l:
        print(s)
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()


Fixed, accepted submission:

def main():
    l = input().split(' ')

    s = []

    for el in l:
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()
Problem:
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
numbers=input().split()
sorted(numbers, key=int)
print(numbers[0], numbers[-1], sum(map(int, numbers)))

Fixed, accepted submission:
n=int(input())
numbers=input().split()
numbers = sorted(numbers, key=int)
print(numbers[0], numbers[-1], sum(map(int, numbers)))
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
N = int(input())

t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)
t[0] = x[0] = y[0] = 0
result = "YES"

def is_even(num):
    return num % 2 == 0


for i in range(1, N+1):
    t[i], x[i], y[i] = list(map(int, input().split()))
    time = t[i] - t[i-1]
    xlen = x[i] - x[i-1]
    ylen = y[i] - y[i-1]
    if is_even(time) == is_even(xlen+ylen) and abs(xlen) <= time and abs(ylen) <= time - abs(xlen):
        continue
    result = "NO"
    break

print(result)

Fixed, accepted submission:
N = int(input())

t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)
t[0] = 0
x[0] = 0
y[0] = 0
result = "Yes"

def is_even(num):
    return num % 2 == 0

for i in range(1, N+1):
    t[i], x[i], y[i] = list(map(int, input().split()))

for i in range(1, N+1):
    time = t[i] - t[i-1]
    xlen = abs(x[i] - x[i-1])
    ylen = abs(y[i] - y[i-1])
    distance = xlen+ylen
    if is_even(time) == is_even(distance) and distance <= time:
        continue
    result = "No"
    break
    
print(result)
Problem:
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Incorrect submission (verdict: Wrong Answer):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

N = int(input())
aa = inpl_int()

i = 1
while True:
	if aa.count(i)==2:
		X1 = aa.index(i)
		aa[X1] = 0
		X2 = aa.index(i)
		break
	i += 1

print(X1,X2)
L,R = X1,N-X2
ALL = 1

for i in range(1,N+2):
	ALL = ALL * (N+2-i)//i
	if L+R+1 >= i:
		if i == 1:
			daburi = 1
		else:
			daburi = daburi * (L+R+2-i)//(i-1)
	else:
		daburi = 0

	print(i,(ALL-daburi)%mod)

Fixed, accepted submission:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl_int(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

def Comb(n):
    gyakugen = [1]*(n+1)
    fac = [1]*(n+1)

    for i in range(1,n+1):
        fac[i] = (fac[i-1]*i)%mod

    gyakugen[n] = pow(fac[n],mod-2,mod)

    for i in range(n,0,-1):
        gyakugen[i-1] = (gyakugen[i]*i)%mod

    com = [1]*(n+1)

    for i in range(1,n+1):
        com[i] = (fac[n]*gyakugen[i]*gyakugen[n-i])%mod

    return com

N = int(input())
aa = inpl_int()

i = 1
dd = defaultdict(int)
for i,a in enumerate(aa):
	if dd[a] == 0:
		dd[a] = i+1
	else:
		X1 = dd[a]-1
		X2 = i

L,R = X1,N-X2
ALL = 1

ALL = Comb(N+1)
daburi = Comb(L+R)

for i in range(1,N+2):
	if L+R+1 >= i:
		print((ALL[i]-daburi[i-1])%mod)
	else:
		print(ALL[i]%mod)
Problem:
E869120 found a chest which is likely to contain treasure.   However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.   He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`.  One more thing he found is a sheet of paper with the following facts written on it:    * Condition 1: The string S contains a string T as a contiguous substring.   * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.  Print the string S.   If such a string does not exist, print `UNRESTORABLE`.

Incorrect submission (verdict: Wrong Answer):
import re
S=input().replace("?", ".")
T=input()
for i in range(len(S)-len(T)-1):
    if re.match(S[i:i+len(T)], S):
        S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")

Fixed, accepted submission:
import re
S=input().replace("?", ".")
T=input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")
Problem:
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.

Incorrect submission (verdict: Wrong Answer):
n = input()
print('Yes') if 'abc' in n else print('No')

Fixed, accepted submission:
n = input()
print('Yes') if set(n) == set('abc') else print('No')
Problem:
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.  You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.

Incorrect submission (verdict: Wrong Answer):
s = input()
a=0
b=0
for i in range(len(s)):
  if s[i]=='A':
    a = i
    break
for i in range(len(s)-1,-1,-1):
  if s[i] == 'Z':
    b = i
    break
print(b-a+1)

Fixed, accepted submission:
x = int(input())
print('ABC' if x<1200 else 'ARC')
Problem:
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.  The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)  Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Incorrect submission (verdict: Wrong Answer):
x = int(input())

a = 100
i = 0
while True:
	i += 1
	a = int(a * 1.01)
	if(x < a):
		print(i)
		break


Fixed, accepted submission:
x = int(input())

a = 100
i = 0
while True:
	i += 1
	a = int(a * 1.01)
#	print(a)
	if(x <= a):
		print(i)
		break
Problem:
In this problem, we use the 24-hour clock.  Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?

Incorrect submission (verdict: Wrong Answer):
import datetime

h1,m1,h2,m2,k=map(int, input().split())

starttime = datetime.datetime(2020, 1, 1, h1, m1)
endtime = datetime.datetime(2020, 1, 1, h2, m2) - datetime.timedelta(minutes = k)

td = endtime-starttime
ans = td.seconds / 60
if ans <= 0:
    ans = 0
print(ans)

Fixed, accepted submission:
import datetime

h1,m1,h2,m2,k=map(int, input().split())

starttime = 60 * h1 + m1
endtime = 60 * h2 + m2 -k

td = endtime - starttime
if td <= 0:
    td = 0
print(td)
Problem:
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.

Incorrect submission (verdict: Wrong Answer):
s = input()
ans = ""
for i in range(len(s)):
  if i%2 == 1:
    ans += s[i]
print(ans)

Fixed, accepted submission:
s = input()
ans = ""
for i in range(len(s)):
  if i%2 == 0:
    ans += s[i]
print(ans)
Problem:
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i.  Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:    * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.  Find the intensity of each bulb after the K operations.

Incorrect submission (verdict: Wrong Answer):
import heapq

n, k = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

for _ in range(k):
    finish=True
    start=[]
    startInd=0
    end=[]
    endInd=0
    for i in range(n):
        if A[i]!=n:
            finish=False
        heapq.heappush(start,i-A[i])
        heapq.heappush(end,i+A[i])
    if finish:
        break
    # update ans
    cnt=0
    for i in range(n):
        while startInd<n and start[startInd]<=i:
            cnt+=1
            startInd+=1
        A[i]=cnt
        while endInd<n and end[endInd]<=i:
            endInd+=1
            cnt-=1

print(A)

Fixed, accepted submission:
from numba import jit
import numpy as np


n, k = map(int, input().split())
A = np.array([*map(int, input().split())],dtype=np.int64)

# for _ in range(min(k,int(math.log(n,2)))):

@jit
def loop(A):
    for _ in range(k):
        b=np.zeros(n,dtype=np.int64)
        
        for i,v in enumerate(A):
            # if i>v:
            b[max(0,i-v)]+=1
                # b[i-v]+=1
            # else:
                # b[0]+=1
            # j=i-~v
            if i+v+1<n:
                b[i+v+1]-=1
            # if j<n:
            #     b[j]-=1
        
        # update ans
        # cnt=0
        
        #     b[i]+=b[i-1]
        A=np.cumsum(b)
        
        if min(A)==n:
            break
    return A
print(" ".join(map(str,loop(A))))
Problem:
There is a hotel with the following accommodation fee:    * X yen (the currency of Japan) per night, for the first K nights   * Y yen per night, for the (K+1)-th and subsequent nights  Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.

Incorrect submission (verdict: Wrong Answer):
def check_w(arr):
    a = 0
    for i in range(len(arr)-1):
        a += 1
        if arr[i] != arr[i+1]:
            if a % 2 != 0:
                return False
            a = 0
    return True

w = list(input())
w.sort()
if check_w(w):
    print("Yes")
else:
    print("No")


Fixed, accepted submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n >= k:
    print(k * x + (n - k) * y)
else:
    print(n * x)
Problem:
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

Incorrect submission (verdict: Wrong Answer):
n,m = map(int,input().split())
print(n - 1 * m - 1)

Fixed, accepted submission:
n,m = map(int,input().split())
print((n - 1) * (m - 1))
Problem:
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.  Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).

Incorrect submission (verdict: Wrong Answer):
H,W=map(int,input().split())
for _ in range(H):
	a=input().split()
	print(a)
	print(a)

Fixed, accepted submission:
H,W=map(int,input().split())
for _ in range(H):
	a=input()
	print(a)
	print(a)
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
s=input()
for i in range(len(s)):
    s=s[:-1]
    if len(s)%2 ==0 and s[:len(s)//2] == s[len(s)//2:]:
        print(s)
        break


Fixed, accepted submission:
s=input()
for i in range(len(s)):
    s=s[:-1]
    if len(s)%2 ==0 and s[:len(s)//2] == s[len(s)//2:]:
        print(len(s))
        break
Problem:
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

Incorrect submission (verdict: Time Limit Exceeded):
import math

beki=[]
beki.append(1)
x=int(input())
for i in range(int(math.sqrt(x))):
  p=2
  while(i**p<=x):
    beki.append(i**p)
    p+=1
print(beki)

Fixed, accepted submission:
import math

beki=[]
beki.append(1)
x=int(input())
for i in range(2,x):
  p=2
  while(i**p<=x):
    beki.append(i**p)
    p+=1
print(max(beki))
Problem:
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:    * Question 1: Are you subscribing to Newspaper X?   * Question 2: Are you subscribing to Newspaper Y?  As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2.  What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?  Write a program to answer this question.

Incorrect submission (verdict: Wrong Answer):

N, A, B = map(int, input().split(" "))

n = 0
if N >= A+B:
	n = 0
elif N < A+B:
	n = (A+B)- N

print(max(A, B), n)


Fixed, accepted submission:

N, A, B = map(int, input().split(" "))

if A == B and A == N:
	print(A, A)
else:
	n = 0
	if A + B > N:
		n = A+B-N
	else:
		n = 0


	print(min(A, B), n)
Problem:
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:    * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
D = list(map(int, input().split()))
D.sort()
print(D)

def calc(N, D):
  counts = [0]
  preNum = 0
  for i in D:
    if i == preNum:
      counts[-1] += 1
    elif i == preNum + 1:
      counts.append(1)
    else:
      return 0
    preNum = i
  result = 1
  for i in range(len(counts)-1):
    result = result * pow(counts[i], counts[i+1])
  return result%998244353

print(calc(N, D))

Fixed, accepted submission:
N = int(input())
D = [int(d) for d in input().split()]
maxD = max(D)
length = [0 for _ in range(maxD+1)]
mod = 998244353
for d in D:
    length[d] += 1
if D[0] != 0 or length[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(1, maxD + 1):
        if length[i] == 0:
            print(0)
            break
        else:
            ans *= (length[i-1] ** length[i]) % mod
            ans %= mod
    else:
        print(ans)
Problem:
Snuke has a favorite restaurant.  The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.  So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x = 800 * n
y = 200 * (n % 15)
print(x - y)

Fixed, accepted submission:
n = int(input())
x = 800 * n
y = 200 * (n // 15)
print(x - y)
Problem:
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.  She will concatenate all of the strings in some order, to produce a long string.  Among all strings that she can produce in this way, find the lexicographically smallest one.  Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds:    * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.   * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

Incorrect submission (verdict: Wrong Answer):
str = input()

Fixed, accepted submission:
N, L = map(int,input().split())
words = []
for i in range(N):
  words.append(input())
 
words.sort()
print(''.join(words))
Problem:
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".

Incorrect submission (verdict: Wrong Answer):
n1,n2,n3,n4=map(int,input().split())
t=[n1,n2,n3,n4]
t.sort()
print(t)
if t[0]==1 and t[1]==4 and t[2]==7 and t[3]==9:
  print("YES")
else:
  print("NO")

Fixed, accepted submission:
n1,n2,n3,n4=map(int,input().split())
t=[n1,n2,n3,n4]
t.sort()
if t[0]==1 and t[1]==4 and t[2]==7 and t[3]==9:
  print("YES")
else:
  print("NO")
Problem:
There are N integers, A_1, A_2, ..., A_N, written on a blackboard.  We will repeat the following operation N-1 times so that we have only one integer on the blackboard.    * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y.  Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort()
minus=sum(a[0:n//2])
plus=sum(a)-minus
print(plus-minus)

if n%2==0:
 s=a[0]
 for i in range(1,n//2):
  print(a[n-i],s)
  s=a[n-i]-s
  print(a[i],s)
  s=a[i]-s
 print(a[n//2],s)

else:
 s=a[n-1]
 for i in range(n//2):
  print(a[i],s)
  s=a[i]-s
  print(a[n-(i+2)],s)
  s=a[n-(i+2)]-s

Fixed, accepted submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
plus=[a[n-1]]
minus=[a[0]]
for i in range(1,n-1):
	if a[i]>=0:
		plus.append(a[i])
	else:
		minus.append(a[i])
print(sum(plus)-sum(minus))
k=minus[-1]
for i in range(len(plus)-1):
	print(k,plus[i+1])
	k-=plus[i+1]
t=plus[0]
for i in range(len(minus)-1):
	print(t,minus[i])
	t-=minus[i]
print(t,k)