TnT/CodeNet4Repair huggingface dataset:
Problem:
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater.  Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.

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

for i in range(q):
    x = list(input())
    y = list(input())
    max_count = 0
    for j in range(len(x)):
        for k in range(len(y)):
            count = 0
            if x[j] == y[k]:
                count += 1 
                ret = j
                ret_2 = k
                while j < len(x) -1 and k < len(y) -1:
                    j += 1
                    k += 1
                    if x[j] == y[k]:
                        count += 1
                    else:
                        break
                j = ret
                k = ret_2
                max_count = max(count,max_count)
    print(max_count)

Fixed, accepted submission:
q = int(input())
 
def lcss(x,y):
     
    lcs = [0]*(len(x)+1)
    for i in range(len(y)):
        w1 = y[i]
        lcs_2 = lcs[:]
        for j in range(len(x)):
            if x[j] == w1:
                lcs[j+1] = lcs_2[j] + 1  
            elif lcs[j+1] < lcs[j]:
                lcs[j+1] = lcs[j]
    return lcs[-1]
 
for i in range(q):
    x = input()
    y = input()
    print(lcss(x,y))
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

Incorrect submission (verdict: Wrong Answer):
a=int(input())
print(a/(60*60), end=':')
print(a%(60*60)/60, end=':')
print(a%(60*60*60))

Fixed, accepted submission:
a=int(input())
print(int(a/60/60), end=':')
print(int(a%(60*60)/60), end=':')
print(int(a%60))
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):
a=input()
while a!="0 ? 0":
    print(eval(a))
    a=input()


Fixed, accepted submission:
while 1:
  s=input()
  if s.split()[1]=="?":exit()
  print(int(eval(s)))
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

Incorrect submission (verdict: Wrong Answer):
print(38400/3600)

Fixed, accepted submission:
S = int(input()) 
print(S // 3600, ":", S % 3600 // 60, ":", S % 60, sep = "")
Problem:
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.  The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).  Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.  If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x = n//1.08 + 1
m = x*1.08//1
if n==m:
  print(x)
else:
  print(':(')

Fixed, accepted submission:
n = int(input())
for x in range(46297):
  if (x+1)*1.08//1 == n:
    print(x+1)
    break
  if x == 46296:
    print(':(')
Problem:
Joisino is working as a receptionist at a theater.  The theater has 100000 seats, numbered from 1 to 100000.  According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).  How many people are sitting at the theater now?

Incorrect submission (verdict: Wrong Answer):
N = int(input())
total = 0
for i in range(N):
  l, r = map(int, input().split())
  total += l - r + 1
print(total)

Fixed, accepted submission:
N = int(input())
total = 0
for i in range(N):
  l, r = map(int, input().split())
  total += r - l + 1
print(total)
Problem:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.  The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.  Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.  Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
edges = [[0 for _ in range(n)] for _ in range(n)]
mem = [[0 for _ in range(n)] for _ in range(n)]
dist = []

for i in range(n):
    edges[i][int(input())-1] = 1

for i in range(n):
    print(''.join([str(e) for e in edges[i]]))


def has_edge(edges, v, t, d):
    targets = [i for i, e in enumerate(edges[v]) if e != 0]
    for target in targets:
        if mem[v][target] == 0:
            mem[v][target] = 1
            if target == t:
                dist.append(d)
                return True
            else:
                return has_edge(edges, target, t, d+1)
    return False


print(min(dist)+1) if has_edge(edges, 0, 1, 0) else print(-1)

Fixed, accepted submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))
Problem:
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

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

if len(S)==2:
    print(S)
else:
    print(list(reversed(S)))


Fixed, accepted submission:
S=input()

if len(S)==2:
    print(S)
else:
    print(''.join(list(reversed(S))))
