TnT/CodeNet4Repair huggingface dataset:
Problem:
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.  Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.    * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.   * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.  A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these.  Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.

Incorrect submission (verdict: Wrong Answer):
l = input().split()
s = input()

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

count = 0
countt = 0
for i in s:
    if i == 'a':
        if count < a+b:
            count = count + 1
            print('YES')
        else:
            print('No')
    if i == 'b':
        if (count < a+b) and (countt < b):
            count = count + 1
            countt = countt + 1
            print('YES')
        else:
            print('NO')
    if i == 'c':
        print('NO')



Fixed, accepted submission:
l = input().split()
s = input()
 
n = int(l[0])
a = int(l[1])
b = int(l[2])
 
count = 0
countt = 0
for i in s:
    if i == 'a':
        if count < a+b:
            count = count + 1
            print('Yes')
        else:
            print('No')
    if i == 'b':
        if (count < a+b) and (countt < b):
            count = count + 1
            countt = countt + 1
            print('Yes')
        else:
            print('No')
    if i == 'c':
        print('No')
Problem:
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.  Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.  Now, the following Q operations will be performed:    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.  Find the value of the counter on each vertex after all operations.

Incorrect submission (verdict: Wrong Answer):
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, input().split())
adj = [[]] * N
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

count = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    count[p - 1] += x

visited = [False] * N
def dfs(v, acc):
    if visited[v]:
        return
    visited[v] = True
    count[v] += acc
    for u in adj[v]:
        dfs(u, count[v])

dfs(0, 0)
print(" ".join(map(str, count)))

Fixed, accepted submission:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

count = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    count[p - 1] += x

visited = [False] * N
def dfs(v):
    visited[v] = True
    for u in adj[v]:
        if visited[u]:
            continue
        count[u] += count[v]
        dfs(u)

dfs(0)
print(*count)
Problem:
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Incorrect submission (verdict: Wrong Answer):
if __name__ == '__main__':
	n = int(input())
	if n % 2 == 0:
		print(n/2 - 1)
	else:
		print((n-1)/2)

Fixed, accepted submission:

if __name__ == '__main__':
    n = int(input())
    if n % 2 == 0:
        print(int(n/2 - 1))
    else:
        print(int((n-1)/2))
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())
numlist = list(map(int,input().split()))
sum=0
temp = 9999999999999
for i in numlist:
	if i % 2 != 0:
		temp =0
		break
	else:
		while i % 2 ==0:
			i //=2
			sum += 1
		print(sum)
		if temp > sum :
			temp = sum
			
print(temp-1)		
	

Fixed, accepted submission:
N = int(input())
numlist = list(map(int,input().split()))
temp = 9999999999999
for i in numlist:
	sum = 0
	if i % 2 != 0:
		temp =0
		break
	else:
		while i % 2 ==0:
			i //= 2
			sum += 1
		if temp > sum :
			temp = sum
			
print(temp)
Problem:
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Incorrect submission (verdict: Wrong Answer):
def get_score(day, contest, prev_list, loss_list, satisfied_matrix):
    plus = satisfied_matrix[day][contest]
    minus = 0
    for type, prev in enumerate(prev_list):
        if type == contest:
            continue
        spend = day - prev
        minus += loss_list[type] * spend

    return plus - minus



days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]

prev_list = [-1] * 26

ans = []
for day in range(days):
    best_contest = 0
    best_score = 0
    for contest in range(26):
        score = get_score(day, contest, prev_list, loss_list, satisfied_matrix)
        if score > best_score:
            best_contest = contest
            best_score = score

    ans.append(best_contest)
    prev_list[best_contest] = day

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


Fixed, accepted submission:
def score(day, contest, prev_list, loss_list, satisfied_matrix):
    plus = satisfied_matrix[day][contest]
    minus = 0
    for type, prev in enumerate(prev_list):
        spend = day - prev
        minus += loss_list[type] * spend

    return plus - minus



days = int(input())
loss_list = list(map(int, input().split()))
satisfied_matrix = [list(map(int, input().split())) for _ in range(days)]

prev_list = [-1] * 26

total = 0
for day in range(days):
    contest = int(input())
    prev_list[contest-1] = day
    total += score(day, contest-1, prev_list, loss_list, satisfied_matrix)
    print(total)
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):
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a):
    for j in range(b):
        for k in range(c):
            if 500*a+100*b+50*c==x:
                ans += 1
