TnT/CodeNet4Repair huggingface dataset:
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):
m = int(input())
num_list = list(map(int,input().split()))
ans_list = [0]*m
print_list = []
for i in range(m):
    if num_list[m-i-1] == 0:
        continue
    elif num_list[m-i-1] == 1:
        cnt = 0
        for j in range(2**10):
            if (j+1)*(m-i) > m:
                break
            else:
                cnt += ans_list[(m-i)*(j+1)-1]
        if cnt % 2 == 0:
            ans_list[m-i-1] = 1
            print_list.append(m-i)
            
if not print_list:
    print(0)
    
else:
    print(*print_list)

Fixed, accepted submission:
m = int(input())
num_list = list(map(int,input().split()))
ans_list = [0]*m
print_list = []
for i in range(m,0,-1):
    if num_list[i-1] == 0:
        cnt = 0
        for j in range(2,m//i+1):
            cnt += ans_list[i*j-1]
        if cnt % 2 == 1:
            ans_list[i-1] = 1
            print_list.append(i)
    elif num_list[i-1] == 1:
        cnt = 0
        for j in range(2,m//i+1):
            cnt += ans_list[i*j-1]
        if cnt % 2 == 0:
            ans_list[i-1] = 1
            print_list.append(i)
            
if not print_list:
    print(0)
    
else:
    print(sum(ans_list))
    print(*print_list)
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
import sys
S=input()
for i in range(1,len(S)):
  S=S[:-1]
  if len(S)%2==0:
    c=len(S)
    print(S[c//2+1:])
    print(S[:c//2])
    if S[:c//2]==S[c//2+1:]:
      print(i)
      sys.exit()

Fixed, accepted submission:
import sys
S=input()
for i in range(1,len(S)):
  S=S[:-1]
  if len(S)%2==0:
    c=len(S)
    if S[:c//2]==S[c//2:]:
      print(c)
      sys.exit()
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):
#65

X, A, B = map(int, input().rstrip().split())

if A-B >= 0:
    print("delicious")
elif X+A-B >= 0:
    print("Safe")
elif X+1+A-B <= 0:
    print("dangerous")

Fixed, accepted submission:
#65

X, A, B = map(int, input().rstrip().split())

if A-B >= 0:
    print("delicious")
elif X+A-B >= 0:
    print("safe")
elif X+1+A-B <= 0:
    print("dangerous")
Problem:
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.  Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:    * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter.  What is the minimum number of operations required to achieve the objective?

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  if len(set([a,b,c]))==3:
    ans+=2
  elif len(set([a,b,c]))==2:
    ans+=1
print(ans)
    

Fixed, accepted submission:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  ans+=len(set([a[i],b[i],c[i]]))-1
print(ans)
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 = map(int, input().split())
S = input()
for s in S:
  if s == "a" and A > 0:
    print("Yes")
    A -= 1
  elif s == "b" and B > 0:
    print("Yes")
    B -= 1
  else:
    print("No")

Fixed, accepted submission:
N, A, B = map(int, input().split())
S = input()
for s in S:
  if s == "a" and A > 0:
    print("Yes")
    A -= 1
  elif s == "a" and B > 0:
    print("Yes")
    B -= 1
  elif s == "b" and B > 0:
    print("Yes")
    B -= 1
  else:
    print("No")
Problem:
Snuke loves working out. He is now exercising N times.  Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i.  Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Incorrect submission (verdict: Wrong Answer):
import math
print(math.factorial(5))

Fixed, accepted submission:
import math
N=int(input())
print(math.factorial(N)%(10**9+7))
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):
a, b, c = map(int, input().split())
if int(a + b + c) % 4 == 0:
  print('YES')
else:
  print('NO')

Fixed, accepted submission:
a, b, c = input().split()
if int(a + b + c) % 4 == 0:
  print('YES')
else:
  print('NO')
Problem:
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019.  Integers M_1, D_1, M_2, and D_2 will be given as input.   It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1.   Determine whether the date 2019-M_1-D_1 is the last day of a month.

Incorrect submission (verdict: Wrong Answer):
a, b = map(int,input().split())
c, d = map(int,input().split())
if a == b:
  print(0)
else:
  print(1)

Fixed, accepted submission:
a, b = map(int,input().split())
c, d = map(int,input().split())
if a == c:
  print(0)
else:
  print(1)
Problem:
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b.  Determine whether the arrangement of the poles is beautiful.

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

Fixed, accepted submission:
a, b, c = map(int, input().split())
print('YES' if (b - a) == (c - b) else 'NO')
Problem:
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.  For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left.  Assume that initially no person lives in the building.

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

apartment = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
N = int(input())
for i in range(N):
	data = [int(x) - 1 for x in input().split()]
	apartment[data[0]][data[1]][data[2]] = data[3] + 1
for x in range(4):
	for y in range(3):
		for z in range(10):
			print(apartment[x][y][z], end="")
		print()
	if x != 3:
		print("#"*10)

Fixed, accepted submission:
#coding:utf-8

apartment = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
N = int(input())
data = [[int(x) - 1 for x in input().split()] for y in range(N)]
for x in data:
	apartment[x[0]][x[1]][x[2]] += x[3] + 1
	if apartment[x[0]][x[1]][x[2]] > 9:
		apartment[x[0]][x[1]][x[2]] = 9
	elif apartment[x[0]][x[1]][x[2]] < 0:
		apartment[x[0]][x[1]][x[2]] = 0
for x in range(4):
	for y in range(3):
		for z in range(10):
			print(" " + str(apartment[x][y][z]), end="")
		print()
	if x != 3:
		print(("#"*20))
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):
Num = input()
op = -1
A = int(Num[0])
B = int(Num[1])
C = int(Num[2])
D = int(Num[3])
sign = [0]*3

for i in range(2):
    for j in range(2):
        for k in range(2):
            if(A+B*op**(i+1)+C*op**(j+1)+D*op**(k+1) == 7):
                sign[0] = i
                sign[1] = j
                sign[2] = k
                quit()

for n in range(3):
    if(sign[n] == 0):
        sign[n] = "-"
    else:
        sign[n] = "+"

print(str(A)+sign[0]+str(B)+sign[1]+str(C)+sign[2]+str(D)+"=7")

Fixed, accepted submission:
Num = input()
op = -1
A = int(Num[0])
B = int(Num[1])
C = int(Num[2])
D = int(Num[3])
sign = []

for i in range(2):
    for j in range(2):
        for k in range(2):
            if(A+B*op**i+C*op**j+D*op**k == 7):
                sign.append(i)
                sign.append(j)
                sign.append(k)

for n in range(3):
    if(sign[n] == 0):
        sign[n] = "+"
    else:
        sign[n] = "-"

print(Num[0]+sign[0]+Num[1]+sign[1]+Num[2]+sign[2]+Num[3]+"=7")
Problem:
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:    * For any two vertices painted in the same color, the distance between them is an even number.  Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline
def main():
    def Dfs(G, v, cur=0):
        color[v] = cur % 2
        for next_v in G[v]:
            if color[next_v[0]] != -1:
                continue
            Dfs(G, next_v[0], cur+next_v[1])


    n = int(input())
    e = [[0, 0, 0]] + [list(map(int, input().split())) for i in range(n-1)]
    g = [[] for i in range(n+1)]
    print(n, e);
    for i in range(1, n):
        g[e[i][0]].append([e[i][1], e[i][2]])
        g[e[i][1]].append([e[i][0], e[i][2]])

    color = [-1 for i in range(n+1)]
    for v in range(1, n+1):
        if color[v] != -1:
            continue
        Dfs(g, v)

    for i in range(1, n+1):
        print(color[i])

if __name__ == '__main__':
    main()

Fixed, accepted submission:
import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline
def main():
    def Dfs(G, v, cur=0):
        color[v] = cur % 2
        for next_v in G[v]:
            if color[next_v[0]] != -1:
                continue
            Dfs(G, next_v[0], cur+next_v[1])


    n = int(input())
    e = [[0, 0, 0]] + [list(map(int, input().split())) for i in range(n-1)]
    g = [[] for i in range(n+1)]

    for i in range(1, n):
        g[e[i][0]].append([e[i][1], e[i][2]])
        g[e[i][1]].append([e[i][0], e[i][2]])

    color = [-1 for i in range(n+1)]
    for v in range(1, n+1):
        if color[v] != -1:
            continue
        Dfs(g, v)

    for i in range(1, n+1):
        print(color[i])

if __name__ == '__main__':
    main()
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 = map(int,input().split())

print(-(-a+b//2))

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

print(-(-(a+b)//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())
li = list(map(int, input().split()))
count = 0
def calc_half(n):
  return n/2
for i in range(N):
  for i in li:
    if i%2 == 0:
      flag = True
    else:
      flag = False
      break
  if flag == True:
    li = map(calc_half, li)
    count += 1
    
print(count)

Fixed, accepted submission:
N = int(input())
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)
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):
n,p=map(int,input().split())
from collections import Counter
a=[]
while p%2==0:
  a.append(2)
  p//=2
f=3
while f<=p:
  if p%f==0:
    a.append(f)
    p//=f
  else:
      f+=2
c=Counter(a)
ans=1
print(c)
for k,v in c.items():
  if v>=n:
    ans*=k
print(ans)

Fixed, accepted submission:
n,p=map(int,input().split())
from collections import Counter
a=[]
while p%2==0:
  a.append(2)
  p//=2
f=3
while f<=p:
  if p%f==0:
    a.append(f)
    p//=f
  elif f*f>p:
    a.append(p)
    break
  else:
      f+=2
c=Counter(a)
ans=1
for k,v in c.items():
  if v>=n:
    ans*=k**(v//n)
print(ans)
Problem:
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one.  At least how many operations are necessary to satisfy the following conditions?    * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.   * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.

Incorrect submission (verdict: Wrong Answer):
n=int(input())
a=list(map(lambda x: int(x), input().split()))
a.sort()
cnt=[]
val=[]
last=-1
for i in a:
    if i == last:
        cnt[-1]+=1
    else:
        cnt.append(1)
        val.append(i)
        last = i

low_val=-10
low_cnt=0
mid_val=0
mid_cnt=0
ans=0
for i, v in enumerate(val):
    if v>=low_val+3:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        low_val=v
        low_cnt=cnt[i]
        mid_val=0
        mid_cnt=0
    elif v==low_val+2:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        if mid_val>0:
            low_val=mid_val
            low_cnt=mid_cnt
            mid_val=v
            mid_cnt=cnt[i]
        else:
            low_val=v
            low_cnt=cnt[i]
            mid_val=0
            mid_cnt=0
    if v==low_val+1:
        mid_val=v
        mid_cnt=cnt[i]
ans=max(ans, low_cnt+mid_cnt)
print(ans)

Fixed, accepted submission:
n=int(input())
a=list(map(lambda x: int(x), input().split()))

ans_plus=0
tmp=0
if a[0]<=0:
    ans_plus=1-a[0]
    tmp=1
else:
    tmp=a[0]
plus_flag=False
for i in a[1:]:
    tmp+=i
    if plus_flag==True and tmp>0:
        pass
    elif plus_flag==True and tmp<=0:
        ans_plus+=1-tmp
        tmp=1
    elif plus_flag==False and tmp<0:
        pass
    elif plus_flag==False and tmp>=0:
        ans_plus+=1+tmp
        tmp=-1
    plus_flag=not plus_flag


ans_minus=0
tmp=0
if a[0]>=0:
    ans_minus=1+a[0]
    tmp=-1
else:
    tmp=a[0]
plus_flag=True
for i in a[1:]:
    tmp+=i
    if plus_flag==True and tmp>0:
        pass
    elif plus_flag==True and tmp<=0:
        ans_minus+=1-tmp
        tmp=1
    elif plus_flag==False and tmp<0:
        pass
    elif plus_flag==False and tmp>=0:
        ans_minus+=1+tmp
        tmp=-1
    plus_flag=not plus_flag
#print(ans_minus)
print(min(ans_plus, ans_minus))
Problem:
There is a string s of length 3 or greater. No two neighboring characters in s are equal.  Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:    * Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.  The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.

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

s = input()

if (s[0] == s[-1]) ^ (len(s) % 2 == 0):
    print('First')
else:
    print('Second')

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

s = input()

if (s[0] == s[-1]) ^ (len(s) % 2 == 0):
    print('Second')
else:
    print('First')
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,a=map(int,input().split())
for i in range(1,n):
  c,d=map(int,input().split())
  e,f=c,d
  times=1
  while(e<t and f<a):
    times+=1
    e,f=c*times,d*times
  t,a=e,f
print(t+a)

Fixed, accepted submission:
n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
  c,d=map(int,input().split())
  if(t/c>a/d):
    if(t%c==0):times=t//c
    else:times=t//c+1
  else:
    if(a%d==0):times=a//d
    else:times=a//d+1
  #print(times)
  t,a=c*times,d*times
  #print(t,a)
print(t+a)
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 = [int(x) for x in input().split()]

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

Fixed, accepted submission:
a,b = [int(x) for x in input().split()]

if (a*b) % 2 == 0:
  print("Even")
else:
  print("Odd")
Problem:
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer.  Snuke's objective is to permute the element in a so that the following condition is satisfied:    * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.  Determine whether Snuke can achieve his objective.

Incorrect submission (verdict: Wrong Answer):
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if factor_of_four_cnt >= non_factor_cnt + factor_of_two_cnt % 2:
        print('Yes')
    else:
        print('No')

main()

Fixed, accepted submission:
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if factor_of_two_cnt == 0:
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()
Problem:
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.  In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).  Your task is to read a sequence A and perform the Partition based on the following pseudocode:                 Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4     do if A[j] <= x 5        then i = i+1 6            exchange A[i] and A[j]  7 exchange A[i+1] and A[r] 8 return i+1   Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].

Incorrect submission (verdict: Wrong Answer):
def partition(A, p, r):
    x = A[r]
    i = p-1

    for j in range(p, r):
        if A[j] <= x:
            i = i+1
            tmpA = A[i]
            A[i] = A[j]
            A[j] = tmpA

    tmpB = A[i+1]
    A[i+1] = A[r]
    A[r] = tmpB
    return i+1


n = int(input())
A = list(map(int, input().split()))
r = len(A)-1
p = 0
partition(A, p, r)
print(A)



Fixed, accepted submission:
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    A[i+1] = "[{}]".format(A[i+1])


n = int(input())
A = list(map(int, input().split()))
partition(A, 0, n-1)
print(*A)