TnT/CodeNet4Repair huggingface dataset:
Problem:
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail:                 Counting-Sort(A, B, k) 1    for i = 0 to k 2        do C[i] = 0 3    for j = 1 to length[A] 4        do C[A[j]] = C[A[j]]+1 5    /* C[i] now contains the number of elements equal to i */ 6    for i = 1 to k 7    do C[i] = C[i] + C[i-1] 8    /* C[i] now contains the number of elements less than or equal to i */ 9    for j = length[A] downto 1 10       do B[C[A[j]]] = A[j] 11          C[A[j]] = C[A[j]]-1   Write a program which sorts elements of given array ascending order based on the counting sort.

Incorrect submission (verdict: Wrong Answer):
def InputData():
    
    sequence_len = int(input())
    sequence = [None] + [int(a) for a in input().split(" ")]

    return sequence_len, sequence

def countingSort(sequence, k, sequence_len):
    
    B = [None]*(sequence_len+1)
    C = [0]*k
    
    for j in range(1, sequence_len+1):
        C[sequence[j]] += 1
    
    for i in range(1, k):
        C[i] = C[i] + C[i-1]
    
    for j in range(sequence_len, 0, -1):
        B[C[sequence[j]]] = sequence[j]
        C[sequence[j]] -= 1

    return B

def PrintOut(sequence):
    print(' '.join( map(str, sequence)))

def main():
    [sequence_len, sequence] = InputData()
    sequence_out = countingSort(sequence, 10000, sequence_len)
    PrintOut(sequence[1:])

if __name__=="__main__":
    main()


Fixed, accepted submission:
def InputData():
    
    sequence_len = int(input())
    sequence = [None] + [int(a) for a in input().split(" ")]

    return sequence_len, sequence

def countingSort(sequence, k, sequence_len):
    
    B = [None]*(sequence_len+1)
    C = [0]*k
    
    for j in range(1, sequence_len+1):
        C[sequence[j]] += 1
    
    for i in range(1, k):
        C[i] = C[i] + C[i-1]
    
    for j in range(sequence_len, 0, -1):
        B[C[sequence[j]]] = sequence[j]
        C[sequence[j]] -= 1

    return B

def PrintOut(sequence):
    print(' '.join( map(str, sequence)))

def main():
    [sequence_len, sequence] = InputData()
    sequence_out = countingSort(sequence, 10000, sequence_len)
    PrintOut(sequence_out[1:])

if __name__=="__main__":
    main()
Problem:
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.

Incorrect submission (verdict: Wrong Answer):
print((pow(int(input()), 1/2)%1)**2)

