TnT/CodeNet4Repair huggingface dataset:
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):
def insertion_sort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1

        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)

    return A

N = int(input())
A = list(map(int, input().split()))

A = insertion_sort(A, N)
print(*A)

Fixed, accepted submission:
def insertion_sort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        print(*A)

        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v

    return A

N = int(input())
A = list(map(int, input().split()))

A = insertion_sort(A, N)
print(*A)
Problem:
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.  Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.  Find the maximum possible sum of the values of items that Taro takes home.

Incorrect submission (verdict: Wrong Answer):
num, capacity = list(map(int, input().split()))
actions = [[0 for i in range(capacity + 1)]]
for i in range(num):
    actions.append(list(map(int, input().split())))

dp = [[0 for i in range(capacity + 1)] for j in range(num + 1)]
for i in range(1, num + 1):
    for w in range(capacity + 1):
        if w - actions[i][0] >= 0:
            if w <= capacity:
                dp[i][w] = max( dp[i-1][w - actions[i][0]] + actions[i][1],  dp[i-1][w] )
            else:
                dp[i][w] = dp[i-1][w]
print(max( dp[num] ))

Fixed, accepted submission:
def calc(num,capacity):
    dp = [0]*(capacity+1)
    for _ in range(num):
        weight, value = map(int, input().split())
        for w in range(capacity,weight - 1,-1):
            tmp = dp[w - weight] + value
            if dp[w] < tmp:
              dp[w] = tmp
    return dp[capacity]

num, capacity = map(int, input().split())
print(calc(num,capacity))
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())


l = [list(map(int,input().split())) for i in range(n)]

judge = "No"


l.insert(0,[0,0,0])
for i in range(n):
    
    n_j = (l[i+1][0]-l[i][0])%2==1
    xy = (l[i+1][1]+l[i+1][2])-(l[i][1]+l[i][2])
    if n_j==xy%2 & n_j>=xy:
        judge = "Yes"
    else:
        judge ="No"
        break


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


l = [list(map(int,input().split())) for i in range(n)]

judge = 'No'


l.insert(0,[0,0,0])
for i in range(n):
    
    dt = l[i+1][0]-l[i][0]
    n_j = dt%2
    xy = (l[i+1][1]+l[i+1][2])-(l[i][1]+l[i][2])
    if n_j==xy%2 and dt>=abs(xy):
        judge = 'Yes'
    else:
        judge ='No'
        break

print(judge)
Problem:
Niwango-kun is an employee of Dwango Co., Ltd.   One day, he is asked to generate a thumbnail from a video a user submitted.   To generate a thumbnail, he needs to select a frame of the video according to the following procedure:    * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video.   * Select t-th frame whose representation a_t is nearest to the average of all frame representations.   * If there are multiple such frames, select the frame with the smallest index.  Find the index t of the frame he should select to generate a thumbnail.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a_l = list(map(int, input().split()))
import numpy as np
ave_a = np.mean(a_l)
a_l2 = [  abs(a-ave_a) for a in a_l]
ans = 0
l = a_l2[0]
for idx, i in enumerate(a_l2[1:]):
    if l > i:
        ans = min(idx+1, ans)
print(ans)

Fixed, accepted submission:
n = int(input())
a_l = list(map(int, input().split()))
import numpy as np
ave_a = np.mean(a_l)
a_l2 = [ (i, abs(j-ave_a)) for i,j in enumerate(a_l) ]
a_l3 = sorted(a_l2, key=lambda x: x[1])
print(a_l3[0][0])
Problem:
We have N cards. A number a_i is written on the i-th card.   Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.   The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 0
sum1 = 0
sum2 = 0
for i in range(n):
	if cnt % 2 == 0:
		sum1 += a[i]
	else:
		sum2 += a[i]
print(sum1 - sum2)

Fixed, accepted submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
cnt = 0
sum1 = 0
sum2 = 0
for i in range(n):
	if cnt % 2 == 0:
		sum1 += a[i]
	else:
		sum2 += a[i]
	cnt += 1
print(sum1 - sum2)
Problem:
M-kun is a student in Aoki High School, where a year is divided into N terms.   There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:    * For the first through (K-1)-th terms: not given.   * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.  M-kun scored A_i in the exam at the end of the i-th term.   For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.

Incorrect submission (verdict: Wrong Answer):
n,k=map(int,input().split())
l=list(map(int,input().split()))
pr=1
t=[]
for i in range(len(l)):
    if i<k:
        pr*=l[i]
    else:
        t.append(pr)
        pr*=l[i]
        pr//=l[i-k]
t.append(pr)
print(t)
for i in range(len(t)-1):
    if t[i]<t[i+1]:
        print("Yes")
    else:
        print("No")
    

Fixed, accepted submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
pr=1
t=[]
for i in range(len(l)-k):
    if l[i]<l[i+k]:
        print("Yes")
    else:
        print("No")
