TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:    * Choose two among A, B and C, then increase both by 1.   * Choose one among A, B and C, then increase it by 2.  It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Incorrect submission (verdict: Wrong Answer):
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    A, B, C = il()
    diff = sorted([abs(A - B), abs(B - C)])
    c = 0
    for i, d in enumerate(diff):
        div_2 = d // 2
        if div_2 > 0:
            c += d // 2
            diff[i] -= 2 * div_2
    for i, j in ((1, 0), (0, 1)):
        if diff[i] == 1:
            if diff[j] == 1:
                c += 1
            elif diff[j] == 0:
                c += 2

    return c


if __name__ == "__main__":
    print(solve())


Fixed, accepted submission:
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    A, B, C = il()
    m = max([A, B, C])
    diff = [m - A, m - B, m - C]
    c = 0
    for i, d in enumerate(diff):
        div_2 = d // 2
        if div_2 > 0:
            c += d // 2
            diff[i] -= 2 * div_2
    num_of_1 = diff.count(1)
    if num_of_1 == 1:
        c += 2
    elif num_of_1 == 2:
        c += 1
    return c


if __name__ == "__main__":
    print(solve())
Problem:
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?

Incorrect submission (verdict: Wrong Answer):
#!/usr/bin/env python3
#ABC44 C

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,a = map(int, input().split())
X = list(map(int,input().split()))
Y = list(map(lambda x:x-a, X))
d = defaultdict(int)
d[0] = 1
print(Y)
for y in Y:
    for k,v in list(d.items()):
        d[k+y] += v
print(d[0]-1)


Fixed, accepted submission:
#!/usr/bin/env python3
#ABC44 C

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n,a = map(int, input().split())
X = list(map(int,input().split()))
Y = list(map(lambda x:x-a, X))
d = defaultdict(int)
d[0] = 1
for y in Y:
    for k,v in list(d.items()):
        d[k+y] += v
print(d[0]-1)
Problem:
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i.  At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:    * Choose a (connected) rope with a total length of at least L, then untie one of its knots.  Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.

Incorrect submission (verdict: Wrong Answer):
N, L, *a = map(int, open(0).read().split())
for i, (n, m) in enumerate(zip(a, a[1:])):
    if n + m >= L:
        print('Possible')
        print('\n'.join(c for it in (range(1,i), range(N-1,i,-1), [i]) for c in map(str, it)))
        break
else:
    print('Impossible')

Fixed, accepted submission:
N, L, *a = map(int, open(0).read().split())
for i, (n, m) in enumerate(zip(a, a[1:]), 1):
    if n + m >= L:
        print('Possible')
        print('\n'.join(c for it in (range(1,i), range(N-1,i,-1), [i]) for c in map(str, it)))
        break
else:
    print('Impossible')
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):
N = int(input())
S = []
word_list = ["AC","WA","TLE","RE"]
for i in range(N):                     
    array = input()
    S.append(array)

for i in range(4):
  print(word_list[i] +" × "+str(S.count(word_list[i])))

Fixed, accepted submission:
N = int(input())
S = []
word_list = ["AC","WA","TLE","RE"]
for i in range(N):                     
    array = input()
    S.append(array)

for i in range(4):
  print(word_list[i] +" x "+str(S.count(word_list[i])))
Problem:
You start with the number 0 and you want to reach the number N.  You can change the number, paying a certain amount of coins, with the following operations:    * Multiply the number by 2, paying A coins.   * Multiply the number by 3, paying B coins.   * Multiply the number by 5, paying C coins.   * Increase or decrease the number by 1, paying D coins.  You can perform these operations in arbitrary order and an arbitrary number of times.  What is the minimum number of coins you need to reach N?  **You have to solve T testcases.**

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

testcase = [list(map(int,input().split())) for i in range(T)]

from math import ceil
from functools import lru_cache

