TnT/CodeNet4Repair huggingface dataset:
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):
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    op=["-"]*op_cnt
    for j in range(op_cnt):
        if ((i >> j)&1):
            op[j]="+"

    formula=""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
        print(formula)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Fixed, accepted submission:
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    op=["-"]*op_cnt
    for j in range(op_cnt):
        if ((i >> j)&1):
            op[j]="+"

    formula=""
    for p_n, p_o in zip(n, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break
Problem:
Write a program which computes the digit number of sum of two integers a and b.

Incorrect submission (verdict: Wrong Answer):
import sys

for line in sys.stdin:
    a, b = map(str, line.split())
    print(len(a+b))

Fixed, accepted submission:
import sys

for line in sys.stdin:
    a, b = map(int, line.split())
    print(len(str(a+b)))
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())
sum = 0
for i in range(n):
    sum += i
print(sum)    


Fixed, accepted submission:
n = int(input())
sum = 0
for i in range(n+1):
    sum += i
print(sum)
Problem:
There are N people numbered 1 to N. Each person wears a red hat or a blue hat.  You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`.  Determine if there are more people wearing a red hat than people wearing a blue hat.

Incorrect submission (verdict: Wrong Answer):
# coding: utf-8
N = int(input())
s = list(input())
red = 0
blue = 0

for i in range(N):
    print(i)
    if s[i] == 'R':
        red += 1
    elif s[i] == 'B':
        blue += 1

if red > blue:
    print('Yes')
else:
    print('No')

Fixed, accepted submission:
# coding: utf-8
N = int(input())
s = list(input())
red = 0
blue = 0

for i in range(N):
    if s[i] == 'R':
        red += 1
    elif s[i] == 'B':
        blue += 1

if red > blue:
    print('Yes')
else:
    print('No')
Problem:
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.

Incorrect submission (verdict: Wrong Answer):
import sys
import string

count = {k : 0 for k in string.ascii_lowercase}
print(count)
for c in sys.stdin.read().lower():
    if c.islower():
        count[c] = count[c] + 1
for k, v in count.items():
    print(f"{k} : {v}")


Fixed, accepted submission:
import sys
import string

count = {k : 0 for k in string.ascii_lowercase}
for c in list(sys.stdin.read().lower()):
    if c.islower():
        count[c] = count[c] + 1
for k, v in count.items():
    print(f"{k} : {v}")
Problem:
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.  Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.  Given the name of the contest, print the abbreviation of the name.

Incorrect submission (verdict: Wrong Answer):
s = input()
print('A'+s[0]+'C')


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

print(a[0],b[0],c[0],sep='')
Problem:
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.  Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.  Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)  At most how much can he earn on balance?  Note that the same string may be written on multiple cards.

Incorrect submission (verdict: Wrong Answer):
I=lambda:[input()for _ in[0]*int(input())];s=I();t=I();c=0
for i in set(t):a=t.count(i)-s.count(i);c+=a*(a>0)
print(c)

Fixed, accepted submission:
n,*s=open(0);print(max(0,*[s.count(i)-s[int(n):].count(i)*2for i in s]))
Problem:
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.

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

t =0

for i in range(10**5):
	t += 1
	if x< (i*(i+1)//2):
		break
print(t)


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

t =0

for i in range(10**5):
	t += 1
	if x< (i*(i+1)//2)+1:
		break
print(t-1)
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):
import numpy as np

Z = list(map(int,input().split()))

Z = np.sort(Z)[::-1]
#print(Z)
count = 0
if Z[0]==1 or Z[0]==0:
    print ('Brown')
else:
    while Z[0] != 1:
        Z[1] += int(Z[0]/2)
        Z[0] -= int(Z[0]/2)*2
        Z = np.sort(Z)[::-1]
        count += 1
        print (Z)
    if (count%2) == 1:
        print ('Alice')
    else: print ('Brown')

Fixed, accepted submission:
import numpy as np

X,Y = list(map(int,input().split()))


if np.abs(X-Y)<=1:
    print('Brown')
else:
    print('Alice')
Problem:
JOI 君は食事の準備のため，A ℃の肉を電子レンジで B ℃まで温めようとしている． 肉は温度が 0 ℃未満のとき凍っている． また，温度が 0 ℃より高いとき凍っていない． 温度がちょうど 0 ℃のときの肉の状態は，凍っている場合と，凍っていない場合の両方があり得る．  JOI 君は，肉の加熱にかかる時間は以下のようになると仮定して，肉を温めるのにかかる時間を見積もることにした．    * 肉が凍っていて，その温度が 0 ℃より小さいとき： C 秒で 1 ℃温まる．    * 肉が凍っていて，その温度がちょうど 0 ℃のとき： D 秒で肉が解凍され，凍っていない状態になる．    * 肉が凍っていないとき： E 秒で 1 ℃温まる．   この見積もりにおいて，肉を B ℃にするのに何秒かかるかを求めよ．

Incorrect submission (verdict: Wrong Answer):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

t = 0

if A < 0:
    t += C * abs(A) + D

t += E * (B - A)

print(t)


Fixed, accepted submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

t = 0

if A < 0:
    t += C * abs(A) + D

t += E * (B - max(0, A))

print(t)
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

h, w = map(int, input().split())
maze = [list(input()) for a in range(h)]
visited = [[0]*w for a in range(h)]

dy = [0,1,0,-1]
dx = [1,0,-1,0]
def bfs():
    que = deque([])
    que.append((0,0))
    visited[0][0]=0

    while que:
        p = que.popleft()

        if p[0]==h-1 and p[1]==w-1:
            break

        for i in range(4):
            ny = p[0]+dy[i]
            nx = p[1]+dx[i]

            if 0<=ny<h and 0 <=nx<w and maze[ny][nx]=='.' and visited[ny][nx]==0:
                visited[ny][nx]=visited[p[0]][p[1]]+1
                que.append((ny,nx))

    return visited[h-1][w-1]

ans = bfs()
if ans == 0:
    print(-1)
else:
    cnt = 0
    for i in range(h):
        for j in range(w):
            if maze[i][j]=='#':
                cnt +=1

    print(h*w-cnt-ans+1)            


Fixed, accepted submission:
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for a in range(h)]
visited = [[0]*w for a in range(h)]

dy = [0,1,0,-1]
dx = [1,0,-1,0]
def bfs():
    que = deque([])
    que.append((0,0))
    visited[0][0]=0

    while que:
        p = que.popleft()

        if p[0]==h-1 and p[1]==w-1:
            break

        for i in range(4):
            ny = p[0]+dy[i]
            nx = p[1]+dx[i]

            if 0<=ny<h and 0 <=nx<w and maze[ny][nx]=='.' and visited[ny][nx]==0:
                visited[ny][nx]=visited[p[0]][p[1]]+1
                que.append((ny,nx))

    return visited[h-1][w-1]

ans = bfs()
if ans == 0:
    print(-1)
else:
    cnt = 0
    for i in range(h):
        for j in range(w):
            if maze[i][j]=='#':
                cnt +=1

    print(h*w-cnt-ans-1)
Problem:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.  The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it.  Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.  Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
buttons = []
for _ in range(n):
    buttons.append(int(input()))

light = buttons[0]
for i in range(n):
    print(buttons[light-1])
    if light == 2:
        print(i+1)
        break
    light = buttons[light-1]
else:
    print(-1)


Fixed, accepted submission:
n = int(input())
buttons = [0 for _ in range(n)]
for i in range(n):
    buttons[i] = int(input())

light = buttons[0]
for i in range(n):
    if light == 2:
        print(i+1)
        break
    light = buttons[light-1]
else:
    print(-1)
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
import math

a, b = input().split()
result_sqrt = math.sqrt(int(a+b))
if result_sqrt**2 == int(a+b):
  print('yes')
else:
  print('no')


Fixed, accepted submission:
import math

a, b = input().split()

if math.sqrt(int(a+b)).is_integer():
  print("Yes")
else:
  print("No")
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):
# -*- coding: utf-8 -*-

def solve(S):
    S.replace("eraser", "").replace("erase", "").replace("dream", "").replace("dreamer", "")
    if(S==""):
        print("YES")
    else:
        print("NO")
    
if __name__ == '__main__':
    S = input()
  
    solve(S)

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

def solve(S):
    s = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

    if(s==""):
        print("YES")
    else:
        print("NO")
    
if __name__ == '__main__':
    S = input()
  
    solve(S)
Problem:
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.  Find the number of chocolate pieces prepared at the beginning of the camp.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]
answer = X
for a in A:
    print(D // a + 1)
    answer +=  (D - 1) // a + 1
print(answer)


Fixed, accepted submission:
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]
answer = X
for a in A:
    answer +=  (D - 1) // a + 1
print(answer)
Problem:
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.  Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.

Incorrect submission (verdict: Wrong Answer):
i=1
for x in [int(x) for x in input().split()]:
    if x != 0:
        print('Case {0}: {1}'.format(i,x))
        i += 1


Fixed, accepted submission:
i=1
while True:
    x = int(input().strip())
    if x==0:
        break
    else:
        print('Case {0}: {1}'.format(i,x))
        i += 1
Problem:
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements?  Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:    * r_1 + c_1 = r_2 + c_2   * r_1 - c_1 = r_2 - c_2  For example, in the following figure, the bishop can move to any of the red squares in one move:  

Incorrect submission (verdict: Wrong Answer):
h, w=map(int,input().split())
if w % 2 == 0:
    print(int(h * w / 2))
else:
    print(int(h * w / 2) + int(w /2))
    

Fixed, accepted submission:
h, w=map(int,input().split())
if (w == 1) | (h == 1):
    print(1)
elif h % 2 == 0:
    print(int(h * w / 2))
elif h % 2 == 1 & w % 2 == 1:
    print(int((h - 1) * w / 2) + int(w / 2) + 1)
else:
    print(int((h - 1) * w / 2) + int(w / 2))
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 random
import sys

str = input()
print(str)


def retop():
    if(random.uniform(0, 1) > 0.5):
        return "+"
    return "-"


for i in range(100):
    formula = (str[0] + retop() + str[1] + retop() + str[2] + retop() + str[3])
    if eval(formula) == 7:
        print(formula)
        sys.exit()


Fixed, accepted submission:

import random
import sys

str = input()


def retop():
    if(random.uniform(0, 1) > 0.5):
        return "+"
    return "-"


for i in range(100):
    formula = (str[0] + retop() + str[1] + retop() + str[2] + retop() + str[3])
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()
Problem:
Two students of AtCoder Kindergarten are fighting over candy packs.  There are three candy packs, each of which contains a, b, and c candies, respectively.  Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.  Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Incorrect submission (verdict: Wrong Answer):


l = list(map(int, input().split()))
l.sort()
if l[0] + l[1] == l[2]:
    print("YES")
else:
    print("NO")


Fixed, accepted submission:


l = list(map(int, input().split()))
l.sort()
if l[0] + l[1] == l[2]:
    print("Yes")
else:
    print("No")
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())
A = map(int, input().split())
count = 0
for a in A:
    if a%2==0:
        count+=1
    else:
        print(count)
        break

Fixed, accepted submission:
def calc(n):
    ans = 0
    while n%2 == 0:
        ans+=1
        n/=2
    return ans

N = int(input())
A = map(int,input().split())

ans = min(map(calc, A))

print(ans)
Problem:
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.  Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.

Incorrect submission (verdict: Wrong Answer):
import re

def solve(S):
    patterns = ['^.*keyence$', '^k.*eyence$', '^ke.*yence$', '^key.*ence$',
                '^keye.*nce$', '^keyen.*ce$', '^keyenc.*e$', '^keyence.*$']
    for p in patterns:
        if re.match(p, S):
            return 'YES'
    return 'NO'

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

import sys


def solve(S):
    l = len('keyence')
    diff = len(S) - l
    if diff < 0:
        return 'NO'
    for i in range(len(S)):
        t = S[:i] + S[i+diff:]
        if t == 'keyence':
            return 'YES'
    return 'NO'


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Problem:
We are playing a puzzle. An upright board with _H_ rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a digit, one of 1 through 9, is placed in each of the cells. When three or more stones in horizontally adjacent cells are engraved with the same digit, the stones will disappear. If there are stones in the cells above the cell with a disappeared stone, the stones in the above cells will drop down, filling the vacancy.         The puzzle proceeds taking the following steps.    1. When three or more stones in horizontally adjacent cells are engraved with the same digit, the stones will disappear. Disappearances of all such groups of stones take place simultaneously.   2. When stones are in the cells above the emptied cells, these stones drop down so that the emptied cells are filled.    3. After the completion of all stone drops, if one or more groups of stones satisfy the disappearance condition, repeat by returning to the step 1.  The score of this puzzle is the sum of the digits on the disappeared stones.  Write a program that calculates the score of given configurations of stones.     

Incorrect submission (verdict: Wrong Answer):
from itertools import zip_longest

while True:
    n = int(input())
    if not n:
        break
    field = [list(map(int, input().split())) for _ in range(n)]
    field.reverse()
    score = 0
    while True:
        no_more_disappear = True

        for y, row in enumerate(field):
            for i, stone in enumerate(row):
                if stone is None:
                    continue
                cnt = 1
                for stone2 in row[i + 1:]:
                    if stone != stone2:
                        break
                    cnt += 1
                if cnt >= 3:
                    row[i:i + cnt] = [None] * cnt
                    score += stone * cnt
                    no_more_disappear = False

        if no_more_disappear:
            break

        fieldT = map(lambda row: filter(None, row), zip(*field))
        field = map(list, zip_longest(*fieldT))

    print(score)

Fixed, accepted submission:
from itertools import zip_longest

while True:
    n = int(input())
    if not n:
        break
    field = [list(map(int, input().split())) for _ in range(n)]
    field.reverse()
    score = 0
    while True:
        no_more_disappear = True

        for row in field:
            for i, stone in enumerate(row[:3]):
                if stone is None:
                    continue
                cnt = 1
                for stone2 in row[i + 1:]:
                    if stone != stone2:
                        break
                    cnt += 1
                if cnt >= 3:
                    row[i:i + cnt] = [None] * cnt
                    score += stone * cnt
                    no_more_disappear = False

        if no_more_disappear:
            break

        fieldT = map(lambda row: filter(None, row), zip(*field))
        field = list(map(list, zip_longest(*fieldT)))

    print(score)
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):
n=int(input())
a=list(map(int,input().split()))

ans=0

for i in range(1,n):
  diff=a[i]-a[i-1]
  if diff<0:
    ans+=-diff
    a[i]=a[i]-diff
    print(diff)

print(ans)

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

ans=0

for i in range(1,n):
  diff=a[i]-a[i-1]
  if diff<0:
    ans+=-diff
    a[i]=a[i]-diff

print(ans)