TnT/CodeNet4Repair huggingface dataset:
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):
n,q=map(int,input().split())
d=[[0] for _ in range(n+1)]
d1=[0 for _ in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  d[a].append(b)
for i in range(q):
  p,x=map(int,input().split())
  d1[p]+=x

for i in range(1,n+1):
  for m in d[i]:
    d1[m]+=d1[i]
print(d1[1:])

Fixed, accepted submission:
import sys
sys.setrecursionlimit(1000000)
n,q=map(int,input().split())

d=[[0] for _ in range(n+1)]
d1=[0 for _ in range(n+1)]

for i in range(n-1):
  a,b=map(int,input().split())
  d[a].append(b)
  d[b].append(a)

for i in range(q):
  p,x=map(int,input().split())
  d1[p]+=x


vi=[-1 for _ in range(n+1)]

def dfs(x,i):
  vi[x]=i+d1[x]
  for m in d[x]:
    if vi[m]==-1 and m!=0:
      dfs(m,vi[x])    

dfs(1,0)


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

Incorrect submission (verdict: Wrong Answer):
list=list(input())
word=""
for i in list:
  if i=="0":
    word+=i
  elif i=="1":
    word+=i
  else:
    if word=="":
      pass
    else:
      del list[-1]
print(word)
  

Fixed, accepted submission:
list=list(input())
words=[]
word=""
for i in list:
  if i=="0" or i=="1":
    words.append(i)
  else:
    if words==[]:
      pass
    else:
      del words[-1]
for i in words:
  word+=i
print(word)
Problem:
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.  Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

Incorrect submission (verdict: Wrong Answer):
s=input()
s=int(s)
input_data = [int(input()) for _ in range(s)]
print(len(list(input_data)))


Fixed, accepted submission:
s=input()
s=int(s)
input_data = [input() for _ in range(s)]
print(len(set(input_data)))
Problem:
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.  Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Incorrect submission (verdict: Wrong Answer):
A, B, C, X, Y = map(int, input().split())
sum = 0
min_num = 10**10
num = [0]*3
if min(A/2, B/2) > C:
    print(C*Y*2)
    exit()
for c in range(min(X, Y)+1):
    sum += C*c*2
    num[0] = c*2
    for a in range(X-c):
        sum += A
        num[1] = a
    for b in range(Y-c):
        sum += B
        num[2] = b
    if min_num > sum:
        min_num = sum
    print(sum, num)
    sum = 0
print(min_num)

Fixed, accepted submission:
A, B, C, X, Y = map(int, input().split())
sum = 0
min_num = 10**10
num = [0]*3
for c in range(max(X, Y)+1):
    sum += C*c*2
    num[0] = c*2
    sum += A*max(0,X-c) + B*max(0, Y-c)
    num[1] = max(0, X-c)
    num[2] = max(0, Y-c)
    if min_num > sum:
        min_num = sum
    sum = 0
print(min_num)
Problem:
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.  Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.  Given the name of the contest, print the abbreviation of the name.

Incorrect submission (verdict: Wrong Answer):
print("A" + input()[0] + "C")

Fixed, accepted submission:
print("".join(map(lambda x:x[0], input().split())))
Problem:
Mr.X, who the handle name is T, looked at the list which written N handle names, S_1, S_2, ..., S_N.   But he couldn't see some parts of the list. Invisible part is denoted `?`.      Please calculate all possible index of the handle name of Mr.X when you sort N+1 handle names (S_1, S_2, ..., S_N and T) in lexicographical order.   Note: If there are pair of people with same handle name, either one may come first.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a,z = [],[]
for _ in range(n):
	s = input()
	a.append(s.replace("?","a"))
	z.append(s.replace("?","z"))
t = input()
a.append(t)
z.append(t)
a,z = sorted(a)[::-1],sorted(z)
r,l = n+1-a.index(t),z.index(t)+1
for i in range(l,r+1): print(i,end=" ")

Fixed, accepted submission:
n = int(input())
a,z = [],[]
for _ in range(n):
	s = input()
	a.append(s.replace("?","a"))
	z.append(s.replace("?","z"))
t = input()
a.append(t)
z.append(t)
a,z = sorted(a)[::-1],sorted(z)
r,l = n+1-a.index(t),z.index(t)+1
for i in range(l,r): print(i,end=" ")
print(r)
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):
S = int(input())
h = S/3600
m = S/60
s = S
print(h, ':', m, ':', s,  sep='')



Fixed, accepted submission:
S = int(input())
h = S // 3600
m = S // 60 % 60
s = S % 60
print(h, ':', m, ':', s,  sep='')
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("7","8",1)
print(s)

Fixed, accepted submission:
s=input()
print(s.replace("7","8",1))
Problem:
Write a program which performs a sequence of commands to a given string $str$. The command is one of:    * print a b: print from the a-th character to the b-th character of $str$   * reverse a b: reverse from the a-th character to the b-th character of $str$   * replace a b p: replace from the a-th character to the b-th character of $str$ with p  Note that the indices of $str$ start with 0.