Problem:
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.  Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.

Incorrect submission (verdict: Wrong Answer):
for i, x in enumerate(input()):
    if not x:
        break
    print('Case {0}: {1}'.format(i+1, x))

Fixed, accepted submission:
i=1
while(True):
    x = int(input())
    if not x:
        break
    print('Case {0}: {1}'.format(i, x))
    i+=1
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):
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())

Fixed, accepted submission:
a,b,c=map(int,input().split())
if a == b and b == c:
    print('Yes')
else:
    print('No')
Problem:
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

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

candy=N*(1+N)/2
print(candy)

Fixed, accepted submission:
N = int(input())
 
candy=(1+N)*N/2
print(int(candy))
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):
def main():
    N = int(input())
    money = 0
    for i in range(N):
        X,U = input().split()
        if U == 'JPY':
            money +=int(X)
        else:
            money += float(X)*38000
    print(money)
if __name__ =='__main__':
    main()


Fixed, accepted submission:
def main():
    N = int(input())
    money = 0
    for i in range(N):
        X,U = input().split()
        if U == 'JPY':
            money +=int(X)
        else:
            money += float(X)*380000
    print(money)
if __name__ =='__main__':
    main()
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):
S=input()

reverse_S=S[::-1]

while True:
    if (reverse_S.find('maerd')==0 or
        reverse_S.find('esare')==0
        ):
        reverse_S=reverse_S[5:]

    elif reverse_S.find('remaerd')==0:
        reverse_S=reverse_S[7:]
        
    elif reverse_S.find('resare')==0:
        reverse_S=reverse_S[6:]

    else:
        break

if len(reverse_S)==0:
    print('YES')
else:
    print('NO')

Fixed, accepted submission:
N=int(input())
t=[0]*100003
x=[0]*100003
y=[0]*100003

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

for i in range(1,N+1):
    dt=t[i]-t[i-1]
    dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if dist>dt:
        break
    else:
        pass
    if dist%2==dt%2:
        pass
    else:
        break
    count+=1
if count==N:
    print('Yes')
else:
    print('No')
Problem:
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.  Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N.  Find the minimum cost incurred before reaching the goal.

Incorrect submission (verdict: Wrong Answer):
n, m, x = map(int, input().split())
A = map(int, input().split())
r = 0
l = 0
for a in A:
	if a > x:
		r += 1
	else:
		l += 1
print(max(r, l))

Fixed, accepted submission:
n, m, x = map(int, input().split())
A = map(int, input().split())
r = 0
l = 0
for a in A:
	if a > x:
		r += 1
	else:
		l += 1
print(min(r, l))
Problem:
You are given a string S.  Takahashi can insert the character `A` at any position in this string any number of times.  Can he change S into `AKIHABARA`?

Incorrect submission (verdict: Wrong Answer):
import re
s = input()

if len(s) > 9:
    print ("No")
else:
    p = 'A?KIHA?BA?RA?'
    r = re.compile(p)
    result = r.match(s)
    if result:
        print ("Yes")
    else:
        print ("No")


Fixed, accepted submission:
import re
s = input()
 
if len(s) > 9:
    print ("NO")
else:
    p = 'A?KIHA?BA?RA?'
    r = re.compile(p)
    result = r.match(s)
    if result:
        print ("YES")
    else:
        print ("NO")
Problem:
A railroad running from west to east in Atcoder Kingdom is now complete.  There are N stations on the railroad, numbered 1 through N from west to east.  Tomorrow, the opening ceremony of the railroad will take place.  On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.  The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.  Here, it is guaranteed that F_i divides S_i.  That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.  For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

Incorrect submission (verdict: Wrong Answer):
def solve(n, CSF):
    
    times = [0] * n
    total = 0
    for i, (c, s, f) in enumerate(CSF):
        if total < s:
            total = s
        else:
            total += total % f
        total += c
        times[i] = total - times[i - 1]
    ret = [total - times[n - i - 1] for i in range(n)]
    return ret

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')

Fixed, accepted submission:
from math import ceil

def solve(n, CSF):
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] <= s:
                times[j] = s
            else:
                times[j] = s + ceil((times[j] - s) / f) * f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')
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 = 3
b = 4

if a % 2 == 0 and b % 2 == 0:
    print("Even")
else:
    print("Odd")


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

if a % 2 != 0 and b % 2 != 0:
    print("Odd")
else:
    print("Even")
Problem:
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.

Incorrect submission (verdict: Wrong Answer):
import math
a, b = map(int, input().split())
print(math.ceil(a+b))

Fixed, accepted submission:
import math
a, b = map(int, input().split())
print(math.ceil((a+b)/2))
Problem:
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.

Incorrect submission (verdict: Wrong Answer):