Problem:
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`.  You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int,input().split())
s = input()
sw = 0
for i in range(len(s)):
    if i == a and s[i] != '-':
        sw = 1
    elif i != a and s[i] == '-':
        sw = 1
    else:
        pass
if sw == 1:
    print('No')
else:
    print('Yse')

Fixed, accepted submission:
a,b = map(int,input().split())
s = input()
sw = 0
for i in range(len(s)):
    if i == a and s[i] != '-':
        sw = 1
    elif i != a and s[i] == '-':
        sw = 1
    else:
        pass
if sw == 1:
    print('No')
else:
    print('Yes')
Problem:
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?  Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:    * r_1 + c_1 = r_2 + c_2   * r_1 - c_1 = r_2 - c_2  For example, in the following figure, the bishop can move to any of the red squares in one move:  

Incorrect submission (verdict: Wrong Answer):
h, w = map(int, input().split())
ans = h * w
if ans % 2 == 1:
    print(ans//2+1)
else:
    print(ans/2)

Fixed, accepted submission:
h, w = map(int, input().split())
if h == 1 or w == 1:
    ans = 1
elif h % 2 == 0 or w % 2 == 0:
    ans = h * w // 2
else:
    ans = h * w // 2 + 1
print(ans)
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.replace("2017","2018")
print(s)

Fixed, accepted submission:
s = input()
s = s.replace("2017","2018")
print(s)
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())

print(N%1000)

Fixed, accepted submission:
N = int(input())
 
print((1000 - (N%1000))%1000)
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):
x, a, b = map(int, input().split())

if abs(a - x) > abs(b - x):
  print('A')
else:
  print('B')  

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

if abs(a - x) > abs(b - x):
  print('B')
else:
  print('A')
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())

nx = 0
ny = 0
nt = 0
for _ in range(N):
    t, x, y = map(int, input().split())
    k = abs(nx-x)+abs(ny-y)
    if k > t:
        print("No")
        break
    if (k-t)%2 != 0:
        print("No")
        break
    nx = x
    ny = y
    nt = t
else:
    print("Yes")

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

nx = 0
ny = 0
nt = 0
for _ in range(N):
    t, x, y = map(int, input().split())
    k = abs(nx-x)+abs(ny-y)
    if k > t-nt:
        print("No")
        break
    if (k-(t-nt))%2 != 0:
        print("No")
        break
    nx = x
    ny = y
    nt = t
else:
    print("Yes")
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):
r,g,b=map(int,input().split())
if (100*r+10*g+b)%4==0:
  print("Yes")
else:
  print("No")

Fixed, accepted submission:
r,g,b=map(int,input().split())
if (100*r+10*g+b)%4==0:
  print("YES")
else:
  print("NO")
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=input().split()
if set(a)==a:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
a=input().split()
if len(set(a))==1:
    print('Yes')
else:
    print('No')
Problem:
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.

Incorrect submission (verdict: Wrong Answer):
#GCD and LCM

while True:
    try:
        a, b = (int(i) for i in input(). split())
        x = a * b
        while True:
            c = a % b
            a = b
            b = c
            if a % b == 0:
                break
        x = x / a
        print("%d %d" % (b, x))
    except:
        break

Fixed, accepted submission:
def main():
    gcd = lambda n, m : gcd(m, n % m) if m != 0 else n
    while True:
        try:
            n, m = map(int, input().split())

            g = gcd(n, m)
            l = n * m // g

            print(g, l)
        except:
            break

if __name__ == '__main__':
    main()
Problem:
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives.  You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative.  For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins.  If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x = []
ans = 0
for i in range(n):
  array = list(map(str,input().split()))
  x.append(array)
  if x[i][1] == "JPY":
  	ans += int(x[i][0])
  else:
  	ans += int(float(x[i][0]) * 380000)
print(ans)


Fixed, accepted submission:
n = int(input())
x = []
ans = 0
for i in range(n):
  array = list(map(str,input().split()))
  x.append(array)
  if x[i][1] == "JPY":
  	ans += int(x[i][0])
  else:
  	ans += float(x[i][0]) * 380000
print(ans)
Problem:
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N).  In particular, any integer sequence is similar to itself.  You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N.  How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?

Incorrect submission (verdict: Wrong Answer):
n=int(input())
s=input().split()
x=1
for i in s:
 if(int(i)%2==0):
  x*=2
print(2**n-x)

Fixed, accepted submission:
n=int(input())
s=input().split()
x=1
for i in s:
 if(int(i)%2==0):
  x*=2
print(3**n-x)
Problem:
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied:    * Each lowercase letter of the English alphabet occurs even number of times in w.  You are given the string w. Determine if w is beautiful.

Incorrect submission (verdict: Wrong Answer):
w = input()
flag = 0

for j in range(0,len(w)):
    sum = 0
    for i in range(0,len(w)):
        if w[j] == w[i]:
            sum += 1
    if sum % 2 != 0:
        print("NO")
        flag = 1
        break

if flag == 0:
    print("YES")

Fixed, accepted submission:
from collections import Counter

w = input()
flag = 0

counter = Counter(w)

for word, cnt in counter.most_common():
    if cnt % 2 != 0:
        flag = 1

if flag == 0:
    print("Yes")
else:
    print("No")
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):
import re

s = input()
print('Yes' if re.match('^(dream|dreamer|erase|eraser)+$', s) else 'No')

Fixed, accepted submission:
import re

s = input()
print('YES' if re.match('^(dream|dreamer|erase|eraser)+$', s) 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())
print('Even' if a*b%2 == 0 else 'Odd')
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):
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
if N<=K:
    print(X)
else:
    print(Y)

Fixed, accepted submission:
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
if N<=K:
    print(X*N)
else:
    print(X*(K)+Y*(N-K))
Problem:
Takahashi loves numbers divisible by 2.  You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.  Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.  For example,    * 6 can be divided by 2 once: 6 -> 3.   * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.   * 3 can be divided by 2 zero times.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
ans = 0
for i in range(100):
    if N%2 == 0:
        ans += 1
    else:
        print(ans)
        exit()

Fixed, accepted submission:
N = int(input())
if N == 1:
    print(1)
    exit()
for i in range(8):
    if 2**i > N:
        print(2**(i-1))
        exit()
Problem:
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.  They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card.  Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.

Incorrect submission (verdict: Wrong Answer):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
    s += a[i]
    Min = min(Min, abs(2 * s- total))


Fixed, accepted submission:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
    s += a[i]
    Min = min(Min, abs(2 * s- total))
print(Min)
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):
import numpy as np
n=int(input())
l=list(map(int,input().split()))

arr=np.sort(np.array(l))
med=np.median(arr)

med_max=np.median(np.delete(arr,0))
med_min=np.median(np.delete(arr,n-1))

if n%2==1:
    p=(n-1)//2
    med_midmin=np.median(np.delete(arr,p+1))
    med_mid=np.median(np.delete(arr,p))
    med_midmax=np.median(np.delete(arr,p-1))

    for i in range(n):
        if l[i]<arr[p-1]:
            print(med_max)
        elif l[i]==arr[p-1]:
            print(med_midmax)
        elif l[i]==arr[p]:
            print(med_mid)
        elif l[i]==arr[p+1]:
            print(med_midmin)
        else:
            print(med_min)

if n%2==0:
    p=(n+1)//2
    med_midmin=np.median(np.delete(arr,p))
    med_midmax=np.median(np.delete(arr,p-1))
    for i in range(n):
        if l[i]<arr[p-1]:
            print(med_max)
        elif l[i]==arr[p-1]:
            print(med_midmax)
        elif l[i]==arr[p]:
            print(med_midmin)
        else:
            print(med_min)

Fixed, accepted submission:
import numpy as np
n=int(input())
l=list(map(int,input().split()))

arr=np.sort(np.array(l))
med=np.median(arr)

med_max=int(np.median(np.delete(arr,0)))
med_min=int(np.median(np.delete(arr,n-1)))


p=(n+1)//2
for i in range(n):
    if l[i]<=arr[p-1]:
        print(med_max)
    else:
        print(med_min)
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());print(max(a+b,b+c,a+c))

Fixed, accepted submission:
a,b,c=map(int,input().split());print(min(a+b,b+c,a+c))
Problem:
There is a cave.  The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.  It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.  Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.    * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.  Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Incorrect submission (verdict: Wrong Answer):
print('No')

Fixed, accepted submission:
from collections import deque
n, m = map(int, input().split())
dir = [[] for _ in range(n+1)]

for i in range(m):
    ta, tb = map(int, input().split())
    dir[ta].append(tb)
    dir[tb].append(ta)

ans = [0]*(n+1)
flag = [False]*(n+1)
flag[1] = True
que = deque([1])
while que:
    
    now = que.popleft()
    for to in dir[now]:
        if flag[to]:
            continue
        que.append(to)
        flag[to] = True
        ans[to] = now

print('Yes')
for i in range(2,n+1):
    print(ans[i])