@lru_cache(maxsize=None)
def f(n,a,b,c,d):
    if n == 0:
        return 0
    if n == 1:
        return d
    else:
        return min((n-5*(n//5)) * d + c + f(n//5,a,b,c,d),(n-3*(n//3)) * d + b + f(n//3,a,b,c,d),(n-2*(n//2)) * d + a + f(n//2,a,b,c,d),
                   (5*ceil(n/5)-n) * d + c + f(ceil(n/5),a,b,c,d),(3*ceil(n/3)-n) * d + b + f(ceil(n/3),a,b,c,d),(2*ceil(n/2)-n) * d + a + f(ceil(n/2),a,b,c,d),n*d)

for n,a,b,c,d in testcase:
    print(f(n,a,b,c,d))

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

testcase = [list(map(int,input().split())) for i in range(T)]

from functools import lru_cache

@lru_cache(maxsize=None)
def f(n,a,b,c,d):
    if n == 0:
        return 0
    if n == 1:
        return d
    else:
        return min((n-5*(n//5)) * d + c + f(n//5,a,b,c,d),(n-3*(n//3)) * d + b + f(n//3,a,b,c,d),(n-2*(n//2)) * d + a + f(n//2,a,b,c,d),
                   (5*((n+4)//5)-n) * d + c + f((n+4)//5,a,b,c,d),(3*((n+2)//3)-n) * d + b + f((n+2)//3,a,b,c,d),(2*((n+1)//2)-n) * d + a + f((n+1)//2,a,b,c,d),n*d)

for n,a,b,c,d in testcase:
    print(f(n,a,b,c,d))
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):
N=int(input())
M=list(map(int,input().split()))
min(sum([(M[j]-i)**2 for j in range(N)]) for i in range(-100,101))

Fixed, accepted submission:
N=int(input())
M=list(map(int,input().split()))
print(min(sum([(M[j]-i)**2 for j in range(N)]) for i in range(-100,101)))
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):
import sys

E = list(input())

A,B,C,D = map(int, E)

sum = 0
for i in range(2**3):

    op_list = ['-', '-', '-']
    sum1 = 0
    for j in range(len(E)):
        if (i>>j) & 1:
            op_list[j]  = '+'
    sum = eval(E[0]+op_list[0]+E[1]+op_list[1]+E[2]+op_list[2]+E[3])

    if sum==7:
        print(A,op_list[0],B,op_list[1],C,op_list[2],D)
        sys.exit()

Fixed, accepted submission:
import sys

S = list(input())

N = len(S)-1


for i in range(2**N):
    op = ["+"]*N
    for j in range(N):
        if (i>>j)&1:
            op[j] = "-"
    ans = ""
    for j in range(N):
        ans = ans + S[j] + op[j]

    ans = ans + S[j+1]

    if eval(ans)==7:
        print(ans+"=7")
        sys.exit()
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):
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
  ip = input()
  if ip == 'AC':
    ac += 1
  elif ip == 'WA':
    wa += 1
  elif ip == 'TLE':
    tle += 1
  else:
    re += 1
    
print('AC','×',ac)
print('WA','×',wa)
print('TLE','×',tle)
print('RE','×',re)

Fixed, accepted submission:
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Ii()
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
  ip = input()
  if ip == 'AC':
    ac += 1
  elif ip == 'WA':
    wa += 1
  elif ip == 'TLE':
    tle += 1
  else:
    re += 1
    
print('AC','x',ac)
print('WA','x',wa)
print('TLE','x',tle)
print('RE','x',re)
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())
s=input()
list=list(s.split())
for i in range(N):
    list[i]=int(list[i])
print(list)
count=0
while(True):
    for i in range(N):
        list[i]/=2
        if list[i]!=int(list[i]):
            break
    if list[i]!=int(list[i]):
        break
    count+=1
print(count)


Fixed, accepted submission:
N=int(input())
s=input()
list=list(s.split())
for i in range(N):
    list[i]=int(list[i])
count=0
while(True):
    for i in range(N):
        list[i]/=2
        if list[i]!=int(list[i]):
            break
    if list[i]!=int(list[i]):
        break
    count+=1
print(count)
Problem:
Write a program to simulate rolling a dice, which can be constructed by the following net.                  As shown in the figures, each face is identified by a different label from 1 to 6.  Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.

Incorrect submission (verdict: Wrong Answer):
dice = input().split()
direction = list(input())
dice2 = []
for i in range(len(direction)):
    dice2 = dice
    print(dice2)
    if direction[i] == 'E':
        dice = [dice2[3],dice2[1],dice2[0],dice2[5],dice2[4],dice2[2]]
        print(dice)
    elif direction[i] == 'N':
        dice = [dice2[1],dice2[5],dice2[2],dice2[3],dice2[0],dice2[4]]
        print(dice)
    elif direction[i] == 'S':
        dice = [dice2[4],dice2[0],dice2[2],dice2[3],dice2[5],dice2[1]]
        print(dice)
    else:
        dice = [dice2[2],dice2[1],dice2[5],dice2[0],dice2[4],dice2[3]]
        print(dice)
print('{0}'.format(dice[0])) 


Fixed, accepted submission:
dice = input().split()
direction = list(input())
dice2 = []
for i in range(len(direction)):
    dice2 = dice
    if direction[i] == 'E':
        dice = [dice2[3],dice2[1],dice2[0],dice2[5],dice2[4],dice2[2]]
    elif direction[i] == 'N':
        dice = [dice2[1],dice2[5],dice2[2],dice2[3],dice2[0],dice2[4]]
    elif direction[i] == 'S':
        dice = [dice2[4],dice2[0],dice2[2],dice2[3],dice2[5],dice2[1]]
    else:
        dice = [dice2[2],dice2[1],dice2[5],dice2[0],dice2[4],dice2[3]]
print('{0}'.format(int(dice[0])))
Problem:
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M.  For _CODE FESTIVAL 20XX_ held on this planet, N participants gathered from all over the planet.  The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}.  Two participants A and B can _communicate_ with each other if and only if one of the following conditions is satisfied:    * There exists a language that both A and B can speak.   * There exists a participant X that both A and B can communicate with.  Determine whether all N participants can communicate with all other participants.

Incorrect submission (verdict: Wrong Answer):
N,M = map(int,input().split())
KL = [list(map(int,input().split())) for _ in [0]*N]

E = [[] for _ in [0]*(N+M)]
for i,kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N+l-1)
        E[N+l-1].append(i)

start = 0
d = [-1]*(N+M) 
d[start] = 0
q = [start]
while q:
    i = q.pop()
    for j in E[i]:
        if d[j]==-1:continue
        d[j] = d[i]+1
        q.append(j)

ans = True
for b in d[:N]:
    ans = ans and (b>=0)
print("YES" if ans else "NO")

Fixed, accepted submission:

N,M = map(int,input().split())
KL = [list(map(int,input().split())) for _ in [0]*N]

E = [[] for _ in [0]*(N+M)] 
for i,kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N+l-1)
        E[N+l-1].append(i)

