TnT/CodeNet4Repair huggingface dataset:
Problem:
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.  In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).  Your task is to read a sequence A and perform the Partition based on the following pseudocode:                 Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4     do if A[j] <= x 5        then i = i+1 6            exchange A[i] and A[j]  7 exchange A[i+1] and A[r] 8 return i+1   Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].

Incorrect submission (verdict: Wrong Answer):
def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A_tmp = A[i]
            A[i] = A[j]
            A[j] = A_tmp
        t = A[i+1]
        A[i+1] = A[r]
        A[r] = t


n = int(input())
A = [int(_) for _ in input().split()]
q = partition(0, n-1)
for i in range(n):
    if i:
        print(" ")
    if i == q:
        print("[")
    print(A[i])
    if i == q:
        print("]")
print("\n")



Fixed, accepted submission:
def partition(p, r):
    x = A[r]
    i = p - 1  
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A_tmp = A[i]
            A[i] = A[j]
            A[j] = A_tmp
    t = A[i+1]
    A[i+1] = A[r]
    A[r] = t
    return i+1


n = int(input())
A = [int(_) for _ in input().split()]
q = partition(0, n-1)
for i in range(n):
    if i:
        print(" ", end="")
    if i == q:
        print("[", end="")
    print(A[i], end="")
    if i == q:
        print("]", end="")
print("")
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int, input().split())
if (a*b)%2==0:
   print("Odd")
else:
   print("Even")

Fixed, accepted submission:
a,b = map(int, input().split())
if (a*b)%2==0:
   print("Even")
else:
   print("Odd")
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):
a,b,c=map(int,input().split())
if a+b  <  c+b or b+c <c+b:
  print(c+b)
elif c+b  <  a+b or b+c <a+b:
  print(a+b)
else:
  print(a+c)

Fixed, accepted submission:
x,y,z=map(int,input().split())
if (x+y) <= (x+z)  and (x+y)<= (y+z):
  print(x+y)
elif (x+z) <= (x+y) and (x+z) <= (y+z):
  print(x+z)
elif (y+z) <= (x+y) and (y+z) <= (x+z):
  print(y+z)
else:
  print(x+z)
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())
print("Yes" if a<=x and x<=a+b else "No" )

Fixed, accepted submission:
a, b, x = map(int, input().split())
print("YES" if a<=x and x<=a+b else "NO" )
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Time Limit Exceeded):
a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
print(ans)

Fixed, accepted submission:
a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
  i+=1
print(ans)
Problem:
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.  The score allocated to the i-th (1≦i≦N) problem is i points.  Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.  As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.  Determine the set of problems that should be solved.

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


def calc(n):
    mx = 1
    while True:
        if n <= mx * (mx + 1) // 2:
            break
        mx += 1
    return mx


ans = []
while n > 0:
    x = calc(n)
    ans.append(x)
    n -= x
    if x > n:
        ans.append(n)
        break

print(*ans, sep="\n")


Fixed, accepted submission:
N = int(input())
x = 1
for _ in range(100000):
    if (x + 2) * (x + 1) // 2 > N:
        break
    x += 1

H = [i for i in range(x, 0, -1)]
dif = N - sum(H)

for i in range(dif):
    H[(i) % len(H)] += 1

print(*sorted(H), sep="\n")
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-

import math
a, b = map(str, input().split())
c=a+b
c=int(c)

if(isinstance(math.sqrt(c),int)):
  print("Yes")
else: 
  print("No")

Fixed, accepted submission:
# -*- coding: utf-8 -*-

import math
a, b = map(str, input().split())
c=a+b
c=int(c)

if(math.sqrt(c).is_integer()):
  print("Yes")
else: 
  print("No")
Problem:
Write a program which reads an integer and prints sum of its digits.

Incorrect submission (verdict: Wrong Answer):
def main():

    while True:
        number_string = input()
        if number_string == '0': break
        print(list(number_string))
        print(sum(map(int, list(number_string))))
    
main()

Fixed, accepted submission:
def main():

    while True:
        number_string = input()
        if number_string == '0': break
        print(sum(map(int, list(number_string))))
    
main()
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):
# coding: utf-8

import sys
import math

def main(s):
    n = s[0]
    a = s[1]
    b = s[2]
    
    if not(n.isdigit()) or int(n) <= 0 or int(n) > 100:
        return -1
    if not(a.isdigit()) or int(n) < 0 or int(a) > int(n):
        return -1
    if not(b.isdigit()) or int(b) < 0 or int(b) > int(n):
        return -1

    n = int(n)
    a = int(a)
    b = int(b)

    reta = a
    retb = (n - a) - b
    if retb > 0 :
        retb = 0
    else:
        retb = abs(retb)

    print('{reta} {retb}'.format(reta=reta,retb=retb))
    
    return 0

if __name__ == '__main__':
    args = sys.argv
    if len(args) > 1:
        s = args[1:]
        main(s)


Fixed, accepted submission:
# coding: utf-8

import sys
import math

args = input().split()

n = int(args[0])
a = int(args[1])
b = int(args[2])

reta = a
retb = (n - a) - b

