TnT/CodeNet4Repair huggingface dataset:
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())
A = [int(input()) for i in range(N)]
print(A)
cnt = 1
now = 1

while True:
  if now == A[1]:
    print(cnt+1)
    break
  if (cnt > N):
    print(-1)
    break
  now = A[now-1]
  print(now)
  cnt += 1


Fixed, accepted submission:
N = int(input())
V = [int(input()) for i in range(1,N+1)]
cnt = 1
val = V[0]
while True:
  if val == 2:
    print(cnt)
    break
  if (cnt >= N):
    print(-1)
    break
  cnt += 1
  val = V[val-1]
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
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd


args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def input():
    return next(args)
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)


def main():
    N, Q = parse(int, int)
    edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = parse(int1, int1)
        edges[a] += [b]
    vals = [0] * N
    for _ in range(Q):
        p, x = parse(int1, int)
        vals[p] += x

    sum_vals = [0] * N
    que = [(0, 0)]
    while que:
        v, x = que.pop()
        sum_vals[v] += x + vals[v]
        for n in edges[v]:
            que.append((n, sum_vals[v]))

    for v in sum_vals:
        print(v)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()


Fixed, accepted submission:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque


args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def input():
    return next(args)
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)


def main():
    N, Q = parse(int, int)
    edges = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = parse(int, int)
        edges[a] += [b]
        edges[b] += [a]
    vals = [0] * (N + 1)
    for _ in range(Q):
        p, x = parse(int, int)
        vals[p] += x

    counter = [0] * (N + 1)
    que = deque()
    que.append((1, 0))
    alr = [False] * (N + 1)
    while que:
        v, x = que.pop()
        alr[v] = True
        counter[v] += x + vals[v]
        for n in edges[v]:
            if not alr[n]:
                que.append((n, counter[v]))

    print(*counter[1:])

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()
Problem:
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.  She will concatenate all of the strings in some order, to produce a long string.  Among all strings that she can produce in this way, find the lexicographically smallest one.  Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds:    * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.   * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

Incorrect submission (verdict: Wrong Answer):
import sys

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

sorted(word)
for i in range(n):
  sys.stdout.write(word[i])

print()



Fixed, accepted submission:
import sys

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

word.sort()

for i in range(n):
  sys.stdout.write(word[i])

print()
Problem:
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions:    * Question 1: Are you subscribing to Newspaper X?   * Question 2: Are you subscribing to Newspaper Y?  As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2.  What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?  Write a program to answer this question.

Incorrect submission (verdict: Wrong Answer):
i = input().split()
all = int(i[0])
x = int(i[1])
y = int(i[2])
t = 0
max = 0
if x > y:
    max = x - abs(x - y)
    t = x
elif y > x:
    max = y - abs(x - y)
    t = y 
else:
    t = all
    max = x

min = 0
nx = all - x
ny = all - y

if nx > ny:
    nt = nx
elif ny > nx:
    nt = ny
else:
    nt = 0
min = abs(t - nt)
print("{0} {1}".format(max,min))

Fixed, accepted submission:
i = input().split()
all = int(i[0])
x = int(i[1])
y = int(i[2])
t = 0
max = 0
if x > y:
    max = x - abs(x - y)
    t = x
elif y > x:
    max = y - abs(x - y)
    t = y 
else:
    t = x
    max = x

min = 0
nx = all - x
ny = all - y

if nx > ny:
    nt = nx
elif ny > nx:
    nt = ny
else:
    nt = nx
if t >= nt: 
    min = t - nt
else:
    min = 0
print("{0} {1}".format(max,min))
Problem:
Write a program which reads two integers x and y, and prints them in ascending order.

Incorrect submission (verdict: Wrong Answer):
x, y = map(int, input().split())
if x < y :
    x, y = y, x
    print(x, y)
elif y < x :
    print(x, y)
else :
    pass