def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

d = dist_bfs(N+M,E,0)
ans = d[:N].count(-1)==0
print("YES" if ans else "NO")
Problem:
In this problem, we only consider strings consisting of lowercase English letters.  Strings s and t are said to be **isomorphic** when the following conditions are satisfied:    * |s| = |t| holds.   * For every pair i, j, one of the following holds:     * s_i = s_j and t_i = t_j.     * s_i \neq s_j and t_i \neq t_j.  For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not.  A string s is said to be in **normal form** when the following condition is satisfied:    * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.  For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.  You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.

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

def dfs(s,mx):
    if len(s)==n:
        print(s)
        return None
    for i in range(ord('a'),(mx+1)+1):
        dfs(s+chr(i),max(mx,i))
dfs('',ord('a'))

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

def dfs(s,mx):
    if len(s)==n:
        print(s)
        return None
    for i in range(ord('a'),mx+1+1):
        dfs(s+chr(i),max(mx,i))
dfs('',ord('a')-1)
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 = map(int,input().split())
B,W = map(int,input().split())
T   = int(input())

if V <= W:
    print("No")
elif (abs(A-B)/abs(V-W)) <= T:
    print("Yes")
else:
    print("No")

Fixed, accepted submission:
A,V = map(int,input().split())
B,W = map(int,input().split())
T   = int(input())

if V <= W:
    print("NO")
elif (abs(A-B)/abs(V-W)) <= T:
    print("YES")
else:
    print("NO")
