TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}.  Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.

Incorrect submission (verdict: Wrong Answer):
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)

def E():
    s1 = input()
    s2 = input()
    if s1 == s2[::-1]:
        print('Yes')
    else:
        print('No')
E()


Fixed, accepted submission:
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)

def E():
    s1 = input()
    s2 = input()
    if s1 == s2[::-1]:
        print('YES')
    else:
        print('NO')
E()
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):
str_s = input()
str_t = input()

str_s_d = sorted(str_s)
str_t_d = sorted(str_t, reverse=True)

print(str_s_d)
print(str_t_d)

if str_s_d < str_t_d:
    print("Yes")
else:
    print("No")

Fixed, accepted submission:
str_s = input()
str_t = input()

str_s_d = sorted(str_s)
str_t_d = sorted(str_t, reverse=True)

if str_s_d < str_t_d:
    print("Yes")
else:
    print("No")
Problem:
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?  Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Incorrect submission (verdict: Wrong Answer):
import re  
import sys 


def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))


def check(x, a, b, c):
    diff = x - 500 * a - 100 * b
    if diff >= 0 and diff % 50 == 0 and diff // 50 <= c:
        print(a,b,diff // 50)
        return True
    else:
        return False

def main():
    a = i_input() # 500
    b = i_input() # 100
    c = i_input() # 50
    x = i_input() # sum

    count = 0
    for i in range(a + 1):
        for j in range(b + 1):
            if check(x, i, j, c):
                count += 1

    print(count)

if __name__ == "__main__":
    main()


Fixed, accepted submission:
import re  
import sys 


def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))


def check(x, a, b, c):
    diff = x - 500 * a - 100 * b
    if diff >= 0 and diff % 50 == 0 and diff // 50 <= c:
        return True
    else:
        return False

def main():
    a = i_input() # 500
    b = i_input() # 100
    c = i_input() # 50
    x = i_input() # sum

    count = 0
    for i in range(a + 1):
        for j in range(b + 1):
            if check(x, i, j, c):
                count += 1

    print(count)

if __name__ == "__main__":
    main()
Problem:
A Hitachi string is a concatenation of one or more copies of the string `hi`.  For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not.  Given a string S, determine whether S is a Hitachi string.

Incorrect submission (verdict: Wrong Answer):
a = list(map(str, input().split()))
num = len(a)
TorF = True

if num % 2 == 0:
    for i in range(num/2):
        if not a(2*i ) == 'h' and a(2*i + 1) == 'i':
            TorF = False
            break
else:
  TorF = False
  
if TorF == True:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
a = input()
l = list(a)
num = len(l)
TorF = True

if num % 2 == 0:
    b = int(num/2)
    for i in range(b):
        if not (a[2*i] == 'h' and a[2*i + 1] == 'i'):
            TorF = False
            break
else:
    TorF = False

if TorF == True:
    print('Yes')
else:
    print('No')
Problem:
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.  Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode:                 BubbleSort(C) 1 for i = 0 to C.length-1 2     for j = C.length-1 downto i+1 3         if C[j].value < C[j-1].value 4             swap C[j] and C[j-1]                 SelectionSort(C) 1 for i = 0 to C.length-1 2     mini = i 3     for j = i to C.length-1 4         if C[j].value < C[mini].value 5             mini = j 6     swap C[i] and C[mini]   Note that, indices for array elements are based on 0-origin.  For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Incorrect submission (verdict: Wrong Answer):
def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(range(1,n)):
            if(c[i][1] < c[i-1][1]):
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c

