TnT/CodeNet4Repair huggingface dataset:
Problem:
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function.                 Merge(A, left, mid, right)   n1 = mid - left;   n2 = right - mid;   create array L[0...n1], R[0...n2]   for i = 0 to n1-1     do L[i] = A[left + i]   for i = 0 to n2-1     do R[i] = A[mid + i]   L[n1] = SENTINEL   R[n2] = SENTINEL   i = 0;   j = 0;   for k = left to right-1     if L[i] <= R[j]       then A[k] = L[i]            i = i + 1       else A[k] = R[j]            j = j + 1  Merge-Sort(A, left, right){   if left+1 < right     then mid = (left + right)/2;          call Merge-Sort(A, left, mid)          call Merge-Sort(A, mid, right)          call Merge(A, left, mid, right)

Incorrect submission (verdict: Wrong Answer):
N = int(input())
*A, = list(map(int, input().split()))
count = 0


def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    la, ra = [], []
    for i in range(0, n1):
        la += [a[left + i]]
    for i in range(0, n2):
        ra += [a[mid + i]]
    la += [float("inf")]
    ra += [float("inf")]
    print(la)
    print(ra)

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i = i + 1
        else:
            a[k] = ra[j]
            j = j + 1


def merge_sort(a, left, right):
    
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

merge_sort(A, 0, N)
print(count)
print(*A)


Fixed, accepted submission:
N = int(input())
*A, = list(map(int, input().split()))
count = 0


def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

merge_sort(A, 0, N)
print(*A)
print(count)
Problem:
How many multiples of d are there among the integers between L and R (inclusive)?

Incorrect submission (verdict: Wrong Answer):
l,r,d = map(int,input().split())
if l % d == 0:
         print(((r - l) // d) + 1)
else:
         print((r - l) // d)


Fixed, accepted submission:
l,r,d = map(int,input().split())
ans = 0
for i in range(l,r+1):
         if i % d == 0:
                  ans += 1
print(ans)
Problem:
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.

Incorrect submission (verdict: Wrong Answer):
s = list(input())
t = list(input())
s.sort(), t.sort(reverse=True)
s, t = ''.join(s), ''.join(t)

if s<t:
    print('YES')
else:
    print('NO')


Fixed, accepted submission:
s = ''.join(sorted(list(input())))
t = ''.join(sorted(list(input()), reverse=True))
print('Yes') if s<t else print('No')
Problem:
Sitting in a station waiting room, Joisino is gazing at her train ticket.  The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).  In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds.  The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Incorrect submission (verdict: Wrong Answer):
import sys
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
  for j in x:
    for k in x:
      if a+i*b+j*c+k*d==7:
        ans = str(a)
        ans += "+" if i==1 else"-"
        ans += str(b)
        ans += "+" if j==1 else"-"
        ans += str(c)
        ans += "+" if k==1 else"-"
        ans += str(d)
        print(ans)
        sys.exit()

Fixed, accepted submission:
import sys
a,b,c,d = map(int, list(input()))
x = [1,-1]
for i in x:
  for j in x:
    for k in x:
      if a+i*b+j*c+k*d==7:
        ans = str(a)
        ans += "+" if i==1 else "-"
        ans += str(b)
        ans += "+" if j==1 else "-"
        ans += str(c)
        ans += "+" if k==1 else "-"
        ans += str(d)
        ans += "=7"
        print(ans)
        sys.exit()
Problem:
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.  He has very high awareness of safety, and decides to buy two bells, one for each hand.  The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.

Incorrect submission (verdict: Wrong Answer):
array = sorted(input().split())
print(array[0]+array[1])

Fixed, accepted submission:
array = sorted(list(map(int, input().split())))
print(array[0]+array[1])
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 = input().split()
if C >= A and C <= B:
    print('YES')
else:
    print('NO')

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

if C >= A and C <= B:
    print('Yes')
else:
    print('No')
Problem:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Incorrect submission (verdict: Wrong Answer):
n,a,b = map(int,input().split())
count = 0
for i in range(n):
    if (i+1) == 10000 and a == 1:
        count += 1
        break
    judge = (i+1)%10 + ((i+1)%100 - (i+1)%10)//10 + ((i+1)%1000 - (i+1)%100 - (i+1)%10)//100
    if judge >= a and judge <= b:
        count += 1
print(count)


Fixed, accepted submission:
n,a,b = map(int,input().split())
count = 0
for i in range(n+1):
    judge = i%10 + (i%100 - i%10)//10 + (i%1000 - i%100)//100 + (i%10000 - i%1000)//1000 + (i%100000 - i%10000)//10000
    if judge >= a and judge <= b:
        count += i
print(count)
Problem:
You are given three integers, A, B and C.   Among them, two are the same, but the remaining one is different from the rest.   For example, when A=5,B=7,C=5, A and C are the same, but B is different.   Find the one that is different from the rest among the given three integers.

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(int,input().split());print(a+c-b)

Fixed, accepted submission:
a,b,c=sorted(map(int,input().split()));print(a+c-b)
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

Incorrect submission (verdict: Wrong Answer):
N = input().split()
sn = ""
for i in N:
    sn += i
print('Yes' if int(sn) % 4 == 0 else 'No')

Fixed, accepted submission:
N = input().split()
sn = ""
for i in N:
    sn += i
print('YES' if int(sn) % 4 == 0 else 'NO')
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

Incorrect submission (verdict: Wrong Answer):
X,A,B = [int(i) for i in input().split()]
if B-A<=X:
  print('delicious')
else:
  print('dangerous')

Fixed, accepted submission:
X,A,B = [int(i) for i in input().split()]
if B-A<=0:
  print('delicious')
elif 0<B-A<=X:
  print('safe')
else:
  print('dangerous')
Problem:
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:    * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.   * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.  The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Incorrect submission (verdict: Wrong Answer):
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
    k,kk = map(int,input().split())
    a.append(k)
    b.append(kk)

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += int((H - num)/zanmax)
    print(cnt)


Fixed, accepted submission:
import math
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
    k,kk = map(int,input().split())
    a.append(k)
    b.append(kk)

zanmax = max(a)

b = sorted(b,reverse=True)

num = 0
cnt = 0
for i in b:
    if zanmax < i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += ((H-num)/zanmax)
print(math.ceil(cnt))
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

Incorrect submission (verdict: Wrong Answer):
x, a, b = map(int, input().split())
if b <= a:
  print("delicious")
elif a < b <= x:
  print("safe")
else:
  print("dangerous")

Fixed, accepted submission:
x, a, b = map(int, input().split())
if b <= a:
  print("delicious")
elif a < b <= a + x:
  print("safe")
else:
  print("dangerous")
Problem:
Write a program which computes the digit number of sum of two integers a and b.

Incorrect submission (verdict: Wrong Answer):
print(len(str(sum(map(int, input().split())))))

Fixed, accepted submission:
try:
    while 1:
        print(len(str(sum(map(int, input().split())))))
except Exception:
    pass
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 = list(map(int, input().split()))

max_list = [0] * (N - 1)
min_list = [0] * (N - 1)

for i in range(N - 1):
    max_list[i] = max(A_list)
    A_list.pop(A_list.index(max_list[i]))
    min_list[i] = min(A_list)
    A_list.pop(A_list.index(min_list[i]))
    tmp = min_list[i] - max_list[i]
    A_list.append(tmp)

print(-sum(A_list))
for i in range(N - 1):
    print(max_list[i], min_list[i])

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

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

A_sorted = sorted(A_list)

pos_count = len([a for a in A_sorted if a >= 0])
neg_count = len([a for a in A_sorted if a < 0])

if pos_count == 0:
    pos_count = 1
    neg_count = N - 1
if neg_count == 0:
    pos_count = N - 1
    neg_count = 1

output_list = [0] * (N - 1)
count = 0
for q in range(neg_count, N - 1):
    output_list[count] = [A_sorted[0], A_sorted[q]]
    count += 1
    A_sorted[0] -= A_sorted[q]


for i in range(neg_count):
    output_list[count] = [A_sorted[N - 1], A_sorted[i]]
    count += 1
    A_sorted[N - 1] -= A_sorted[i]

print(A_sorted[N - 1])
for item in output_list:
    print(item[0], item[1])
Problem:
Takahashi is a user of a site that hosts programming contests.   When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows:    * Let the current rating of the user be a.   * Suppose that the performance of the user in the contest is b.   * Then, the new rating of the user will be the avarage of a and b.  For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.  Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.   Find the performance required to achieve it.

Incorrect submission (verdict: Wrong Answer):
R = int(input())
G = int(input())

if R >= G:
    sa = R-G
    print(G+sa)
else:
    sa = G-R
    print(R+sa)

Fixed, accepted submission:
R = int(input())
G = int(input())

sa = G-R
print(G+sa)
Problem:
太郎君はよくJOI雑貨店で買い物をする． JOI雑貨店には硬貨は500円，100円，50円，10円，5円，1円が十分な数だけあり，いつも最も枚数が少なくなるようなおつりの支払い方をする．太郎君がJOI雑貨店で買い物をしてレジで1000円札を1枚出した時，もらうおつりに含まれる硬貨の枚数を求めるプログラムを作成せよ．  例えば入力例1の場合は下の図に示すように，4を出力しなければならない．  

Incorrect submission (verdict: Wrong Answer):
c, o= 0, 1000-int(input())
if o>= 500:
    o, c= o-500, c+1
if o>= 100:
    t= o//100
    o, c= o-(100*t), c+t
if o>= 10:
    t= o//10
    o, c= o-(10*t), c+t
if o>= 5:
    t= o//5
    o, c= o-(5*t), c+t
print(c)

Fixed, accepted submission:
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

while True:
    o= int(input())
    if o== 0: break
    c, o= 0, 1000-o
    for l in [500, 100, 50, 10, 5, 1]: change(l)
    print(c+o)
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):
def check(a,b):
    distance = abs(a[1]-b[1]) + abs(a[2]-b[2])
#     print(distance)
    
    time = abs(b[0]-a[0])
#     print(time)
    
    c = time - distance
    if((c >= 0) and (c%2==0)):
        return 0
    else:
        return 1
    

def main():
    n = int(input())
    plan = [list(map(int, input().split())) for i in range(n)]
    if(check([0,0,0],plan[0])==1):
        print("NO")
        return
    
    flag = 0
    for i in range(n-1):
        flag += check(plan[i],plan[i+1])
        if (flag >0):
            break
    
    if (flag == 0):
        print("YES")
    else:
        print("NO")
main()

Fixed, accepted submission:
def check(a,b):
    distance = abs(a[1]-b[1]) + abs(a[2]-b[2])
    time = abs(b[0]-a[0])
    
    c = time - distance
    if((c >= 0) and (c%2==0)):
        return 0
    else:
        return 1
    

def main():
    n = int(input())
    plan = [list(map(int, input().split())) for i in range(n)]
    if(check([0,0,0],plan[0])==1):
        print("No")
        return
    
    flag = 0
    for i in range(n-1):
        flag += check(plan[i],plan[i+1])
        if (flag >0):
            break
    
    if (flag == 0):
        print("Yes")
    else:
        print("No")
main()
Problem:
We have N sticks with negligible thickness. The length of the i-th stick is A_i.  Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Incorrect submission (verdict: Wrong Answer):
input()
a=[int(i) for i in input().split()]
sorted(a,reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
  if tb==1:
    tb=0
  else:
    if a[i]==a[i+1] and tyo==0:
      tyo=a[i]
      tb=1
    else:
      tan=a[i]
      break
print(tyo+tan)

Fixed, accepted submission:
input()
a=[int(i) for i in input().split()]
a.sort(reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
  if tb==1:
    tb=0
  else:
    if a[i]==a[i+1] and tyo==0:
      tyo=a[i]
      tb=1
    elif a[i]==a[i+1]:
      tan=a[i]
      break
print(tyo*tan)
Problem:
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Incorrect submission (verdict: Wrong Answer):
input()
arr = list(map(int, input().split()))
flag = False
count = 0
while not flag:
    flag = True
    for i in range(len(arr)-1):
        if arr[i] > arr[i+1]:
            count + 1
            flag = False
            t = arr[i+1]
            arr[i+1] = arr[i]
            arr[i] = t  
print(" ".join(map(str, arr)))
print(count)


Fixed, accepted submission:
input()
arr = list(map(int, input().split()))
flag = False
count = 0
while not flag:
    flag = True
    for i in range(len(arr)-1):
        if arr[i] > arr[i+1]:
            count += 1
            flag = False
            t = arr[i+1]
            arr[i+1] = arr[i]
            arr[i] = t  
print(" ".join(map(str, arr)))
print(count)
Problem:
Write a program which reads a sequence and prints it in the reverse order.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
num = [int(i) for i in input().split()]
for i in range(round(len(num)/2)):
    num[i],num[len(num)-i-1] = num[len(num)-i-1],num[i]
print(num)


Fixed, accepted submission:
n = int(input())
num = [int(i) for i in input().split()]
for i in range(round(len(num)/2)):
    num[i],num[len(num)-i-1] = num[len(num)-i-1],num[i]
print(' '.join(str(i) for i in num))
Problem:
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.

Incorrect submission (verdict: Wrong Answer):
def main():
    n=list(map(int,input().split()))
    n = n[1]
    friends=[]
    question=[]
    for i in range(n):
        a=tuple(map(int,input().split()))
        friends.append(a)
    m=int(input())
    for i in range(m):
        b=tuple(map(int,input().split()))
        question.append(b)
    for i in question:
        if i in friends:
            print("yes")
        else:
            print("no")
if __name__ == "__main__":
    main()


Fixed, accepted submission:
#coding:utf-8

class UnionFind:
    def __init__(self,n):
        self.parent=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
    def find(self,x):
        if self.parent[x] == x: # if x is x`s root
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    def is_same_tree(self,x,y):
        return self.find(x) == self.find(y) 
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        
def main():
    n=list(map(int,input().split()))
    union=UnionFind(n[0])
    friends=[]
    question=[]
    for i in range(n[1]):
        a=tuple(map(int,input().split()))
        friends.append(a)
    for i in friends:
        union.union(i[0],i[1])
    m=int(input())
    for i in range(m):
        b=tuple(map(int,input().split()))
        question.append(b)
    for i in question:
        if union.find(i[0]) == union.find(i[1]):
            print("yes")
        else:
            print("no")
if __name__ == "__main__":
    main()
Problem:
We have an N \times N square grid.  We will paint each square in the grid either black or white.  If we paint exactly A squares white, how many squares will be painted black?

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = int(input())

print(n**n - a)

Fixed, accepted submission:
n = int(input())
a = int(input())

print(n**2 - a)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
def shift_only(n,array):
    tmp = []
    counter = 0
    while True:
        flag = True
        
        for num in array:
            if num%2 != 0:
                flag = False
        if flag == False:
            break
        array = [i/2 for i in array]
        counter +=1
    return counter

Fixed, accepted submission:
def shift_only(array):
    tmp = []
    counter = 0
    while True:
        flag = True
        
        for num in array:
            if num%2 != 0:
                flag = False
        if flag == False:
            break
        array = [i/2 for i in array]
        counter +=1
    print(counter)
    
n = int(input())
a = list(map(int, input().split()))
shift_only(a)
Problem:
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).  The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.

Incorrect submission (verdict: Wrong Answer):
def CheckCards(Mark):
    for i in range(1, 13):
        if [Mark, i] not in Cards:
            print(Mark + str(i))

n = int(input())
Cards = []
for i in range(n):
    Cards.append(input().split())
    Cards[i][1] = int(Cards[i][1])

CheckCards("S")
CheckCards("H")
CheckCards("C")
CheckCards("D")

Fixed, accepted submission:
def CheckCards(Mark):
    for i in range(1, 14):
        if [Mark, i] not in Cards:
            print(Mark + " " + str(i))

n = int(input())
Cards = []
for i in range(n):
    Cards.append(input().split())
    Cards[i][1] = int(Cards[i][1])

CheckCards("S")
CheckCards("H")
CheckCards("C")
CheckCards("D")