print(ans)

Fixed, accepted submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans += 1
print(ans)
Problem:
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.

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

# 1,[2],3,[4,5],6,[7,8,9],10 ...

ans = (-1+(8*x+1)**0.5)/2
ans = -(-ans//1)

print(ans)

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

# 1,[2],3,[4,5],6,[7,8,9],10 ...

ans = (-1+(8*x+1)**0.5)/2
ans = -(-ans//1)

print(int(ans))
Problem:
We ask you to select some number of positive integers, and calculate the sum of them.  It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.  Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.  If the objective is achievable, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
A, B, C = list(map(int, input().split()))
i = 1
d_set = set()
while(True):
    d = A*i % B
    if d == C:
        print('Yes')
        break
    if d in d_set:
        print('No')
        break
    d_set.add(d)
    i += 1

Fixed, accepted submission:
A, B, C = list(map(int, input().split()))
i = 1
d_set = set()
while(True):
    d = A*i % B
    if d == C:
        print('YES')
        break
    if d in d_set:
        print('NO')
        break
    d_set.add(d)
    i += 1
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):
s = input()

found_a = True
high = 0
low = 0

for index, word in enumerate(s):
    if found_a == False:
        if word == 'A':
            low = index
            found_a = True
    if word == 'Z':
        high = index

print(high - low)

Fixed, accepted submission:
s = input()

found_a = False
high = 0
low = 0

for index, word in enumerate(s):
    if found_a == False:
        if word == 'A':
            low = index
            found_a = True
    if word == 'Z':
        high = index

print(high - low + 1)
Problem:
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time.  Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.

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

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max((takahashi // t), (aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)
	
if __name__ == "__main__":
	main()


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

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max(-(-takahashi // t), -(-aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)

if __name__ == "__main__":
	main()
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):
r = str(input())
g = str(input())

if r == g[::-1]:
  print('Yes')
else:
  print('No')

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

if r == g[::-1]:
  print('YES')
else:
  print('NO')
Problem:
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.

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

if  N <= K:
    print("NO")
elif N == K:
    print("NO")
else:
    print("Yes")

Fixed, accepted submission:
import sys
N, K = map(int, input().split())

ans = 0

for i in range(1,N+1,2):
    ans = ans + 1

if ans >= K:
    print("YES")
    sys.exit()

print("NO")
Problem:
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.  You are given an integer N. Find the N-th Lucas number.  Here, the i-th Lucas number L_i is defined as follows:    * L_0=2   * L_1=1   * L_i=L_{i-1}+L_{i-2} (i≥2)

Incorrect submission (verdict: Wrong Answer):
def Lucas(n):
  if n==0: return 2
  if n==1: return 1
  a=2
  b=1
  for i in range(2,n):
    a,b=b,a+b
  return b
N=int(input())
print(Lucas(N))


Fixed, accepted submission:
def Lucas(n):
  if n==0: return 2
  if n==1: return 1
  a=2
  b=1
  for i in range(2,n+1):
    a,b=b,a+b
  return b
N=int(input())
print(Lucas(N))
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())
s = (a+b)*h/2
print(s)


Fixed, accepted submission:
a = int(input())
b = int(input())
h = int(input())
s = (a+b)*h/2
print(int(s))
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())

if h*w%2 == 0:
  print(h*w/2)
else:
  print(h*w/2 + 1)

Fixed, accepted submission:
h, w = map(int, input().split())

if h == 1 or w == 1:
  a = 1

elif h % 2 == 1 and w % 2 == 1:
	a = int((h * w + 1) / 2) 
else:
	a = int(h * w / 2)
    
print(a)
Problem:
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
s = [i for i in input()]

max = 0

for i in range(1, n-1):
    a = set(s[:i])
    b = set(s[i:])

    print(a & b)
    
    if max < len(a & b):
        max = len(a & b)
print(max)



Fixed, accepted submission:
N = int(input())
S = list(input())
 
m = 0
for i in range(1, N - 1):
    a = set(S[:i])
    b = set(S[i:])
    if m < len(a & b):
        m = len(a & b)
 
print(m)
Problem:
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime.  You are given Q queries.  In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Incorrect submission (verdict: Wrong Answer):
import math
import bisect
import heapq
from collections import deque

q = int(input())


def is_prime(n):
    prime = True

    for i in range(2, int(math.sqrt(n)) + 1):

        if n % i == 0:
            prime = False

    return prime


for i in range(q):
    count = 0
    l, r = map(int, input().split())

    for j in range(l, r + 1, 2):
        if is_prime(j) and is_prime(j * (j - 1) / 2):
            count += 1

    print(count)


Fixed, accepted submission:
import math
import bisect
import heapq
from collections import deque

def prime_list(n):
    l = [True for _ in range(n+1)]
    l[0] = False
    l[1] = False
    for i in range(2,n+1):
        if l[i]:
            for j in range(2*i,n+1,i):
                l[j] = False

    return l

p = prime_list(10**5)

like = [0 for _ in range(10**5 + 1)]
for i in range(3,10**5+1,2):
    if p[i] and p[(i+1)//2]:
        like[i] = 1

for i in range(1, 10**5+1):
    like[i] += like[i-1]

q = int(input())
for i in range(q):
    l,r = map(int, input().split())
    print(like[r]-like[l-1])
Problem:
In this problem, we use the 24-hour clock.  Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?

Incorrect submission (verdict: Wrong Answer):
h1,h2,m1,m2,k = map(int,input().split())

a = 60*h2 + m2
b = 60+h1 + m1
print(a-b-k)

Fixed, accepted submission:
h1,m1,h2,m2,k = map(int,input().split())

a = 60*h2 + m2
b = 60*h1 + m1
print(a-b-k)
Problem:
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:    * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.   * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.  The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Incorrect submission (verdict: Wrong Answer):
[n, h] = list(map(int, input().split()))
sword = []
for _ in range(n):
    sword.append(list(map(int, input().split())))
sword.sort(key=lambda x:x[1])
cut = max(sword, key=lambda x:x[0])[0]
attack = []
for _ in range(n):
    if sword[0][1] > cut:
        attack.append(sword[0][1])
        del sword[0]
    else:
        attack.append(cut)
        break
counter = 0
while h > 0:
    if len(attack) >= 2:
        h -= attack[0]
        del attack[0]
        counter += 1
    else:
        h -= attack[0]
        counter += 1
print(counter)


Fixed, accepted submission:
from math import ceil
import numpy as np
[n, h] = list(map(int, input().split()))
sword = []
for _ in range(n):
    sword.append(list(map(int, input().split())))
if n > 1:
    sword.sort(key=lambda x:x[1])
    cut = max(sword, key=lambda x:x[0])
    sword.remove(max(sword, key=lambda x:x[0]))
    sword.reverse()
    counter = 0
    for i in sword:
        if i[1] < cut[0]:
            break
        h -= i[1]
        counter += 1
        #print("HP:{}, attack:{}, counter:{}".format(h, i[1], counter))
        if h <= 0:
            break
    if h > 0:
        h -= cut[1]
        counter += 1
        if h > 0:
            counter += int(ceil(h / float(cut[0])))
    print(counter)
else:
    print(int(ceil((h - sword[0][1]) / sword[0][0])) + 1)
Problem:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.  Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.  Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.  Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.

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

Fixed, accepted submission:
x,a,b=map(int,input().split())
if b-a<=x:
    if b-a<=0:
        print('delicious')
    else:
        print('safe')
else:
    print('dangerous')
Problem:
Today is August 24, one of the five Product Days in a year.  A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day):    * d_1 \geq 2   * d_{10} \geq 2   * d_1 \times d_{10} = m  Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D.  In Takahashi Calendar, how many Product Days does a year have?

Incorrect submission (verdict: Wrong Answer):
m,d=map(int,input().split())
ans=0
for i in range(1,m+1):
  for j in range(1,d+1):
    if i>=2 and j>=20 and j//10>=2 and j%10>=2 and m==(j//10)*(j%10):
      ans+=1
print(ans)

Fixed, accepted submission:
m,d=map(int,input().split())
ans=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if j//10>=2 and j%10>=2 and i==(j//10)*(j%10):
      ans+=1
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 = list(map(int, input().split()))  
B, W = list(map(int, input().split()))  
T = int(input())  

if (A + V*T) >= B + W*T:
    print("Yes")
else:
    print("No")

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

if B - A > 0:
    if (A + V*T) - (B + W*T) >= 0:
        print("YES")
    else:
        print("NO")
else:
    if (A - V*T) - (B - W*T) <= 0:
        print("YES")
    else:
        print("NO")