TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Incorrect submission (verdict: Wrong Answer):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
hashmap = defaultdict(int)
for a in A:
  hashmap[a]+=1
ans = 0
for k, v in hashmap.items():
  ans+=min(v,k-v)
print(ans)


Fixed, accepted submission:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
hashmap = defaultdict(int)
for a in A:
  hashmap[a]+=1
ans = 0
for k, v in hashmap.items():
  if k < v:
    ans+=v-k
  elif k > v:
    ans+=v
print(ans)
Problem:
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Incorrect submission (verdict: Wrong Answer):
def bubbleSort(A, N):
    flag = True
    count = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(A)
    print(count)


arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]

bubbleSort(arr_num, arr_length)

Fixed, accepted submission:
def bubbleSort(A, N):
    flag = True
    count = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(*A)
    print(count)


arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]

bubbleSort(arr_num, arr_length)
Problem:
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.  The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.  One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.  If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.    * X < Z \leq Y   * x_1, x_2, ..., x_N < Z   * y_1, y_2, ..., y_M \geq Z  Determine if war will break out.

Incorrect submission (verdict: Wrong Answer):
N, M, X, Y = map(int, input().split())
list_x = [int(i) for i in input().split()]
list_y = [int(j) for j in input().split()]
if X >= Y:
    print("War")
else:
    if max(list_x) +1 >= min(list_y):
        print("War")
    else:
        print("No War")


Fixed, accepted submission:
N, M, X, Y = map(int, input().split())
list_x = [int(i) for i in input().split()]
list_y = [int(j) for j in input().split()]
if max(list_x) >= min(list_y):
    print('War')
else:
    if X < max(list_x) + 1 <= Y:
        print('No War')
    else:
        print('War')
Problem:
Rng is preparing a problem set for a qualification round of CODEFESTIVAL.  He has N candidates of problems. The difficulty of the i-th candidate is D_i.  There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems.  Determine whether Rng can complete the problem set without creating new candidates of problems.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

dic = {}
for d in D:
    if d in dic.keys():
        dic[d] += 1
    else:
        dic[d] = 1

for t in T:
    if t in dic.keys():
        if dic[t] == 0:
            print('No')
            exit()
        dic[t] -= 1
    else:
        print('No')
        exit()

print('Yes')


Fixed, accepted submission:
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

dic = {}
for d in D:
    if d in dic.keys():
        dic[d] += 1
    else:
        dic[d] = 1

for t in T:
    if t in dic.keys():
        if dic[t] == 0:
            print('NO')
            exit()
        dic[t] -= 1
    else:
        print('NO')
        exit()

print('YES')
Problem:
N persons are standing in a row. The height of the i-th person from the front is A_i.  We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:  Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.  Find the minimum total height of the stools needed to meet this goal.

Incorrect submission (verdict: Wrong Answer):
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    top = a[0]
    ans = 0

    for height in a:
        if top < height:
            ans += height - top
            top = height

    print(ans)


main()


Fixed, accepted submission:
def main():
    n = int(input())
    a = list(map(int, input().split(" ")))
    top = a[0]
    ans = 0

    for i in range(n):
        if a[i] < top:
            ans += top - a[i]
        else:
            top = a[i]

    print(ans)


main()
Problem:
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Incorrect submission (verdict: Wrong Answer):
N = int(input())
if N % 2 == 1:
  print((N-1) / 2)
else: print(N/2 - 1)

Fixed, accepted submission:
N = int(input())
print((N-1) // 2)
Problem:
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:    * You should select three distinct integers from 1 to n.   * A total sum of the three integers is x.  For example, there are two combinations for n = 5 and x = 9.    * 1 + 3 + 5 = 9   * 2 + 3 + 4 = 9

Incorrect submission (verdict: Wrong Answer):
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    for a in range(1, n + 1):
        for b in range(2, n + 1):
            for c in range(3, n + 1):
                count = 0
                if (a + b + c) == x:
                    count += 1
    print(count)

Fixed, accepted submission:
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)
Problem:
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.

Incorrect submission (verdict: Wrong Answer):
# AOJ 0005 GCD and LCM
# Python3 2018.6.9 bal4u

def lcm(a, b):
	return a/gcd(a, b)*b

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

while True:
    try:
        a = list(map(int, input().split()))
        print(gcd(a[0], a[1]), lcm(a[0], a[1]))
    except EOFError:
        break


Fixed, accepted submission:
# AOJ 0005 GCD and LCM
# Python3 2018.6.9 bal4u

def lcm(a, b):
	return a // gcd(a, b) * b

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