Problem:
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.  He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:    * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.  In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**.    * Buy stock: Pay A_i yen and receive one stock.   * Sell stock: Sell one stock for A_i yen.  What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x = list(map(int, input().split()))
x.append(90)
y = 1000
k =0
for i in range(len(x)-1):
    if x[i] < x[i+1]:
        k += int(y/x[i])
        y -= x[i]*int(y/x[i])
    elif x[i] > x[i+1]:
        y = x[i]*k
        k = 0
print(y)


Fixed, accepted submission:
n = int(input())
x = list(map(int, input().split()))
x.append(90)
y = 1000
k =0
for i in range(len(x)-1):
    if x[i] < x[i+1]:
        k += int(y/x[i])
        y -= x[i]*int(y/x[i])
    elif x[i] > x[i+1]:
        y += x[i]*k
        k = 0
    
print(y)
Problem:
There are N rabbits, numbered 1 through N.  The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.  For a pair of rabbits i and j (i＜j), we call the pair (i，j) a _friendly pair_ if the following condition is met.    * Rabbit i likes rabbit j and rabbit j likes rabbit i.  Calculate the number of the friendly pairs.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
rs = list(map(int, input().split()))
numpair = 0
for i in range(N):
	if (i+1) == rs[rs[i] - 1]:
		numpair+=1
print(numpair/2)

Fixed, accepted submission:
N = int(input())
rs = list(map(int, input().split()))
numpair = 0
for i in range(N):
	if (i+1) == rs[rs[i] - 1]:
		numpair+=1
print(numpair//2)
Problem:
Alice and Brown loves games. Today, they will play the following game.  In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:    * Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.  The player who becomes unable to perform the operation, loses the game.  Given X and Y, determine the winner of the game, assuming that both players play optimally.

Incorrect submission (verdict: Wrong Answer):
x, y = map(int, input().split())
print('Alice' if abs(x-y) else 'Brown')


Fixed, accepted submission:
x, y = map(int, input().split())
print('Brown' if abs(x-y) <= 1 else 'Alice')
Problem:
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.  Finally he found _n_ islands that had treasures and one island that had nothing. Most of islands had seashore and he can land only on an island which had nothing. He walked around the island and found that there was an old bridge between this island and each of all other _n_ islands.  He tries to visit all islands one by one and pick all the treasures up. Since he is afraid to be stolen, he visits with bringing all treasures that he has picked up. He is a strong man and can bring all the treasures at a time, but the old bridges will break if he cross it with taking certain or more amount of treasures.  Please write a program that judges if he can collect all the treasures and can be back to the island where he land on by properly selecting an order of his visit.

Incorrect submission (verdict: Wrong Answer):
while True:
    n = int(input())
    if n == 0:
        break
    z = sorted([tuple(map(int, input().split())) for _ in range(n)],  key=lambda x: x[1])
    cnt = total = 0
    for a, b in z:
        total += a
        if total > b:
            cnt = 1
            break
    print("Yes" if cnt else "No")

Fixed, accepted submission:
while True:
    n = int(input())
    if n == 0:
        break
    z = sorted([tuple(map(int, input().split())) for _ in range(n)],  key=lambda x: x[1])
    total = 0
    for a, b in z:
        total += a
        if total > b:
            print("No")
            break
    else:
        print("Yes")
Problem:
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:    * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.  What is the largest possible sum of the integers written on the blackboard after K operations?

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

testA = 0
if testA < a:
    testA = a
if testA < b:
    testA = b
if testA < c:
    testA = c
  
ans = a + b + c + testA * (K-1)
print(ans)

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

A = 0
if A < a:
    A = a
if A < b:
    A = b
if A < c:
    A = c
  
ans = a + b + c - A + A * 2**K
print(ans)
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):


ans = [0] * 10010
n = int(input())

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            value = x*x + y*y + z*z + x*y + y*z + z*x
            for i in range(1, n+1):
                if value == i:
                    ans[i] += 1

for i in ans[:n]:
    print(i)


Fixed, accepted submission:


ans = [0] * 10010
n = int(input())

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            value = x*x + y*y + z*z + x*y + y*z + z*x
            if value <= n:
                ans[value] += 1

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