def selectionSort(c,n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if(c[j][1] < c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c

def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True

n = int(input())
c = input().split(' ')
trump = [list(i) for i in c]
bubble = ["".join(s) for s in bubbleSort(trump, n)]
selection = ["".join(s) for s in selectionSort(trump, n)]
str_bubble = " ".join(bubble)
str_selection = " ".join(selection)
print(str_bubble)
print('Stable')
print(str_selection)
if isStable(bubble, selection, n):
    print('Stable')
else:
    print('Not stable')



Fixed, accepted submission:
def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(range(1,n)):
            if(c[i][1] < c[i-1][1]):
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c

def selectionSort(c,n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if(c[j][1] < c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c

def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True

n = int(input())
c = input().split(' ')
trump = [list(i) for i in c]
bubble = ["".join(s) for s in bubbleSort(trump, n)]
trump = [list(i) for i in c]
selection = ["".join(s) for s in selectionSort(trump, n)]
str_bubble = " ".join(bubble)
str_selection = " ".join(selection)
print(str_bubble)
print('Stable')
print(str_selection)
if isStable(bubble, selection, n):
    print('Stable')
else:
    print('Not stable')
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=map(int,input().split())
m=[[0for _ in range(w+2)]for _ in range(h+2)]
for y in range(h):
  s=input()
  for x in range(w):
    if s[x]=="#":
      for i in [-1,0,1]:
        for j in [-1,0,1]:
          m[y+j][x+i]+=1
      m[y+1][x+1]=9
for y in range(1,h+1):
  ans=""
  for x in range(1,w+1):
    if m[y][x]>9:
      ans+="#"
    else:
      ans+=str(m[y][x])
  print(ans)

Fixed, accepted submission:
h,w=map(int,input().split())
m=[[0for _ in range(w+2)]for _ in range(h+2)]
for y in range(h):
  s=input()
  for x in range(w):
    if s[x]=="#":
      for i in [0,1,2]:
        for j in [0,1,2]:
          m[y+j][x+i]+=1
      m[y+1][x+1]=9
for y in range(1,h+1):
  ans=""
  for x in range(1,w+1):
    if m[y][x]>8:
      ans+="#"
    else:
      ans+=str(m[y][x])
  print(ans)
Problem:
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.

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

x = 0

while a > b:
    
    if c % a == 0:
        x = x + 1




Fixed, accepted submission:
a, b, c = map(int, input().split())

x = 0

for i in range(a, b+1):
    
    if c % i == 0:
        x += 1

print(x)
Problem:
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.  To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

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

if 7 in N:
    N.remove(7)
    if 5 in N:
        if sum(N) == 10:
            print("Yes")
            exit()
print("No")

Fixed, accepted submission:
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

# N = list(map(int,input().split()))
N = list(map(int,input().split()))
N.sort()
if sum(N)==17 and int(N[0]) == int(N[1]) == 5:
    print('YES')
else:
    print("NO")
Problem:
An elementary school student Takahashi has come to a variety store.  He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?  Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

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

Fixed, accepted submission:
a,b,c = map(int,input().split())
if a + b >= c:
    print("Yes")
else:
    print("No")
Problem:
It is September 9 in Japan now.  You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

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

if n[0] == 9 or n[1] == 9:
  prnit("Yes")
else:
  print("No")

Fixed, accepted submission:
n = input()
 
if n[0] == "9" or n[1] == "9":
  print("Yes")
else:
  print("No")
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):
a, g, b = map(int, input().split())

num = a*100 + g*10 + b

if num % 4 == 0:
  print('Yes')
else:
  print('No')


Fixed, accepted submission:
r, g, b = map(int, input().split())

num = r*100 + g*10 + b

if num % 4 == 0:
  print('YES')
else:
  print('NO')
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):
N = int(input())
K = int(input())
i = 1
for num in range(N):
  if i < K:
    i *= 2
  else:
    i += K
print (i)

Fixed, accepted submission:
R = int(input())
G = int(input())
print (2*G - R)
Problem:
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:    * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.  Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.

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


for i in range(K):
    if i % 2 == 0:  
        if A % 2 == 1:
            A -= 1

        B += A // 2
        A = A // 2
    else:   
        if B % 2 == 1:
            B -= 1

        A += B // 2
        B = B // 2

    print(A, B)

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


for i in range(K):
    if i % 2 == 0:  
        if A % 2 == 1:
            A -= 1

        B += A // 2
        A = A // 2
    else:   
        if B % 2 == 1:
            B -= 1

        A += B // 2
        B = B // 2

print(A, B)
Problem:
You are given three integers A, B and C.  Determine if there exists an equilateral triangle whose sides have lengths A, B and C.

Incorrect submission (verdict: Wrong Answer):
A,B,C = list(map(int, input().split()))
if A==B and B==C:
	print("yes")
else:
	print("No")

Fixed, accepted submission:
A,B,C = list(map(int, input().split()))
if A==B and B==C:
	print("Yes")
else:
	print("No")
Problem:
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s).  Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.

Incorrect submission (verdict: Wrong Answer):
l = list(input())

for i in range(len(l)):
  if l[i] == "A":
    a = i
    break
for i in range(len(l)):
  if l[-1-i] == "Z":
    b = i
    break
print(b-a+1)

Fixed, accepted submission:
l = list(input())

for i in range(len(l)):
  if l[i] == "A":
    a = i
    break
for i in range(len(l)):
  if l[-1-i] == "Z":
    b = len(l)-i
    break
print(b-a)
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()
flag = 0
while True:
    if S.startswith("dream") or S.startswith("erase"):
        S = S[5:]
        if S.startswith("ase"):
            S = S[3:]
        if S.startswith("aser"):
            S = S[4:]
    if S.startswith("dreamer"):
        S = S[7:]
    if S.startswith("eraser"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")


Fixed, accepted submission:
S = input()
flag = 0
S = S[::-1]
while True:
    if S.startswith("maerd") or S.startswith("esare"):
        S = S[5:]
    elif S.startswith("remaerd"):
        S = S[7:]
    elif S.startswith("resare"):
        S = S[6:]
    elif S == "":
        break
    else:
        flag = 1
        break
print("YES" if flag == 0 else "NO")
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 == 1:
  print('Odd')
else:
  print('Even')
Problem:
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:                 for i = 1 to A.length-1     key = A[i]     /* insert A[i] into the sorted sequence A[0,...,j-1] */     j = i - 1     while j >= 0 and A[j] > key         A[j+1] = A[j]         j--     A[j+1] = key   Note that, indices for array elements are based on 0-origin.  To illustrate the algorithms, your program should trace intermediate result for each step.

Incorrect submission (verdict: Wrong Answer):
N=int(input("N"))
A=[0]*N
A=input().split()
print(A)
for i in range(1,len(A)):
    j = i
    while (j > 0) and (A[j-1] > A[j]) :
        tmp = A[j-1]
        A[j-1] = A[j]
        A[j] = tmp
        j -= 1
    print(A)


Fixed, accepted submission:
n=int(input())
a=input().split()
for i in range(n):
 k=int(a[i])
 j=i-1
 while j>=0 and int(a[j])>k:
  a[j+1]=a[j]
  j-=1
 a[j+1]=k
 print(*a)
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 = int(input())
b = int(input())
h = int(input())
print((a+b)*(h/2))


Fixed, accepted submission:
a = int(input())
b = int(input())
h = int(input())
print(((a+b)*h)//2)
Problem:
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.  To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:    * The `0` key: a letter `0` will be inserted to the right of the string.   * The `1` key: a letter `1` will be inserted to the right of the string.   * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.  Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?

Incorrect submission (verdict: Wrong Answer):
s = input()
ans = []
for i in s:
  if i == "B":
    if ans:
      ans.pop()
  else:
    ans.append(i)
print(*ans)

Fixed, accepted submission:
s = input()
ans = ""
for i in s:
  if i == "B":
    ans = ans[:-1]
  else:
    ans += i
print(ans)
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())

def f(x):
    sum = 0
    while x > 0:
        sum += x % 10
        x //= 10
    return sum

count = 0
for i in range(N):
    if A <= f(i+1) <= B:
        count += i

print(count)


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

def f(x):
    sum = 0
    while x > 0:
        sum += x % 10
        x //= 10
    return sum

count = 0
for i in range(N):
    if A <= f(i+1) <= B:
        count += i+1

print(count)
Problem:
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

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

A = [0] + A + [0] 
kane = []
for i in range(1, N+2):
    kane.append(abs(A[i] - A[i-1]))
skane = sum(kane)

print(kane)

for i in range(1, N+1):
    print(skane - kane[i-1] - kane[i] + abs(A[i+1] - A[i-1]))

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

A = [0] + A + [0] 
kane = []
for i in range(1, N+2):
    kane.append(abs(A[i] - A[i-1]))
skane = sum(kane)

for i in range(1, N+1):
    print(skane - kane[i-1] - kane[i] + abs(A[i+1] - A[i-1]))
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):
# -*- coding: utf-8 -*-
import math

lastT, lastX, lastY = 0, 0, 0
flag = True

N = int(input())
for i in range(N):
    t, x, y = map(int, input().split())

    

    if ( t - lastT < math.fabs(x - lastX) + math.fabs(y - lastY)
        or ( (t - lastT) - math.fabs(x - lastX) - math.fabs(y - lastY) ) % 2 == 1 ):
        flag = False

    lastT = t
    lastX = x
    lastY = y

print(flag)


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

lastT, lastX, lastY = 0, 0, 0
flag = "Yes"

N = int(input())
for i in range(N):
    t, x, y = map(int, input().split())

    

    if ( t - lastT < math.fabs(x - lastX) + math.fabs(y - lastY)
        or ( (t - lastT) - math.fabs(x - lastX) - math.fabs(y - lastY) ) % 2 == 1 ):
        flag = "No"

    lastT = t
    lastX = x
    lastY = y

print(flag)
Problem:
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.  Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Incorrect submission (verdict: Wrong Answer):
s=input()
if "keyence" in s:exit(print("YES"))
for i in range(1,6):
  if s[:i]+s[-(6-i):]=="keyence":exit(print("YES"))
print("NO")

Fixed, accepted submission:
s=input()
if "keyence"==s:exit(print("YES"))
for i in range(10):
  for j in range(i,len(s)):
    if s[:i]+s[j:]=="keyence":exit(print("YES"))
print("NO")