if retb > 0:
  retb = 0
else:
  retb = abs(retb)

print('{reta} {retb}'.format(reta=min(a,b),retb=retb))

sys.exit(0)
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
N=int(input())
M=N%1000
print(M)

Fixed, accepted submission:
N=int(input())
if N%1000==0:
    print("0")
else:
    print(1000-(N%1000))
Problem:
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.

Incorrect submission (verdict: Wrong Answer):
a, b = map(int,input().split())
if a * b % 2:
    print('odd')
else:
    print('even')


Fixed, accepted submission:
a, b = map(int,input().split())
if a * b % 2:
    print('Odd')
else:
    print('Even')
Problem:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.    An example of a trapezoid  Find the area of this trapezoid.

Incorrect submission (verdict: Wrong Answer):
a = input()
b = input()
c = input()
a = a.replace("a","")
b = b.replace("b","")
c = c.replace("c","")
turn = 'a'
for i in range(500):
	if turn == 'a':
		if int(len(a)) == 0:
			print("A")
			break
		else:
			turn = str(a[0])
			a = a[1:]
	if turn == 'b':
		if int(len(b)) == 0:
			print('B')
			break
		else:
			turn = str(b[0])
			b = b[1:]
	if turn == 'c':
		if int(len(c)) == 0:
			print('C')
			break
		else:
			turn = str(c[0])
			c = c[1:]

Fixed, accepted submission:
a = int(input())
b = int(input())
h = int(input())
print(int((a + b)*h/2))
Problem:
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b.  The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.

Incorrect submission (verdict: Wrong Answer):
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        print(a/b)

Fixed, accepted submission:
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        print(a//b)
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):
import itertools

H, W = map(int, input().split())
S = []
ans = []
for _ in range(H):
    S.append(list(input()))
    ans.append(['

op =[]
for i in itertools.product([-1, 0, 1], repeat=2):
    op.append(i)


for i, s1 in enumerate(S):
    for j, s2 in enumerate(s1):
        if(s2 == '.'):
            counter = 0
            for o in op:
                print(i,j,o)
                if(i == 0 and o[0] == -1):
                    continue
                elif(i == H-1 and o[0] == 1):
                    continue
                elif(j == 0 and o[1] == -1):
                    continue
                elif(j == W-1 and o[1] == 1):
                    continue
                else:
                    if(S[i + o[0]][j + o[1]] == "#"):
                        counter += 1
            ans[i][j] = str(counter)

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

Fixed, accepted submission:
def myAnswer(H:int,W:int,S:list) -> None:
   XY = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
   index = []
   ans = [[0]*W for _ in range(H)]
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):
            ans[i][j] = "#"
            index.append([i,j])
   for i,j in index:
      for x,y in XY:
         if(0 > (j + x) or (j + x) >= W or 0 > (i + y) or (i + y) >= H):
            continue
         elif(ans[y+i][x+j]== "#"):
            continue
         else:
            ans[y + i][x + j] += 1
   for a in ans:
      string = ""
      for s in a:
         string += str(s)
      print(string)

def modelAnswer(H:int,W:int,S:list) -> int:
   dx = [1,0,-1,0,1,-1,-1,1]
   dy = [0,1,0,-1,1,1,-1,-1]
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):continue

         num = 0
         for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            if(ni < 0 or H <= ni):continue
            if(nj < 0 or W <= nj):continue
            if(S[ni][nj] == "#"): num+=1
         
         S[i][j] = str(num )
   for s in S:
      ans = ""
      for a in s:
         ans += a
      print(ans)
def main():
   H,W = map(int,input().split())
   S = [list(input()) for _ in range(H)]
   myAnswer(H,W,S[:])
if __name__ == '__main__':
   main()
Problem:
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.  Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.  Here, the distance between two points s and t on a number line is represented by |s-t|.

Incorrect submission (verdict: Wrong Answer):
location_list = list(map(int, input().split()))

ax_length = abs(location_list[0] - location_list[1])
bx_length = abs(location_list[0] - location_list[2])

if ax_length > bx_length:
    print('A')
else:
    print('B')


Fixed, accepted submission:
location_list = list(map(int, input().split()))

ax_length = abs(location_list[0] - location_list[1])
bx_length = abs(location_list[0] - location_list[2])

if ax_length < bx_length:
    print('A')
else:
    print('B')
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: Wrong Answer):
x = int(input())

maxInt = 1

i = 2
while i * i <= x:
	exp = i * i
	while exp <= x:
		exp *= i
	else:
		maxInt = max(maxInt, exp)
		i += 1
print(maxInt)

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

maxInt = 1

