TnT/CodeNet4Repair huggingface dataset:
Problem:
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i.  Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition:    * For every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3.  Here the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j.  Help Takahashi by finding a permutation that satisfies the condition.

Incorrect submission (verdict: Wrong Answer):
from collections import deque
n = int(input())
E = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

def bfs(cur, pre, c):
    stack = deque([[cur, pre, c]])
    while stack:
        cur, pre, c = stack.popleft()
        if c <= 3:
            for e in E[cur]:
                if e != pre:
                    stack.append([e, cur, c+1])

for i in range(n):
    bfs(i, -1, 0)

print(-1)


Fixed, accepted submission:
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
E = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

mod = [3, 1, 2]
ans = [0 for i in range(n)]
count = [0, 0]

def bfs(cur, pre, c):
    stack = deque([[cur, pre, c]])
    while stack:
        cur, pre, c = stack.popleft()
        count[c % 2] += 1
        for e in E[cur]:
            if e != pre:
                stack.append([e, cur, c+1])

def case1(cur, pre, c, i):
    stack = deque([[cur, pre, c]])
    while stack:
        cur, pre, c = stack.popleft()
        t = c % 2
        if t == i:
            ans[cur] = mod[0]
            mod[0] += 3
        else:
            if mod[1] <= n:
                ans[cur] = mod[1]
                mod[1] += 3
            elif mod[2] <= n:
                ans[cur] = mod[2]
                mod[2] += 3
            else:
                ans[cur] = mod[0]
                mod[0] += 3
        for e in E[cur]:
            if e != pre:
                stack.append([e, cur, c+1])

def case2(cur, pre, c):
    stack = deque([[cur, pre, c]])
    while stack:
        cur, pre, c = stack.popleft()
        t = c % 2
        if mod[t+1] <= n:
            ans[cur] = mod[t+1]
            mod[t+1] += 3
        else:
            ans[cur] = mod[0]
            mod[0] += 3
        for e in E[cur]:
            if e != pre:
                stack.append([e, cur, c+1])

bfs(0, -1, 0)

if count[0] <= n // 3:
    case1(0, -1, 0, 0)
elif count[1] <= n  // 3:
    case1(0, -1, 0, 1)
else:
    case2(0, -1, 0)