s = input()
arr = ['a', 'e', 'i', 'o', 'u']
for i in arr:
    if s == i:
        print("vowel")
    else:
        print("consonant")


Fixed, accepted submission:

s = input()
arr = ['a', 'e', 'i', 'o', 'u']
for i in arr:
    if s == i:
        print("vowel")
        exit(0)
print("consonant")
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):
#coding:utf-8
n, a, b = map(int, input().split())
ans = 0

for i in range(1, n+1):
    num = sum(map(int, str(i)))
    if num >= a and num <= b:
        ans += num
print(ans)

Fixed, accepted submission:
#coding:utf-8
n, a, b = map(int, input().split())
ans = 0

for i in range(1, n+1):
    num = sum(map(int, str(i)))
    if num >= a and num <= b:
        ans += i
print(ans)
Problem:
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.  He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.

Incorrect submission (verdict: Wrong Answer):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
  print('No')
  exit(0)
if abs(a-b)%(v-w) == 0:
  f = abs(a-b//(v-w))
else:
  f = abs(a-b//(v-w)+1)
if f <= t:
  print('Yes')
else:
  print('No')
  


Fixed, accepted submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
  print('NO')
  exit(0)
if abs(a-b)%(v-w) == 0:
  f = abs(a-b)//(v-w)
else:
  f = abs(a-b)//(v-w)+1
if f <= t:
  print('YES')
else:
  print('NO')
Problem:
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered.  This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source.  DFS timestamps each vertex as follows:    * $d[v]$ records when $v$ is first discovered.   * $f[v]$ records when the search finishes examining $v$’s adjacency list.  Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules:    * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.   * IDs in the adjacency list are arranged in ascending order.   * The program should report the discover time and the finish time for each vertex.   * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.   * The timestamp starts with 1.

Incorrect submission (verdict: Wrong Answer):
n=0
t=2
def adjacent_matrix():
    global n
    n=int(input())
    v=[]
    array=[]
    for i in range(n):
        zero=[0 for i in range(n)]
        a=list(map(int,input().split()))
        a=a[2:]
        for j in a:
            zero[j-1]=1
        array.append(zero)
    return array
def dfs(array,i,d,f):
    global t
    for (j,x) in enumerate(array[i]):
        if x == 1:
            d[j] = t
            t += 1
            dfs(array,j,d,f)
    f[i] = t
    t += 1
    return 


def main():
    array=adjacent_matrix()
    print()
    d=[1 for i in range(n)]
    f=[1 for i in range(n)]
    dfs(array,0,d,f)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i]))

if __name__ == "__main__":
    main()


Fixed, accepted submission:
n=0
t=1
def adjacent_matrix():
    global n
    n=int(input())
    v=[]
    array=[]
    for i in range(n):
        zero=[0 for i in range(n)]
        a=list(map(int,input().split()))
        a=a[2:]
        for j in a:
            zero[j-1]=1
        array.append(zero)
    return array
def dfs(array,i,d,f):
    global t
    if i == n:
        return
    else:
        if(d[i] == 0):
            d[i] = t
            t += 1
            for (j,x) in enumerate(array[i]):
                if x == 1:
                    dfs(array,j,d,f)
            f[i] = t
            t += 1
    return 


def main():
    array=adjacent_matrix()
    d=[0 for i in range(n)]
    f=[0 for i in range(n)]
    for i in range(n):
        dfs(array,i,d,f)
    for i in range(n):
        print("{} {} {}".format(i+1,d[i],f[i]))

if __name__ == "__main__":
    main()
Problem:
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.     

Incorrect submission (verdict: Wrong Answer):
W, H, x, y, r = map(int, input().split())

if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
    print('1')
else:
    print('0')


Fixed, accepted submission:
W, H, x, y, r = map(int, input().split())

if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
    print('Yes')
else:
    print('No')
Problem:
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b.  Determine whether the arrangement of the poles is beautiful.

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

Fixed, accepted submission:
a,b,c = map(int,input().split())
print("YES" if (b-a)==(c-b) else "NO")
Problem:
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.  Determine if it is possible that there are exactly X cats among these A + B animals.

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

if x < a:
    print('No')
else:
    if x > a + b:
        print('No')
    else:
        print('Yes')

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

if x < a:
    print('NO')
else:
    if x > a + b:
        print('NO')
    else:
        print('YES')
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):
n = int(input())
a = list(map(int, input().split()))
ans = 0
while a[0] > 1:
        for i in range(n):
                if a[i] % 2 != 0:
                        break
                else:
                        a[i] /= 2
                        print(a[i])
        else:
                ans += 1
                continue
        break;

print(ans)

Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
while a[0] > 1:
        for i in range(n):
                if a[i] % 2 != 0:
                        break
                else:
                        a[i] /= 2
        else:
                ans += 1
                continue
        break;

print(ans)