Incorrect submission (verdict: Wrong Answer):
s = input()
n = int(input())
for i in range(n):
    p = input().split()
    
    a, b = [int(x) for x in p[1:3]]
    if p[0]=="print":
        print(s[a:b+1])
    if p[0]=="replace":
        s = s[:a] + p[3] + s[b+1:]
    if p[0]=="reverse":
        s = s[:a] + s[a:b+1:-1] + s[b+1:]

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

for i in range(n):
    p = input().split()

    a, b = [int(x) for x in p[1:3]]
    if p[0]=="print":
        print(s[a:b+1])
    elif p[0]=="replace":
        s = s[:a] + p[3] + s[b+1:]
    elif p[0]=="reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
Problem:
_Seisu-ya_ , a store specializing in non-negative integers, sells N non- negative integers. The i-th integer is A_i and has a _utility_ of B_i. There may be multiple equal integers with different utilities.  Takahashi will buy some integers in this store. He can buy a combination of integers whose _bitwise OR_ is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.  Find the maximum possible sum of utilities of purchased integers.

Incorrect submission (verdict: Wrong Answer):
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
ans=0
for i in range(n):
    if k|l[i][0]==k:
        ans+=l[i][1]
t=0
for i in range(30):
    if (1<<29-i)|k:
        t+=2**(29-i)
        p=t-1
        kai=0
        for i in range(n):
            if p|l[i][0]==p:
                kai+=l[i][1]
        ans=max(ans,kai)
print(ans)
        
        

Fixed, accepted submission:
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
ans=0
for i in range(n):
    if k|l[i][0]==k:
        ans+=l[i][1]
t=0
for i in range(30):
    if (1<<29-i)&k:
        t+=2**(29-i)
        p=t-1
        kai=0
        for i in range(n):
            if p|l[i][0]==p:
                kai+=l[i][1]
        ans=max(ans,kai)
print(ans)
Problem:
Given two integers $A$ and $B$, compute the product, $A \times B$.

Incorrect submission (verdict: Wrong Answer):
a,b = map(int,input().split())
c = abs(a) // abs(b)
print(-c if a * b < 0 else c)



Fixed, accepted submission:
a,b = map(int,input().split())
print(a*b)
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):
s = list(map(int,input().split()))
print(s.count(1))

Fixed, accepted submission:
s = str(input())
print(s.count('1'))
Problem:
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
used = [False] * n
a.sort(key = lambda x: x[0], reverse=True)
b.sort(key = lambda x: x[0], reverse=True)
result = 0
for i in range(n):
  for j in range(n):
    if used[j]:
      continue
    if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
      print(a[i], b[j])
      used[j] = True
      result += 1
      break
print(result)


Fixed, accepted submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]
used = [False] * n
a.sort(key = lambda x: x[0], reverse = True)
b.sort(key = lambda x: x[0], reverse = True)
result = 0
for i in range(n):
  pj = -1
  miny = float('inf')
  for j in range(n):
    if used[j]:
      continue
    if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
      if b[j][1] < miny:
        pj = j
        miny = b[j][1]
  if pj != -1:
    used[pj] = True
    result += 1
print(result)
Problem:
We have an N \times N square grid.  We will paint each square in the grid either black or white.  If we paint exactly A squares white, how many squares will be painted black?

Incorrect submission (verdict: Wrong Answer):
N, A = [int(input()) for i in range(2)]
print(N ^ 2 - A)

Fixed, accepted submission:
N, A = [int(input()) for i in range(2)]
print(pow(N, 2) - A)
Problem:
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.   The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.  An edge whose removal disconnects the graph is called a _bridge_.   Find the number of the edges that are bridges among the M edges.

Incorrect submission (verdict: Wrong Answer):
inputs = input().split()
N = int(inputs[0])
M = int(inputs[1])

grid_list = [[] for x in range(N)]
input_edge = []

diff = 0
for i in range(N):
    diff += i

for M in range(M):
    inputs = input().split()
    a = int(inputs[0])
    b = int(inputs[1])
    input_edge.append([a-1, b-1])
    grid_list[a - 1].append(b-1)
    grid_list[b-1].append(a-1)



ans = 0
for inp in input_edge:
    grid_list[inp[0]].remove(inp[1])
    grid_list[inp[1]].remove(inp[0])
    able_list = []
    sum = 0
    search_list = []
    for g in grid_list[0]:
        search_list.append(g)
    for g in search_list:
        able_list.append(g)
        for h in grid_list[g]:
            if h not in search_list:
                search_list.append(h)
    able_list = list(set(able_list))
    for i in able_list:
        sum += i
    if diff > sum:
        print("%s , %s" % (inp[0], inp[1]))
        ans += 1
    grid_list[inp[0]].append(inp[1])
    grid_list[inp[1]].append(inp[0])

print(ans)

Fixed, accepted submission:
inputs = input().split()
N = int(inputs[0])
M = int(inputs[1])