Fixed, accepted submission:
while True :
    x, y = map(int, input().split())
    if x == 0 and y == 0 :
        break
    else :
        if x > y :
            a, b = y, x
            print(a, b)
        else :
            print(x, y)
Problem:
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.

Incorrect submission (verdict: Wrong Answer):
from itertools import accumulate

def main():
    n = int(input())
    A = list(map(int, input().split()))

    if n  == 0:
        if A[0] == 1:
            return 1
        else:
            return -1
    elif A[0] != 0:
        return -1
    
    nodes = 0
    bound = list(accumulate(A[::-1]))
    bound.reverse()
    # print('bound: ', bound)
    
    above = [0] * (n+1)
    above[0] = 1
    B = [0] * (n+1)
    for i, a in enumerate(A):
        if i == 0:
            B[0] = 1
        else:
            above[i] = (above[i-1] - A[i-1]) * 2
            if above[i] < 0:
                return -1
            B[i] = min(above[i], bound[i])
    
    
    return sum(B)

main()

Fixed, accepted submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    if n  == 0:
        if A[0] == 1:
            return 1
        else:
            return -1
    elif A[0] != 0:
        return -1
    
    bound = [0]*(n+1)
    bound[n] = A[n]
    for i in range(n-1, -1, -1):
        bound[i] = bound[i+1] + A[i]

    B = [0] * (n+1)
    for i in range(n+1):
        if i == 0:
            B[i] = 1
        else:
            above = (B[i-1] - A[i-1]) * 2
            if  (i < n and above <= 0) or above < 0:
                return -1
            B[i] = min(above, bound[i])
    if B[n] < A[n]:
        return -1
    
    return sum(B)

print(main())
Problem:
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.  The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.  One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.  If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.    * X < Z \leq Y   * x_1, x_2, ..., x_N < Z   * y_1, y_2, ..., y_M \geq Z  Determine if war will break out.

Incorrect submission (verdict: Wrong Answer):
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

if min(y)-max(x)>=2:
  print('No War')
else:
  print('War')

Fixed, accepted submission:
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
if max(x)<min(y) and X<Y:
  if len(set(range(max(x)+1,min(y)+1))&set(range(X+1,Y+1)))>=1:
  	print('No War')
  else:
    print('War')
else:
  print('War')
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

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

for i in range(1,10001):
    if i**2 == a*b:
        print('Yes')
        exit()
        
print('No')

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

N = int(a+b)

import sys

for i in range(1,int(N**0.5)+1):
    if i**2 == N:
        print('Yes')
        sys.exit()
        
print('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):
def keisan(a,b):
  if a * b % 2 == 0:
    print("Even")
  else:
      print("odd")

keisan(1,21)

Fixed, accepted submission:
a,b=map(int,input().split())
print("Even" if a*b%2==0 else "Odd")
Problem:
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.  The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)  Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Incorrect submission (verdict: Wrong Answer):
x = int(input())
y = 0
z = 100

if x<=z:
  pass
else:
  while z<x:
    y+=1
    x = int((x*1.01)%1)

print(y)

Fixed, accepted submission:
x = int(input())
y = 0
z = 100

while z<x:
    y+=1
    z *= 101
    z //= 100

print(y)
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):
n = int(input())

T = 1
A = 1
for _ in range(n):
    t, a=map(int, input().split())
    if T * a == t * A:
        continue
    if T % t != 0:
        T += t - T % t
    if A < T * a // t:
        A = T * a // t
    else:
        A += a - A % a
        T = A * t // a

print(A + T)

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