print(" ".join([str(i) for i in ans]))
Problem:
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N).  For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.  We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:    * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.  Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Incorrect submission (verdict: Wrong Answer):
import math
N = int(input())
a_list = [0] + list(map(int, input().split()))
result = True
answer_box = [0] * (N+1)
inboxes = []
for i in range(N, 0, -1):
    last_i = i * (N // i)
    count = 0
    for j in range(last_i, i-1, -i):
        print(N, i, j)
        count += answer_box[j]
    if (count % 2) != a_list[i]:
        answer_box[i] = 1
        inboxes.append(i)

if(result):
    print(len(inboxes))
    if(len(inboxes) > 0):
        print(" ".join(str(e) for e in inboxes))
else:
    print(-1)


Fixed, accepted submission:
import math
N = int(input())
a_list = [0] + list(map(int, input().split()))
result = True
answer_box = [0] * (N+1)
inboxes = []
for i in range(N, 0, -1):
    last_i = i * (N // i)
    count = 0
    for j in range(last_i, i-1, -i):
        count += answer_box[j]
    if (count % 2) != a_list[i]:
        answer_box[i] = 1
        inboxes.append(i)

if(result):
    print(len(inboxes))
    if(len(inboxes) > 0):
        print(" ".join(str(e) for e in inboxes))
else:
    print(-1)
Problem:
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.  The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:    * A: Swim in the sea. Gain a_i points of happiness.   * B: Catch bugs in the mountains. Gain b_i points of happiness.   * C: Do homework at home. Gain c_i points of happiness.  As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.  Find the maximum possible total points of happiness that Taro gains.

Incorrect submission (verdict: Wrong Answer):
def calc_happiness(h):
    n = len(h)
    if (n == 0):
        return 0

    states = [[None, None, None]] * len(h)
    states[0] = h[0]
    for i in range(1, n):
        states[i][0] = h[i][0] + max(h[i-1][1], h[i-1][2])
        states[i][1] = h[i][1] + max(h[i-1][0], h[i-1][2])
        states[i][2] = h[i][2] + max(h[i-1][0], h[i-1][1])

    return max(states[n-1][0], states[n-1][1], states[n-1][2])

if __name__ == "__main__":
    n = int(input())
    h = [[]] * n
    for day in range(n):
        h[day] = list(map(int, input().split(" ")))
    res = calc_happiness(h)
    print(res)

Fixed, accepted submission:
def calc_happiness(h):
    n = len(h)

    states = [[None, None, None] for i in range(n)]
    states[0] = h[0]
    for i in range(1, n):
        states[i][0] = h[i][0] + max(states[i-1][1], states[i-1][2])
        states[i][1] = h[i][1] + max(states[i-1][0], states[i-1][2])
        states[i][2] = h[i][2] + max(states[i-1][0], states[i-1][1])
    return max(states[n-1][0], states[n-1][1], states[n-1][2])

if __name__ == "__main__":
    n = int(input())
    h = [[]] * n
    for day in range(n):
        h[day] = list(map(int, input().split(" ")))
    res = calc_happiness(h)
    print(res)
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):
def calc(l):
    r = 0
    finish = False
    while True:
        for i in range(0, len(l)):
            if l[i] % 2 == 0:
                l[i] = l[i]//2
            else:
                finish = True
                break
        if finish:
            break
        print(l)
        r += 1

    return r


_ = input()
l = list(map(int, input().split()))
r = calc(l)
print(r)


Fixed, accepted submission:
def calc(l):
    r = 0
    finish = False
    while True:
        for i in range(0, len(l)):
            if l[i] % 2 == 0:
                l[i] = l[i]//2
            else:
                finish = True
                break
        if finish:
            break
        r += 1

    return r


_ = input()
l = list(map(int, input().split()))
r = calc(l)
print(r)
Problem:
It is September 9 in Japan now.  You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

Incorrect submission (verdict: Wrong Answer):
l = list(input())

for i in l:
    if i == "9":
        print("Yes")
    else:
        print("No")


Fixed, accepted submission:
l = list(input())
for i in l:
    if i == "9":
        print("Yes")
        break
else:
    print("No")
Problem:
Write a program which calculates the cube of a given integer x.

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

Fixed, accepted submission:
x = int(input())
print(x * x * x)
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):
N, A, B = list(map(int, input().split()))
S = input()
y, yab = 0, 0

for s in S:
    if(s == 'a'):
        if(y <= A + B):
            print("Yes")
            y += 1
        else:
            print("No")
    elif(s == 'b'):
        if(y <= A + B and yab <= B):
            print("Yes")
            y += 1
            yab += 1
        else:
            print("No")
    else:
        print("No")

Fixed, accepted submission:
N, A, B = list(map(int, input().split()))
S = input()
y, yab = 0, 1

for s in S:
    if(s == 'a'):
        if(y < A + B):
            print("Yes")
            y += 1
        else:
            print("No")
    elif(s == 'b'):
        if(y < A + B and yab <= B):
            print("Yes")
            y += 1
            yab += 1
        else:
            print("No")
    else:
        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(x):
  list = []
  list.append(2)
  list.append(0)
  i = 2
  while i <= x:
    list.append(list[i-1]+list[i-2])
    i += 1
  return list
      
 
if __name__ == '__main__':
  inputstr = input()
  num = int(inputstr)
  list = lucas(num)
  ans = list[num]
  print(ans,flush=True)

Fixed, accepted submission:

def lucas(x):
  list = []
  list.append(2)
  list.append(1)
  i = 2
  while i <= x:
    list.append(list[i-1]+list[i-2])
    i += 1
  return list
      
 
if __name__ == '__main__':
  inputstr = input()
  num = int(inputstr)
  list = lucas(num)
  ans = list[num]
  print(ans,flush=True)