i = 2
while i * i <= x:
	exp = i * i
	while exp <= x:
		exp *= i
	else:
		maxInt = max(maxInt, exp // i)
		i += 1
print(maxInt)
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 = float(input())
g = float(input())

t = 2*g -r

print(t)

Fixed, accepted submission:
r = int(input())
g = int(input())

t = 2*g -r

print(t)
Problem:
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.  The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.  Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.

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

if S.count("o") >= 8:
  print("Yes")
else:
  if 15 - len(S) + S.count("o") >= 8:
    print("Yes")
  else:
    print("No")


Fixed, accepted submission:
S = list(str(input()))

if S.count("o") >= 8:
  print("YES")
else:
  if 15 - len(S) + S.count("o") >= 8:
    print("YES")
  else:
    print("NO")
Problem:
Snuke loves working out. He is now exercising N times.  Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i.  Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
pow = 1
for i in range(1,N+1):
        pow = pow*i
num = 10**9+7
print(pow%num)
print(pow)

Fixed, accepted submission:
N = int(input())
pow = 1
num = 10**9+7
for i in range(1,N+1):
        pow = pow*i%num
print(pow%num)
Problem:
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:    * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.

Incorrect submission (verdict: Wrong Answer):
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'Yes'
while True:
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'No'
        break
    break
print(can)


Fixed, accepted submission:
s = input()[::-1]
words = [w[::-1] for w in ['dream', 'dreamer', 'erase', 'eraser']]

can = 'YES'
while s:
    match_any = False
    for w in words:
        if s.startswith(w):
            s = s.replace(w, '', 1)
            match_any = True
            break
    if not match_any:
        can = 'NO'
        break
print(can)
Problem:
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.  You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.  Find B_i for each i = 1, 2, ..., N.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
lst_x = list(map(int, input().split()))
lst_x.sort()
b1 = lst_x[n//2 - 1]
b2 = lst_x[n//2]


for x in lst_x:
    if x <= b1:
        ans = b2
    else:
        ans = b1
    print(ans)

Fixed, accepted submission:
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    print(b2 if x <= b1 else b1)
Problem:
Write a program which performs a sequence of commands to a given string $str$. The command is one of:    * print a b: print from the a-th character to the b-th character of $str$   * reverse a b: reverse from the a-th character to the b-th character of $str$   * replace a b p: replace from the a-th character to the b-th character of $str$ with p  Note that the indices of $str$ start with 0.

Incorrect submission (verdict: Wrong Answer):
sen = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    sta = int(cmd[1])
    end = int(cmd[2])
    if len(cmd) == 4:
        sen = sen[0:sta] + cmd[3] + sen[end+1:]
    elif cmd[0] == 'reverse':
        rev = sen[end+1:sta:-1]
        sen = sen[0:sta] + rev +sen[end+1:]
    elif cmd[0] == 'print':
        print(sen[sta:end+1])

Fixed, accepted submission:
sen = input()
n = int(input())
for i in range(n):
    cmd = input().split()
    sta = int(cmd[1])
    end = int(cmd[2])
    if cmd[0] == 'replace':
        sen = sen[0:sta] + cmd[3] + sen[end+1:]
    elif cmd[0] == 'reverse':
        rev = sen[sta:end+1]
        rev = rev[::-1]
        # print(rev)
        sen = sen[0:sta] + rev +sen[end+1:]
    elif cmd[0] == 'print':
        print(sen[sta:end+1])
Problem:
E869120 has A 1-yen coins and infinitely many 500-yen coins.   Determine if he can pay exactly N yen using only these coins.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
while True:
    N = int(input("N = "))
    A = int(input("A = "))
    if (N >= 1 and N <= 10000) and (A >= 0 and A <= 1000):
        break

if (N / 500) > 0:
    x = N % 500
    if A >= x:
        print('Yes')
    else:
        print('No')
else:
    if A >= N:
        print('yes')
    else:
        print('No')


Fixed, accepted submission:
# -*- coding: utf-8 -*-
while True:
    N = int(input())
    A = int(input())
    if (N >= 1 and N <= 10000) and (A >= 0 and A <= 1000):
        break

if (N / 500) > 0:
    x = N % 500
    if A >= x:
        print('Yes')
    else:
        print('No')
else:
    if A >= N:
        print('yes')
    else:
        print('No')
Problem:
You went shopping to buy cakes and donuts with X yen (the currency of Japan).  First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.  How much do you have left after shopping?

Incorrect submission (verdict: Wrong Answer):
X,A,B=[int(input()) for i in range(3)]
x=0
XX=X-A
while XX>0:
    XX-=B
    print(XX)
    x+=1

print(X-A-B*(x-1))

Fixed, accepted submission:
X,A,B=[int(input()) for i in range(3)]
x=0
XX=X-A
while XX>=0:
    XX-=B
    x+=1

print(X-A-B*(x-1))
Problem:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`.  After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.

Incorrect submission (verdict: Wrong Answer):
S=input()
S[4],print('8')

Fixed, accepted submission:
S=input()
print("2018"+S[4:])
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = [i for i in str(input())]

print("AC x " + str(S.count('AC')))
print("WA x " + str(S.count('WA')))
print("TLE x " + str(S.count('TLE')))
print("RE x " + str(S.count('RE')))


Fixed, accepted submission:
N = int(input())
S = ["00"]
for i in range(N):
    S.append(str(input()))

print("AC x " + str(S.count('AC')))
print("WA x " + str(S.count('WA')))
print("TLE x " + str(S.count('TLE')))
print("RE x " + str(S.count('RE')))