T = 1
A = 1
for _ in range(n):
    t, a = map(int, input().split())
    m = max([T // t, A // a])
    for i in range(1000):
        i += m
        if T <= t * i and A <= a * i:
            T = t * i
            A = a * i
            break

print(A + T)
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, a = input().split()
B, b = input().split()
T = input()

A = int(A)
a = int(a)
B = int(B)
b = int(b)
T = int(T)

distance = abs(A-B)
speed = a-b

if distance - speed * T <= 0:
    print("yes")
else:
    print("no")

Fixed, accepted submission:
A, a = input().split()
B, b = input().split()
T = input()

A = int(A)
a = int(a)
B = int(B)
b = int(b)
T = int(T)

distance = abs(A-B)
speed = a-b

if distance - speed * T <= 0:
    print("YES")
else:
    print("NO")
Problem:
E869120 found a chest which is likely to contain treasure.   However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.   He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`.  One more thing he found is a sheet of paper with the following facts written on it:    * Condition 1: The string S contains a string T as a contiguous substring.   * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.  Print the string S.   If such a string does not exist, print `UNRESTORABLE`.

Incorrect submission (verdict: Wrong Answer):
sd, t = input(), input()





ans = ''
for i in  range(len(sd) - len(t)+1):
    target = sd[i:i+len(t)]
    print("target= {}".format(target))
    count = 0
    for j in range(len(t)):
        if t[j]==target[j] or target[j]=='?':
            count+=1
        else:
            break
    if count==len(t):
        
        tmp = sd[:i]+t+sd[len(t)+i:]
        print("tmp= {}".format(tmp))
        if ans=='':
            ans = ''.join(['a' if i=='?' else i for i in tmp])
        else:
            ans = min(ans, ''.join(['a' if i=='?' else i for i in tmp]))
print('UNRESTORABLE' if ans=='' else ans)

Fixed, accepted submission:


s, t = input(), input()
for i in range(len(s) - len(t), -1, -1):
    tt = s[i : i + len(t)]
    flag = True
    for j in range(len(t)):
        if tt[j] == t[j] or tt[j] == "?":
            continue
        else:
            flag = False
    if flag:
        ans = list(s[:i] + t + s[i + len(t) :])
        for k in range(len(s)):
            if ans[k] == "?":
                ans[k] = "a"
        print("".join(ans))
        exit()
print("UNRESTORABLE")
Problem:
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P.  Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.

Incorrect submission (verdict: Wrong Answer):
'''input
3 24
'''
import math
n, p = map(int, input().strip().split())
ans = 1
i = 2
while i * i <= p:
	cnt = 0
	while(p % i == 0):
		cnt += 1
		p /= i
	ans = ans * pow(i, cnt)
print(ans)

Fixed, accepted submission:
'''input
1 5
'''
n, p = map(int, input().strip().split())
ans = 1
i = 2
while i * i <= p:
	cnt = 0
	while p % i == 0:
		p //= i
		cnt += 1
	ans = ans * pow(i, cnt // n)
	i += 1
ans = ans * (p if n == 1 else 1)
print(ans)
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):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

r, g = [int(readline()) for _ in range(2)]
ans = r + (g - r) * 2
print(r, (g - r), (g - r) * 2)

Fixed, accepted submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

r, g = [int(readline()) for _ in range(2)]
ans = r + (g - r) * 2
print(ans)
Problem:
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.  

Incorrect submission (verdict: Wrong Answer):
x = input()
ls_x = x.split()

print(ls_x)

for i in range(len(ls_x)):
    ls_x[i] = int(ls_x[i])

gA = [1,3,5,7,8,10,12]
gB = [4,6,9,11]

if ls_x[0] == 2 or ls_x[1] == 2:
    print("No")

if ls_x[0] == gA[i] and ls_x[1] == gA[i]:
    print("Yes")
else:
    print("No")

if ls_x[0] == gB[i] and ls_x[1] == gB[i]:
    print("Yes")
else:
    ("No")



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

gA = [1,3,5,7,8,10,12]
gB = [4,6,9,11]
gC = [2]

def ok(x, y, group):
    return (x in group) and (y in group)

if ok(x, y, gA):
    print("Yes")
elif ok(x, y, gB):
    print("Yes")
elif ok(x, y, gC):
    print("Yes")
else:
    print("No")
Problem:
Sitting in a station waiting room, Joisino is gazing at her train ticket.  The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).  In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds.  The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Incorrect submission (verdict: Wrong Answer):
#A_list =list(map(int,input().split()))
A_list = [int(x) for x in list(input())]
OP_list = ["","",""]
#current = 1


def solve(current, current_sum):
    if current == 4:
        return current_sum == 7
    
    if solve(current + 1 , current_sum + A_list[current]):
        OP_list[current-1] = "+"
        return True
    
    if solve(current + 1 , current_sum - A_list[current]):
        OP_list[current-1] = "-"
        return True
    
    return False

solve(1,A_list[0])
print (OP_list)
        

Fixed, accepted submission:
#A_list =list(map(int,input().split()))
A_list = [int(x) for x in list(input())]
OP_list = ["","",""]
answer = ""
#current = 1


def solve(current, current_sum):
    if current == 4:
        return current_sum == 7
    
    if solve(current + 1 , current_sum + A_list[current]):
        OP_list[current-1] = "+"
        return True
    
    if solve(current + 1 , current_sum - A_list[current]):
        OP_list[current-1] = "-"
        return True
    
    return False

solve(1,A_list[0])
answer = str(A_list[0]) + OP_list[0] + str(A_list[1]) + OP_list[1] + str(A_list[2]) + OP_list[2] + str(A_list[3]) + "=7"
print (answer)
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):
def resolve():
    r = int(input())
    g = int(input())
    print((g - r) * 2)


if __name__ == "__main__":
    resolve()


Fixed, accepted submission:
def resolve():
    r = int(input())
    g = int(input())
    print(2 * g - r)


if __name__ == "__main__":
    resolve()
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 A < X:
    print('No')
    exit()
if A + B < X:
    print('No')
    exit()
print('Yes')

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

if A > X:
    print('NO')
    exit()
if A + B < X:
    print('NO')
    exit()
print('YES')
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):
a=list(map(lambda x: len(x),list(input().split())))
a.sort()
print("YES" if a==[5,5,7] else "NO")

Fixed, accepted submission:
a=list(map(int,input().split()))
a.sort()
print("YES" if a==[5,5,7] 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):
# coding: utf-8
# Your code here!

list_a = input().split()
print("Even") if (int(list_a[0])+int(list_a[1]))%2==0 else print("Odd")

Fixed, accepted submission:
# coding: utf-8
# Your code here!

list_a = input().split()
print("Even") if (int(list_a[0])*int(list_a[1]))%2==0 else print("Odd")
Problem:
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i.  Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.

Incorrect submission (verdict: Wrong Answer):
m = int(input().count('1'))


Fixed, accepted submission:
print(input().count('1'))
Problem:
ある部屋ではICカードを用いて鍵を開け閉めする電子錠システムを用いている。 このシステムは以下のように動作する。  各ユーザーが持つICカードを扉にかざすと、そのICカードのIDがシステムに渡される。 システムはIDが登録されている時、施錠されているなら開錠し、そうでないのなら施錠し、それぞれメッセージが出力される。 IDが登録されていない場合は、登録されていないというメッセージを出力し、開錠及び施錠はおこなわれない。  さて、現在システムにはN個のID(U1, U2, ……, UN)が登録されており、施錠されている。 M回ICカードが扉にかざされ、そのIDはそれぞれ順番にT1, T2, ……, TMであるとする。 この時のシステムがどのようなメッセージを出力するか求めよ。

Incorrect submission (verdict: Wrong Answer):
N = int(input())
U = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

opened = False
for T_i in T:
    if T_i in U:
        if opened == True:
            print('Closed by ' + T_i)
            opened = False
        else:
            print('Opened by ' + T_i)
            opened = True


Fixed, accepted submission:
N = int(input())
U = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

opened = False
for T_i in T:
    if T_i in U:
        if opened == True:
            print('Closed by ' + T_i)
            opened = False
        else:
            print('Opened by ' + T_i)
            opened = True
    else:
        print('Unknown ' + T_i)