Problem:
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.  The problem has N test cases.  For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.  See the Output section for the output format.

Incorrect submission (verdict: Wrong Answer):
d={'AC':0,'WA':0,'TLE':0,'RE':0}
n=int(input())
for i in range(0,n):
    d[input()]+=1
for j in d:
    print(j,"X",d[j])

Fixed, accepted submission:
d={'AC':0,'WA':0,'TLE':0,'RE':0}
n=int(input())
for i in range(0,n):
    d[input()]+=1
for j in d:
    print(j,"x",d[j])
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):

nums = input("NとLスペース区切りで入力").split()
N = int(nums[0])
L = int(nums[1])
print("N=" + str(N))
print("L=" + str(L))


count = 0
print("start")
list = []

while count < N:
    list.append(input())
    count += 1

s_list = sorted(list)
print(s_list)
print(''.join(s_list))


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



count = 0
list = []

while count < N:
    list.append(input())
    count += 1

s_list = sorted(list)
print(''.join(s_list))
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):
import numpy as np

A = list(map(int,input().split()))
count = 0

while all(a % 2 == 0 for a in A):
  A = [a/2 for a in A]
  count += 1
  
print(count)


Fixed, accepted submission:
a = str(input())
count = 0

for i in list(a):
  if i == "1":
    count = count +1