Fixed, accepted submission:
print(int((pow(int(input()), 1/2)//1)**2))
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):
# PROXY

list = [int(i) for i in input().split()]
print(min(list),abs(list[1]-list[2]))

Fixed, accepted submission:
# PROXY

list = [int(i) for i in input().split()]
print(min(list),(list[1] + list[2]) - list[0] if (list[1] + list[2]) - list[0] > 0 else 0)
Problem:
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.  He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.

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

if (v - w > 0) and (a != b):
    if abs(a-b) <= (v - w) * t:
        print("Yes")
    else:
        print("No")
    
elif a == b:
    print("Yes")

else:
    print("No")

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

if (v - w > 0) and (a != b):
    if abs(a-b) <= (v - w) * t:
        print("YES")
    else:
        print("NO")
    
elif a == b:
    print("YES")

else:
    print("NO")
Problem:
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of   AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.

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

if (a-b)<=w:
  print(0)
else:
  print((a-b)-w)

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

if abs(a-b)<=w:
  print(0)
else:
  print(abs(a-b)-w)
Problem:
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament.  The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day.  Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline



S = input().rstrip()

win = 0
length = len(S)

for i in range(length):
    if S[i] == 'o':
        win += 1

win += 15 - length

if win >= 8:
    print("Yes")
else:
    print("No")


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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline



S = input().rstrip()

win = 0
length = len(S)

for i in range(length):
    if S[i] == 'o':
        win += 1

win += 15 - length

if win >= 8:
    print("YES")
else:
    print("NO")
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+b >= x and a >= x :
  print("YES")
  
else:
  print("NO")

Fixed, accepted submission:
a,b,x = map(int, input().split())
 
if a+b >= x and x >= a :
  print("YES")
  
else:
  print("NO")
Problem:
Ringo is giving a present to Snuke.  Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things.  You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.

Incorrect submission (verdict: Wrong Answer):
S = input()
if len(S) >= 4 and S[::4] == 'YAKI':
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
S = input()
if len(S) >= 4 and S[:4] == 'YAKI':
  print('Yes')
else:
  print('No')
Problem:
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:    * Hit his pocket, which magically increases the number of biscuits by one.   * Exchange A biscuits to 1 yen.   * Exchange 1 yen to B biscuits.  Find the maximum possible number of biscuits in Snuke's pocket after K operations.

Incorrect submission (verdict: Wrong Answer):
if __name__ == "__main__":
    K,A,B = map(int,input().split())
    
    if A > B:
        print(1 + K)
    elif B - A == 1:
        print(1 + K)
    else :
        if K < A - 1:
            print (1 + K)
        else:
            K -= A - 1
            if K % 2 == 0:
                print (A + (K / 2) * (B - A))
            else:
                print (A + ((K - 1) / 2) * (B - A) + 1)

Fixed, accepted submission:
if __name__ == "__main__":
    K,A,B = map(int,input().split())
    
    if B - A <= 2:
        print(K + 1)
    else :
        
        if K <= A-1:
            print(1 + K)
        else:
            
            rest = K - (A - 1)
            if rest < 2:
                print(1 + K)
            else:
                q,r = divmod(rest,2)
                print(A + q * (B - A) + r)
Problem:
You went shopping to buy cakes and donuts with X yen (the currency of Japan).  First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.  How much do you have left after shopping?

Incorrect submission (verdict: Wrong Answer):
x=int(input())
a=int(input())
b=int(input())
print(x-a--(x-a)//b)

Fixed, accepted submission:
print((int(input())-int(input()))%int(input()))
Problem:
Takahashi is distributing N balls to K persons.  If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?

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

Fixed, accepted submission:
a, b = map(int, input().split())
if b == 1:
    print(0)
else:
    print(a - b)
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())

print("Even" if (a * b) % 2 else "Odd" )

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

print("Even" if (a * b) % 2 == 0 else "Odd" )
Problem:
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`.  You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.

Incorrect submission (verdict: Wrong Answer):
s=input()
print(len(s[1:-1]))
print(s[0]+str(len(s[1:-1]))+s[-1])

Fixed, accepted submission:
s=input()
print(s[0]+str(len(s[1:-1]))+s[-1])
Problem:
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.  Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut:    * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).   * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.  Find the minimum amount of money needed before cutting the bar into two parts with the same length.

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

li = [0]*(n+1)

for i in range(n):
    li[i+1] = li[i] + a[i]
    
#print(li[n]%2)
tmp = 10**18

if li[n] % 2 == 1:
    li[n] += 1
    for i in range(n+1):
        #print(abs(li[i]-li[n]//2)<tmp)
        if abs(li[i]-li[n]//2) < tmp:
            tmp = abs(li[i]-li[n]//2)
        else:
            break
elif li[n] % 2 == 0:
    for i in range(n+1):
        #print(abs(li[i]-li[n]//2)<tmp)
        if abs(li[i]-li[n]//2) < tmp:
            tmp = abs(li[i]-li[n]//2)
        else:
            break

if li[n] % 2 == 0:
    print(tmp)
else:
    print(1+tmp*2)

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

li = [0]*(n+1)

for i in range(n):
    li[i+1] = li[i] + a[i]
    
#print(li)

li_sum = sum(a)

ans = 10**18

for i in range(n):
    #print(ans)
    if ans > abs(li_sum - 2*li[i]):
        ans = abs(li_sum - 2*li[i])
        
print(ans)
Problem:
Write a program which reads an integer and prints sum of its digits.

Incorrect submission (verdict: Wrong Answer):
while True:
    data = int(input())
    if data == 0:
        break

Fixed, accepted submission:
while True:
    data = input()
    if data[0] == '0':
        break

    print(sum([int(i) for i in data]))
Problem:
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**.  You are given a 4-digit integer N. Answer the question: Is N **good**?

Incorrect submission (verdict: Wrong Answer):
n = set(map(int, input()))
print(len(n))


Fixed, accepted submission:
n=input()
print("Yes" if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "No")
Problem:
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?

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

ans = b // x - a // x
print(ans)


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

ans = b // x - (a - 1) // x
print(ans)
Problem:
An elementary school student Takahashi has come to a variety store.  He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?  Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

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

if a+b > c:
    print("No")
else:
    print("Yes")

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

if a+b >= c:
    print("Yes")
else:
    print("No")
Problem:
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them.  He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).  Find the minimum total cost to achieve his objective.

Incorrect submission (verdict: Wrong Answer):
import math
n=int(input())
a=map(int, input().split())
ave = sum(a)/n
if math.ceil(ave)-ave > ave-math.floor(ave):
    t = math.floor(ave)
else:
    t = math.ceil(ave)
print(sum([(t-x)**2 for x in a]))

Fixed, accepted submission:
import math
n=int(input())
a=list(map(int, input().split()))
ave = sum(a)/n
if math.ceil(ave)-ave > ave-math.floor(ave):
    t = math.floor(ave)
else:
    t = math.ceil(ave)
total = 0
for v in a:
    total += (t-v) ** 2
print(total)
Problem:
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).  The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.

Incorrect submission (verdict: Wrong Answer):
# coding: utf-8
suits = ['S', 'H', 'C', 'D']
cards = [(suit + str(i)) for i in range(1, 14) for suit in suits]

for _ in range(int(input())):
    cards.remove(''.join(input().split()))

for trump in cards:
    print(trump[0], trump[1:])



Fixed, accepted submission:
# coding: utf-8
suits = ['S', 'H', 'C', 'D']
cards = [(suit + str(i)) for suit in suits for i in range(1, 14)]

for _ in range(int(input())):
    cards.remove(''.join(input().split()))

for trump in cards:
    print(trump[0], trump[1:])
Problem:
We have a grid with N rows and M columns of squares. Initially, all the squares are white.  There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted.  Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Incorrect submission (verdict: Wrong Answer):
n, m, k = map(int, input().split())

if k == 0 or k == n * m:
    print("Yes")
    exit()

for i in range((n + 1) // 2):
    for j in range((m + 1) // 2):
        if i * j + (n - i) * (m - j) == k:
            print("Yes")
            exit()
print("No")

Fixed, accepted submission:
n, m, k = map(int, input().split())
for i in range(n + 1):
    for j in range(m + 1):
        black = i * (m - j) + (n - i) * j
        if black == k:
            print("Yes")
            exit()
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):
#!/usr/bin/env python3
from collections import deque

def main():
    N = int(input())
    adj = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        adj[a].append((b,i))
        adj[b].append((a,i))
    p = max([len(a) for a in adj])
    ans = [-1] * (N-1)
    visited = [-1] * N
    ans[0] = 1
    q = deque([0])
    
    while q:
        now = q.popleft()
        tmp = 1
        for v in adj[now]:
            if visited[v[0]] < 0:
                q.append(v[0])
                ans[v[1]] = (tmp + 1) % p
                tmp += 1
                visited[v[0]] = 0
                if ans[v[1]] == 0:
                    ans[v[1]] += p
            else:
                tmp = ans[v[1]]
    print(p)
    [print(a) for a in ans]

if __name__ == "__main__":
    main()


Fixed, accepted submission:
#!/usr/bin/env python3
from collections import deque

def main():
    N = int(input())
    adj = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        adj[a].append((b,i))
        adj[b].append((a,i))
    p = max([len(a) for a in adj])
    ans = [-1] * (N-1)
    visited = [-1] * N
    visited[0] = 0
    q = deque([0])
    
    while q:
        now = q.popleft()
        tmp = 0
        for v in adj[now]:
            if visited[v[0]] == 0:
                tmp = ans[v[1]]
                break
        
        for v in adj[now]:
            if visited[v[0]] < 0:
                q.append(v[0])
                ans[v[1]] = (tmp+1) % p
                tmp += 1
                visited[v[0]] = 0
                if ans[v[1]] == 0:
                    ans[v[1]] += p
    print(p)
    [print(a) for a in ans]

if __name__ == "__main__":
    main()
Problem:
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.  He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.  So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`.  Find the minimum number of iterations for the rewrite operation.

Incorrect submission (verdict: Wrong Answer):
s = input()
x,ans = "CODEFESTIBAL2016",0
for i in range(16):
  if x[i]!=s[i]: ans += 1
print(ans)

Fixed, accepted submission:
s = input()
x,ans = "CODEFESTIVAL2016",0
for i in range(16):
  if x[i]!=s[i]: ans += 1
print(ans)
Problem:
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

Incorrect submission (verdict: Wrong Answer):
n = int(input())
print("{}".format(n*(n+1)/2))

Fixed, accepted submission:
n = int(input())
print("{}".format(int(n*(n+1)/2)))
Problem:
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.  We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly.  For each city, find the number of the cities connected to that city by both roads and railways.

Incorrect submission (verdict: Wrong Answer):
n,k,l=map(int,input().split())
from collections import defaultdict
road=defaultdict(set)
metro=defaultdict(set)
for i in range(k):
    p,q=map(int,input().split())
    road[p]|={q,}
for j in range(l):
    r,s=map(int,input().split())
    metro[r]|={s,}

city={i for i in range(1,n+1)}
def maketree(n,target):
    city={i for i in range(1,n+1)}
    tree=[]
    now=1
    block={now,}
    city-={now,}
    block|=target[now]
    count=0
    while len(city)>0:
        for i in target[now]:
            block|=target[i]
            city-={i,}
        next=city & block
        
        if len(next)>0:
            now=next.pop()
            block|=target[now]
            city-={now,}
        elif len(next)==0:
            tree.append(block)
            if len(city)!=0:
                now=city.pop()
                block={now,}
                city-={now,}
                block|=target[now]
                if len(city)==0:tree.append(block)
    return tree
roadtree=maketree(n,road)
metrotree=maketree(n,metro)

ans=[]
for i in roadtree:
    for j in metrotree:
        ans.append(i & j)

result=[1 for i in range(n)]
while len(ans)>0:
    x=ans.pop()
    for i in x:
        result[i-1]=len(x)
        
res=''
for i in range(n):
    res=res+str(result[i])+' '

Fixed, accepted submission:
import sys
input=sys.stdin.readline
N,K,L=map(int,input().split())
road=[tuple(map(int,input().split())) for _ in range(K)]
metro=[tuple(map(int,input().split())) for _ in range(L)]
inf=float('inf')
def Find(root,x):
    if root[x]<0:
        return x
    if root[x]>=0:
        root[x]=Find(root,root[x])
        return root[x]

def UnionFind(N,branch):
    root=[-1]*(N+1)
    for a,b in branch:
        aroot=Find(root,a)
        broot=Find(root,b)
        if aroot==broot:continue
        elif root[aroot]<=root[broot]:
            root[aroot]+=root[broot]
            root[broot]=aroot
        elif root[aroot]>root[broot]:
            root[broot]+=root[aroot]
            root[aroot]=broot
    return root
r_root=UnionFind(N,road)
m_root=UnionFind(N,metro)
from collections import defaultdict
data=[]
cnt=defaultdict(int)
for i in range(1,N+1):
    ri=Find(r_root,i)
    mi=Find(m_root,i)
    data.append((ri,mi))
    cnt[(ri,mi)]+=1
ans=''
for d in data:
    ans+=str(cnt[d])+' '
print(ans[:-1])
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):
import random
N = int(input())
A = random.sample(range(1000000), k=N)
c = 1000000
for i in range(len(A)):
    tmp = 0
    while A[i]%2 == 0:
        tmp+=1
        A[i] //= 2
    c = min(c,tmp)
print(c)

Fixed, accepted submission:
N = int(input())
A = list(map(int,input().split()))
c = 1000000
for i in range(len(A)):
    tmp = 0
    while A[i]%2 == 0:
        tmp += 1
        A[i] //= 2
    c = min(c,tmp)
print(c)