while True:
    try:
        a = list(map(int, input().split()))
        print(gcd(a[0], a[1]), lcm(a[0], a[1]))
    except EOFError:
        break
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 sys
sys.setrecursionlimit(10 ** 6)


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


def main():
    N = int(input())
    a = [-1]+list(map(int, input().split()))
    b = [0] * (N+1)
    for i in reversed(range(1,N+1)):
        total = 0
        for j in range(i,N+1):
            if i%j==0:
                total += b[j]
        if a[i] != (total%2):
            b[i] = 1
    print(*b[1:])

if __name__ == "__main__":
    main()


Fixed, accepted submission:
import sys
sys.setrecursionlimit(10 ** 6)


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


def main():
    N = int(input())
    a = [-1]+list(map(int, input().split()))
    b = [0] * (N+1)
    for i in reversed(range(1,N+1)):
        total = 0
        for j in range(i,N+1,i):
            total += b[j]
        if a[i] != (total%2):
            b[i] = 1
    ans = []
    cnt = 0
    for i, n in enumerate(b):
        if n!=0:
            ans.append(i)
            cnt += 1
    print(cnt)
    print(*ans)

if __name__ == "__main__":
    main()
Problem:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`.  After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.

Incorrect submission (verdict: Wrong Answer):
s = input()
s.replace('8/', '9/')
print(s)

Fixed, accepted submission:
S=str(input())
print(S.replace('7/','8/'))
Problem:
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.  If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]

pre_t, pre_x, pre_y = 0, 0, 0
for t, x, y in TXY:
  diff_t = t - pre_t
  diff_pos = abs(x-pre_x) + abs(y-pre_y)
  if diff_t > diff_pos or diff_pos-diff_t % 2 == 1:
    print('No')
    exit()
  else:
    pre_t, pre_x, pre_y = t, x, y
print('Yes')

Fixed, accepted submission:
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]
 
pre_t, pre_x, pre_y = 0, 0, 0
for t, x, y in TXY:
  diff_t = t - pre_t
  diff_pos = abs(x-pre_x) + abs(y-pre_y)
  if diff_t < diff_pos or (diff_t-diff_pos) % 2 == 1:
    print('No')
    exit()
  else:
    pre_t, pre_x, pre_y = t, x, y
print('Yes')
Problem:
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:    * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.

Incorrect submission (verdict: Wrong Answer):
s = input()
judge = "YES"

s = s.replace("eraser", "0")
s = s.replace("erase", "0")
s = s.replace("dreamer", "0")
s = s.replace("dream", "0")

if not s.isdigit():
  judge = "NO"
print(s)
print(judge)

Fixed, accepted submission:
s = input()
judge = "YES"

s = s.replace("eraser", "0")
s = s.replace("erase", "0")
s = s.replace("dreamer", "0")
s = s.replace("dream", "0")

if not s.isdigit():
  judge = "NO"
print(judge)
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 = [input() for i in range(n)]
print('AC x' + str((s.count('AC'))))
print('WA x' + str((s.count('WA'))))
print('TLE x' + str((s.count('TLE'))))
print('RE x' + str((s.count('RE'))))


Fixed, accepted submission:
n = int(input())
s = [input() for i in range(n)]
ans = ['AC', 'WA', 'TLE', 'RE']
for i in ans:
    print(i, 'x', s.count(i))
Problem:
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.

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

s1 = a[0]
s2 = b[0]
s3 = c[0]

print(s1+s2+s3)


Fixed, accepted submission:
N = input().upper()
N = N.split()

print("{}{}{}".format(N[0][0],N[1][0],N[2][0]))
Problem:
We have N cards. A number a_i is written on the i-th card.   Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.   The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Incorrect submission (verdict: Wrong Answer):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    sw = 0
    alice = 0
    bob = 0
    for i in a:
        if sw == 0:
            alice += i
            sw = 1
        else:
            bob += i
            sw = 0
    print(alice-bob)

if __name__ == '__main__':
    main()


Fixed, accepted submission:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    sw = 0
    alice = 0
    bob = 0
    for i in a:
        if sw == 0:
            alice += i
            sw = 1
        else:
            bob += i
            sw = 0
    print(alice-bob)

if __name__ == '__main__':
    main()
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())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    tmp = input()
    if tmp == "AC":
        ac += 1
    elif tmp == "WA":
        wa += 1
    elif tmp == "tle":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Fixed, accepted submission:
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    tmp = input()
    if tmp == "AC":
        ac += 1
    elif tmp == "WA":
        wa += 1
    elif tmp == "TLE":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))
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):
x,y,z=map(int,input().split())
t1=0
t2=0
for i in range(1,x):
  if i%z==0:
    t1+=1
for i in range(1,y):
  if i%z==0:
    t2+=1
    
print(t2-t1)
  

Fixed, accepted submission:
a,s,d=map(int,input().split())
if a%d==0:
  print(s//d-a//d+1)
else:
  print(s//d-a//d)
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):
num = int(input())

count = {"AC":0,"WA":0,"TLE":0,"RE":0}

for _ in range(num):
    s = input()
    count[s] += 1

print("AC x {}".format(count["AC"]))
print("WA x {}".format(count["WA"]))
print("TLE x {}".format(count["TLE"]))
print("RE {}".format(count["RE"]))


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

count = {"AC":0,"WA":0,"TLE":0,"RE":0}

for _ in range(num):
    s = input()
    count[s] += 1

print("AC x {}".format(count["AC"]))
print("WA x {}".format(count["WA"]))
print("TLE x {}".format(count["TLE"]))
print("RE x {}".format(count["RE"]))
Problem:
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?  Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Incorrect submission (verdict: Wrong Answer):
a = int(input())
b = int(input())
c = int(input())
x = int(input())

pattern = 0
for i in range(c+1):
  for j in range(b+1):
    for k in range(a+1):
      if 500*a - 100*b - 50*c == x:
        pattern += 1

print(pattern)

Fixed, accepted submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())

pattern = 0
for i in range(c+1):
  for j in range(b+1):
    for k in range(a+1):
      if 500*k + 100*j + 50*i == x:
        pattern += 1

print(pattern)
Problem:
Write a program which reads a sequence and prints it in the reverse order.

Incorrect submission (verdict: Wrong Answer):
a = list(map(int, input().split()))
a.sort(reverse=True)
print(" ".join(map(str, a)))

Fixed, accepted submission:
_ = input()
a = list(map(int, input().split()))
a = list(a[i] for i in range(len(a)-1,-1,-1))
print(" ".join(map(str, a)))
Problem:
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).   Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares.   Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game.   When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares.  The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.

Incorrect submission (verdict: Wrong Answer):
from collections import deque
from itertools import chain
H, W = map(int, input().split(' '))
Maze = [list(input()) for _ in range(H)]
White = list(chain.from_iterable(Maze)).count('.')
Maze[0][0] = 1
q = deque([])
current = [0, 0]
q.append(current)

dir_x = [1, -1, 0, 0]
dir_y = [0, 0, 1, -1]
while len(q) > 0:
    now_y, now_x = q.popleft()
    print(now_y, now_x)
    if now_y == H-1 and now_x == W-1 : break
    for (dx, dy) in zip(dir_x, dir_y):
        if 0 <= now_y + dy <= H-1 and 0 <= now_x + dx <= W-1 and Maze[now_y + dy][now_x + dx] == '.':
            Maze[now_y + dy][now_x + dx] = Maze[now_y][now_x] + 1
            q.append([now_y + dy, now_x + dx])


if Maze[H-1][W-1] == '.': print(-1)
else: print(White - Maze[H-1][W-1])

Fixed, accepted submission:
from collections import deque
from itertools import chain
H, W = map(int, input().split(' '))
Maze = [list(input()) for _ in range(H)]
White = list(chain.from_iterable(Maze)).count('.')
Maze[0][0] = 1
q = deque([])
current = [0, 0]
q.append(current)

dir_x = [1, -1, 0, 0]
dir_y = [0, 0, 1, -1]
while len(q) > 0:
    now_y, now_x = q.popleft()
    if now_y == H-1 and now_x == W-1 : break
    for (dx, dy) in zip(dir_x, dir_y):
        if 0 <= now_y + dy <= H-1 and 0 <= now_x + dx <= W-1 and Maze[now_y + dy][now_x + dx] == '.':
            Maze[now_y + dy][now_x + dx] = Maze[now_y][now_x] + 1
            q.append([now_y + dy, now_x + dx])


if Maze[H-1][W-1] == '.': print(-1)
else: print(White - Maze[H-1][W-1])
Problem:
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.   For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.  In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi.   How many days from 2018-1-1 through 2018-a-b are Takahashi?

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

ans = a - 1
if b > a:
    print(ans+1)
else:
    print(ans)



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

if b >= a:
    print(a)
else:
    print(a-1)
Problem:
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.  Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).

Incorrect submission (verdict: Wrong Answer):
h,w = map(int,input().split())
l = list(map(str,input().split()))
for i in range(len(l)):
  print(l[i])
  print(l[i])

Fixed, accepted submission:
h, w = list(map(int, input().split()))
c = [input() for i in range(h)]

for i in range(h*2):
  print(c[i // 2])