print(count)
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
import math
N = int(input())
m = math.ceil(N//1000)
n_coin = 0
change = 1000*m-N
if change >= 500:
    n_coin +=1
    change -= 500
while change >= 100:
    n_coin += 1
    change -= 100
if change >= 50:
    n_coin +=1
    change -= 50
while change >= 10:
    n_coin += 1
    change -= 10
if change >= 5:
    n_coin +=1
    change -= 5
while change >= 1:
    n_coin += 1
    change -= 1
print(n_coin)

Fixed, accepted submission:
import math
N = int(input())
m = math.ceil(N/1000)
n_coin = 0
change = 1000*m - N
print(change)
Problem:
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:    * 1 \leq x,y,z   * x^2 + y^2 + z^2 + xy + yz + zx = n  Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

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

def number(i):
   for j in range(1,41):
      for k in range(1,58):
         for u in range(1,101):
            if i==j*j+k*k+u*u+j*k+k*u+u*j:
               if j==k and k==u:
                  print(1)
                  return
               elif j==k or k==u:
                  print(3)
                  return
               else:
                  print(6)
                  return

   print(0)
   return

for h in range(n):
   number(h)

Fixed, accepted submission:
n=int(input())
y=[0 for _ in range(10**4+1)]
for j in range(1,100):
   for k in range(1,100):
      for u in range(1,100):
         a=j*j+k*k+u*u+j*k+k*u+u*j
         if a <= 10**4:
            y[a-1]+=1
for o in range(n):
   print(y[o])
Problem:
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N.  When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness.  Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".  Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".

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


def main():
    N = int(input())
    A = np.array([])
    B = np.array([])
    for i in range(0, N):
        a, b = map(int, input().split())
        A = np.append(A, [a])
        B = np.append(B, [b])
    
    
    
    
    
    sub(N, A, B)


def sub(N, A, B):
    takahashi = 0
    aoki = 0
    
    sum_AB = A + B
    print(A, B)
    for i in range(1, N + 1):
        max_idx = np.argmax(sum_AB)
        print(sum_AB, max_idx)
        if i % 2 == 1:
            takahashi += A[max_idx]
        else:
            aoki += B[max_idx]
        sum_AB[max_idx] = -1

    print(takahashi - aoki)



main()


Fixed, accepted submission:
import numpy as np


def main():
    N = int(input())
    A = []
    B = []
    for i in range(0, N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    
    takahashi = 0
    aoki = 0
    
    A = np.array(A)
    B = np.array(B)
    sum_AB = A + B
    l = sum_AB.argsort()[::-1]
    takahashi = sum([A[i] for i in [j for idx, j in enumerate(l) if idx % 2 == 0]])
    aoki = sum([B[i] for i in [j for idx, j in enumerate(l) if idx % 2 != 0]])

    print(int(takahashi - aoki))


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

Incorrect submission (verdict: Wrong Answer):
S = input()
if len(S) == 2:
    print(S)
else:
    print(reversed(S))

Fixed, accepted submission:
S = input()
if len(S) == 2:
    print(S)
else:
    print(S[::-1])
Problem:
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.  Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
s = input()

ans = [0 for i in range(n + 1)]

for i in range(n):
    for j in range(n + 1):
        if j <= i:
            if s[i] == '.':
                ans[j] += 1
        else:
            if s[i] == '#':
                ans[j] += 1
print(ans)



Fixed, accepted submission:

n = int(input())
s = input()

b = 0
w = 0
tb = 0
tw = 0

for i in reversed(range(n)):
    if s[i] == '#':
        tb += 1
        if tb > tw:
            b += tb
            w += tw
            tb = 0
            tw = 0
    else:
        tw += 1
print(tb + w)
Problem:
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.  He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.  Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
d = {}
X =[]
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.append(x)
    else:
        d[x] += 1
ans = 0
for x in X:
    a = d[x]
    if a%2 == 0:
        ans += a//2 - 1
    else:
        ans += a//2
        X.remove(x)
n = len(X)
ans += (n+1)//2
print(ans)

Fixed, accepted submission:
N = int(input())
A = list(map(int,input().split()))
from collections import deque
d = {}
X = deque()
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.appendleft(x)
    else:
        d[x] += 1
ans = 0
from collections import deque
Y=deque()
while X:
    x = X.popleft()
    a = d[x]
    if a%2 == 0:
        ans += a-2
        Y.appendleft(x)
    else:
        ans += a-1

n = len(Y)
ans += ((n+1)//2)*2
print(N-ans)
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

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

n = 100 * r + 10 * g + b

if n % 4 == 0:
    print("Yes")
else:
    print("No")


Fixed, accepted submission:
r, g, b = map(int, input().split(" "))

n = 100 * r + 10 * g + b

if n % 4 == 0:
    print("YES")
else:
    print("NO")
Problem:
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.  Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.  Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Incorrect submission (verdict: Wrong Answer):
import sys

sys.setrecursionlimit(100000)

class Tree():
    def __init__(self, n, root, connects):
        self.root = root
        self.connects = connects
        self.parents = [0] * n
        self.parents[root] = None
        self.children = [0] * n
        self.children[self.root] = connects[self.root]
        self.make_tree(self.root)

    def make_tree(self, node):
        for child in self.children[node]:
            self.parents[child] = node
            self.children[child] = [c for c in self.connects[child] if c != node]
            if self.children[child] != []:
                self.make_tree(child)


def main():
    n = int(input())
    G = [[] for _ in range(n)]
    ID = [dict() for _ in range(n)]
    for i in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        G[b].append(a)
        ID[a][b] = i
        ID[b][a] = i
    t = Tree(n, root = 0, connects = G)
    m = max(len(g) for g in G)
    ans = [0] * (n - 1)
    def bfs(a, pre = set()):
        color = list(set(range(m)) - pre)
        for b in t.children[a]:
            c = color.pop()
            ans[ID[a][b]] = c
            bfs(b, set([c]))
    bfs(0)
    [print(a) for a in ans]
      
if __name__ == '__main__':
    main()


Fixed, accepted submission:
import sys

sys.setrecursionlimit(100000)

def main():
    n = int(input())
    G = [[] for _ in range(n)]
    ID = [dict() for _ in range(n)]
    for i in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        G[b].append(a)
        ID[a][b] = i
        ID[b][a] = i
    m = max(len(g) for g in G)
    ans = [0] * (n - 1)
    def bfs(a, pre = -1, pre_c = -1):
        color = 1
        for b in G[a]:
            if b == pre: continue
            if color == pre_c: color += 1
            ans[ID[a][b]] = color
            bfs(b, a, color)
            color += 1

    bfs(0)
    print(m)
    [print(a) for a in ans]
      
if __name__ == '__main__':
    main()