grid_list = [[] for x in range(N)]
input_edge = []

diff = 0
for i in range(N):
    diff += i

for M in range(M):
    inputs = input().split()
    a = int(inputs[0])
    b = int(inputs[1])
    input_edge.append([a-1, b-1])
    grid_list[a - 1].append(b-1)
    grid_list[b-1].append(a-1)



ans = 0
for inp in input_edge:
    grid_list[inp[0]].remove(inp[1])
    grid_list[inp[1]].remove(inp[0])
    able_list = []
    sum = 0
    search_list = []
    for g in grid_list[0]:
        search_list.append(g)
    for g in search_list:
        able_list.append(g)
        for h in grid_list[g]:
            if h not in search_list:
                search_list.append(h)
    able_list = list(set(able_list))
    for i in able_list:
        sum += i
    if diff > sum:
        ans += 1
    grid_list[inp[0]].append(inp[1])
    grid_list[inp[1]].append(inp[0])

print(ans)
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            print(a[max(i-1,0):min(i+2,w-1),max(j-1,0):min(j+2,w-1)])
            a[i][j]=a[a[max(i-1,0):min(i+2,w-2),max(j-1,0):min(j+2,w-2)]=='#'].size
for i in a:
    print(''.join(i))

Fixed, accepted submission:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            b=a[max(i-1,0):min(i+2,h),max(j-1,0):min(j+2,w)].flatten()
            a[i][j]=sum(b=='#')
for i in a:
    print(''.join(i))
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):
def main():
    num = list(map(int, input().split()))
    total_sum = 0
    print(num[0])
    for i in range(1,num[0]+1):
        current = i
        current_sum=0
        while i >= 1:
            current_sum += i %10
            i /=10
        if ((current_sum >= num[1]) and (current_sum <= num[2])):
            total_sum += current
    print(total_sum)
main()

Fixed, accepted submission:
def main():
    num = list(map(int, input().split()))
    total_sum = 0
    for i in range(1,num[0]+1):
        current = i
        current_sum=0
        while i >=1:
            current_sum += int( i %10)
            i = i//10
        if ((current_sum >= num[1]) and (current_sum <= num[2])):
            total_sum += current
    print(total_sum)
main()
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: Time Limit Exceeded):
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    g = 1
    for i in range(1, max([a, b])):
        if(a % i == 0 and b % i == 0):
            g = i
    return g


def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        print(str(gcd(line[0], line[1])) + " " + str(lcm(line[0], line[1])))
    except:
        exit()

Fixed, accepted submission:
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(min(line), max(line))
        print(str(g) + " " + str(line[0]*line[1]//g))
    except:
        exit()
Problem:
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.   For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.  In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi.   How many days from 2018-1-1 through 2018-a-b are Takahashi?

Incorrect submission (verdict: Wrong Answer):
def resolve():
    a, b = map(int, input().split())
    if a > b: c = a-1
    else: c = a
    print(c)

Fixed, accepted submission:
def resolve():
    a, b = map(int, input().split())
    if a <= b: c = a
    else: c = a - 1
    print(c)
resolve()
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 = list(input())
ans = 0
for i in range(N):
  A = S[:i]
  B = S[i:]
  C = list(set(A) & set(B))
  print(C)
  c = len(C)
  if c > ans:
    ans += 1

print(ans)


Fixed, accepted submission:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
  A = S[:i]
  B = S[i:]
  C = list(set(A) & set(B))
  #print(C)
  c = len(C)
  if c > ans:
    ans += 1

print(ans)
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("even")
else:
    print("odd")

Fixed, accepted submission:
a,b=map(int,input().split())
if a*b%2==0:
	print("Even")
else:
    print("Odd")
Problem:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.  Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.  Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.

Incorrect submission (verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
right = a+b
left = c+d
if(right<left):
  print("Left")
elif(left<right):
  print("Right")
else:
  print("Balanced")

Fixed, accepted submission:
a,b,c,d=map(int,input().split())
right = a+b
left = c+d
if(right>left):
  print("Left")
elif(right<left):
  print("Right")
else:
  print("Balanced")
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):
in_str = input()
for var in range(1,3):
    print("Case" + str(var) + ": " + in_str)

Fixed, accepted submission:
import sys
count = 1
while True:
    x = sys.stdin.readline().strip()
    if x == '0':
        break
    print("Case %d: %s" % (count, x))
    count += 1
Problem:
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:    * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.   * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.  You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.

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

Fixed, accepted submission:
n,m=map(int,input().split())
l1,r2=1,2*m+1
if m%2:
  r1=m
else:
  r1=m+1
l2=r1+1
for i in range(m//2):
  print(l1,r1)
  print(l2,r2)
  l1+=1
  l2+=1
  r1-=1
  r2-=1
if m%2:
  print(l2,r2)
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):
a, b = list(map(int, input().split()))

import math
math.ceil((a+b)/2)

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

import math
print(math.ceil((a+b)/2))