TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given an H × W grid.   The squares in the grid are described by H strings, S_1,...,S_H.   The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).   `.` stands for an empty square, and `#` stands for a square containing a bomb.  Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.   (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)   He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  Print the strings after the process.

Incorrect submission (verdict: Wrong Answer):
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))


for h in range(H):
    for w in range(W):
        cnt = 0
        if S[h][w]==".":
            if w > 0:
                cnt += int(S[h][w-1] == "#")
            if w < W-1:
                cnt += int(S[h][w+1] == "#")
                
            if h > 0:
                cnt += int(S[h-1][w] == "#")
                if w > 0:
                    cnt += int(S[h-1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h-1][w+1] == "#")
                    
            if h < H-1:
                cnt += int(S[h+1][w] == "#")
                if w > 0:
                    cnt += int(S[h+1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h+1][w+1] == "#")
            
            S[h][w] = cnt

print(S)
            
               

Fixed, accepted submission:
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))


for h in range(H):
    for w in range(W):
        cnt = 0
        if S[h][w]==".":
            if w > 0:
                cnt += int(S[h][w-1] == "#")
            if w < W-1:
                cnt += int(S[h][w+1] == "#")
                
            if h > 0:
                cnt += int(S[h-1][w] == "#")
                if w > 0:
                    cnt += int(S[h-1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h-1][w+1] == "#")
                    
            if h < H-1:
                cnt += int(S[h+1][w] == "#")
                if w > 0:
                    cnt += int(S[h+1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h+1][w+1] == "#")
            
            S[h][w] = str(cnt)

for s in S:
    print("".join(s))
Problem:
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.  You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.

Incorrect submission (verdict: Wrong Answer):
# input
O = input()
E = input()

password = [0 for _ in range(len(O) + len(E))]

for i in range(len(O)):
    password[2 * i] = O[i]

for i in range(len(E)):
    password[2 * i + 1] = E[i]

password_str = str(password)

print(password_str)

Fixed, accepted submission:
# input
O = input()
E = input()

password = [0 for _ in range(len(O) + len(E))]

for i in range(len(O)):
    password[2 * i] = O[i]

for i in range(len(E)):
    password[2 * i + 1] = E[i]

password_str = ''.join(password)
print(password_str)
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())
wid = 0
if w % 2 == 0:
    wid = w // 2
else:
    wid = w // 2 + 1
if h % 2 == 0:
    print(h*wid)
else:
    print(h*wid - h//2*(wid-1))


Fixed, accepted submission:
h, w =  map(int,input().split())
if h == 1 or w == 1:
    print(1)
    exit()
else:
    print((h * w + 1) // 2)
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((N * (N + 1)) / 2)

Fixed, accepted submission:
N = int(input())
print((N * (N + 1)) // 2)
Problem:
Takahashi loves numbers divisible by 2.  You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.  Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.  For example,    * 6 can be divided by 2 once: 6 -> 3.   * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.   * 3 can be divided by 2 zero times.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
count = 0

if N == 1:
    print(1)

elif N == 2 or N == 3:
    print(2)

else:
    even = [i for i in range(2, N+1, 2)]

    while len(even) >1:
        i = 0
        count +=1
        while i < len(even):
            if even[i]%2 == 0:
                even[i] = even[i]/2
                i +=1
            else:
                del even[i-1]
                i +=1
    print(2**count)


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

if N == 1:
    print(1)

elif N == 2 or N == 3:
    print(2)

elif N < 8:
    print(4)

elif N < 16:
    print(8)

elif N < 32:
    print(16)

elif N < 64:
    print(32)

else:
    print(64)
Problem:
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_.   Here, a correct bracket sequence is defined as follows:    * `()` is a correct bracket sequence.   * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence.   * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.   * Every correct bracket sequence can be derived from the rules above.  Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
S = input()
cnt = [0, 0]
ans = ""
for i in range(N):
  if S[i] == ")":
    cnt[0] += 1
  else:
    cnt[1] += 1
print("(" * cnt[0] + S + ")" * cnt[1])

Fixed, accepted submission:
N = int(input())
S = input()
s = S[:]
while "()" in s:
  s = s.replace("()", "")
r = s.count("(")
l = s.count(")")
print("(" * l + S + ")" * r)
Problem:
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer.  Snuke's objective is to permute the element in a so that the following condition is satisfied:    * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.  Determine whether Snuke can achieve his objective.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
count = [0] * 3
for i in range(n):
    if a[i] % 4 == 0:
        count[2] += 1
    elif a[i] % 2 == 0:
        count[1] += 1
    else:
        count[0] += 1

ans = False

if count[0] + (count[1] % 2) <= count[2] + 1:
    ans = True

if ans:
    print("YES")
else:
    print("NO")


Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))
count = [0] * 3
for i in range(n):
    if a[i] % 4 == 0:
        count[2] += 1
    elif a[i] % 2 == 0:
        count[1] += 1
    else:
        count[0] += 1

ans = False

if count[0] + (count[1] % 2) <= count[2] + 1:
    ans = True

if ans:
    print("Yes")
else:
    print("No")
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())
p = a*b % 2
if p == 1 :
    print("Even")
else:
    print("Odd")

Fixed, accepted submission:
a,b = map(int,input().split())
ans = a*b
if ans % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

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

print(N%1000)

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

amari = N%1000

if amari == 0:
    print(0)
else:
    print(1000-amari)
Problem:
AtCoDeer has three cards, one red, one green and one blue.   An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.   We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.   Is this integer a multiple of 4?

Incorrect submission (verdict: Wrong Answer):
rgb = list(map(str,input().split()))
print('Yes' if int(''.join(rgb)) % 4 == 0 else 'NO')

Fixed, accepted submission:
rgb = list(map(str,input().split()))
print('YES' if int(''.join(rgb)) % 4 == 0 else 'NO')
Problem:
Write a program which reads two integers a and b, and calculates the following values:    * a ÷ b: d (in integer)   * remainder of a ÷ b: r (in integer)   * a ÷ b: f (in real number)

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

d = a // b
r = a % b
f = a / b
print(d,r,f,sep=' ')


Fixed, accepted submission:
a,b = map(int,input().split(" "))
d = a // b
r = a % b
f = a / b
print(d,r,"{:.5f}".format(f))
Problem:
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1.  Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode:                 BubbleSort(C) 1 for i = 0 to C.length-1 2     for j = C.length-1 downto i+1 3         if C[j].value < C[j-1].value 4             swap C[j] and C[j-1]                 SelectionSort(C) 1 for i = 0 to C.length-1 2     mini = i 3     for j = i to C.length-1 4         if C[j].value < C[mini].value 5             mini = j 6     swap C[i] and C[mini]   Note that, indices for array elements are based on 0-origin.  For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

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

d = c[:]


for i in range(n):
    for j in range(n - 1, i, -1):
        if d[j] < d[j - 1]:
            d[j], d[j - 1] = d[j - 1], d[j]
print(*d)
print("Stable")

# selectionsort
for i in range(n):
    minj = i
    for j in range(i, n):
        if c[j] < c[minj]:
            minj = j
    c[i], c[minj] = c[minj], c[i]

print(*c)
print("Stable" if c == d else "Not stable")

Fixed, accepted submission:
n = int(input())
c = input().split()
d = c[:]


for i in range(n):
    for j in range(n - 1, i, -1):
        if d[j][1] < d[j - 1][1]:
            d[j], d[j - 1] = d[j - 1], d[j]
print(*d)
print("Stable")

# selectionsort
for i in range(n):
    minj = i
    for j in range(i, n):
        if c[j][1] < c[minj][1]:
            minj = j
    c[i], c[minj] = c[minj], c[i]

print(*c)
print("Stable" if c == d else "Not stable")
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):
def find(x, parent):
    if parent[x] == x:
        return x
    else:
        
        parent[x] = find(parent[x], parent)
        return parent[x]


def unite(x, y, parent):
    x = find(x, parent)
    y = find(y, parent)
    if x == y: return

    parent[y] = x

def solve():
    N, K, L = map(int, input().split())
    
    street = [i for i in range(N+1)]
    train = [i for i in range(N+1)]

    for _ in range(K):
        a, b = map(int, input().split())
        unite(0, a, street)
        unite(0, b, street)

    for _ in range(L):
        a, b = map(int, input().split())
        unite(0, a, train)
        unite(0, b, train)

    ans = []
    for i in range(1, N+1):
        c = 0
        if street[i] == 0:
            c += 1
        if train[i] == 0:
            c += 1
        ans.append(str(c))

    print(' '.join(ans))

print(solve())

Fixed, accepted submission:
from collections import defaultdict

def find(x, parent):
    if parent[x] == x:
        return x
    else:
        
        parent[x] = find(parent[x], parent)
        return parent[x]


def unite(x, y, parent):
    x = find(x, parent)
    y = find(y, parent)
    if x == y: return

    parent[y] = x

def solve():
    N, K, L = map(int, input().split())
    
    street = [i for i in range(N)]
    train = [i for i in range(N)]

    for _ in range(K):
        a, b = map(int, input().split())
        unite(a-1, b-1, street)

    for _ in range(L):
        a, b = map(int, input().split())
        unite(a-1, b-1, train)

    d = defaultdict(int)
    for i in range(N):
        a = find(street[i], street)
        b = find(train[i], train)
        d[(a, b)] += 1

    ans = []
    for i in range(N):
        a = find(street[i], street)
        b = find(train[i], train)
        ans.append(str(d[(a, b)]))

    print(' '.join(ans))

solve()
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()
print('YES' if (int(a+b))**.5 == int(math.sqrt(int(a+b))) else 'No')


Fixed, accepted submission:
import math

a,b=map(str,input().split())
c=int(a+b)
print('Yes' if (math.sqrt(c)//1)**2==c else 'No')
Problem:
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}.  Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.

Incorrect submission (verdict: Wrong Answer):
#A_Rotation
def rotation(c1, c2):
	if str(c1) == str(c2)[:-1]:
		print("YES")
	else:
		print("NO")

if __name__ == "__main__":
	c1 = input()
	c2 = input()
	rotation(c1, c2)

Fixed, accepted submission:
#A_Rotation
def rotation(c1, c2):
	if str(c1) == str(c2)[::-1]:
		print("YES")
	else:
		print("NO")

if __name__ == "__main__":
	c1 = input()
	c2 = input()
	rotation(c1, c2)
Problem:
浩と健次郎の兄弟は猪苗代湖に魚釣りをしに来ました。二人は以下のように点数を決め、釣り上げた魚の合計得点で勝負することにしました。    * イワナは１匹 a 点   * ヤマメは１匹 b 点   * イワナ１０匹ごとに c 点追加   * ヤマメ２０匹ごとに d点追加  浩と健次郎が釣り上げた魚の数をもとに、どちらが勝ちか、あるいは引き分けか判定するプログラムを作成せよ。

Incorrect submission (verdict: Wrong Answer):
h1, h2 = map(int, input().split())
k1, k2 = map(int, input().split())
a, b, c, d = map(int, input().split())
hiroshi = (a * h1) + (b * h2) + (divmod(h1, 10)[0] * c) + (divmod(h2, 20)[0] * d)
kenjiro = (a * k1) + (b * k2) + (divmod(k1, 10)[0] * c) + (divmod(k2, 20)[0] * d)
print("even" if hiroshi else ["hiroshi", "kenjiro"][hiroshi < kenjiro])

Fixed, accepted submission:
h1, h2 = map(int, input().split())
k1, k2 = map(int, input().split())
a, b, c, d = map(int, input().split())
hiroshi = (a * h1) + (b * h2) + (divmod(h1, 10)[0] * c) + (divmod(h2, 20)[0] * d)
kenjiro = (a * k1) + (b * k2) + (divmod(k1, 10)[0] * c) + (divmod(k2, 20)[0] * d)
print("even" if hiroshi == kenjiro else ["hiroshi", "kenjiro"][hiroshi < kenjiro])
Problem:
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.  The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)  Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

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

year = 0
money = 100
while(True):
    money *= 1.01
    money = money // 1
    year += 1
    if(money > x):
        break

print(str(year))


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

year = 0
money = 100
while(True):
    money *= 1.01
    money = money // 1
    year += 1
    if(money >= x):
        break

print(str(year))
Problem:
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".

Incorrect submission (verdict: Wrong Answer):
ins=input().split()
a=int(ins[0])
b=int(ins[1])
c=int(ins[2])

if a<b and b<c:
    print("Yse")
else:
    print("No")



Fixed, accepted submission:
ins=input().split()
a=int(ins[0])
b=int(ins[1])
c=int(ins[2])

if a<b and b<c:
    print("Yes")
else:
    print("No")
Problem:
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.  Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.

Incorrect submission (verdict: Wrong Answer):
iro = list(map(int, input().split()))
shu = 1
iro.sort()
for i in range(1, len(iro)):
  if iro[i - 1] != iro[i]:
    shu += 1
print(iro)

Fixed, accepted submission:
iro = list(map(int, input().split()))
shu = 1
iro.sort()
for i in range(1, len(iro)):
  if iro[i - 1] != iro[i]:
    shu += 1
print(shu)
Problem:
We ask you to select some number of positive integers, and calculate the sum of them.  It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.  Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.  If the objective is achievable, print `YES`. Otherwise, print `NO`.

Incorrect submission (verdict: Wrong Answer):
A, B, C = map(int, input().split())

ans = "No"
for i in range(1, 1000):
    a = A*i
    if a % B == C:
        ans = "Yes"
        break
        
print(ans)

Fixed, accepted submission:
A, B, C = map(int, input().split())

ans = "NO"
for i in range(1, 1000):
    a = A*i
    if a % B == C:
        ans = "YES"
        break
        
print(ans)
Problem:
E869120 found a chest which is likely to contain treasure.   However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.   He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`.  One more thing he found is a sheet of paper with the following facts written on it:    * Condition 1: The string S contains a string T as a contiguous substring.   * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.  Print the string S.   If such a string does not exist, print `UNRESTORABLE`.

Incorrect submission (verdict: Wrong Answer):
s=input()
t=input()
ans=1
table=str.maketrans({'?':'a'})
for i in range(len(s),len(t),-1):
    x=list(s[i-len(t):i])
    if set(x)=={'?'}:
        s=s.translate(table)
        ans=2
        break
    else:
        cnt=0
        for j in range(len(t)):
            if x[j]=='?' or x[j]==t[j]:
                cnt+=1
        
        if cnt==len(t):
            ans=2
            s.replace(s[i-len(t):i],t)
            print(s[i-len(t):i])
            print(s)
            s=s.translate(table)
            break
        else:
            ans=1
            break

if ans==1:
    print('UNRESTORABLE')
else:
    print(s)

Fixed, accepted submission:
import re
s=input().replace('?','.')
t=input()
ans='UNRESTORABLE'
for i in range(len(s)-len(t),-1,-1):
    if re.match(s[i:i+len(t)],t):
        s=s.replace('.','a')
        ans=s[:i]+t+s[i+len(t):]
        break
print(ans)
Problem:
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.  You are given an integer N. Find the N-th Lucas number.  Here, the i-th Lucas number L_i is defined as follows:    * L_0=2   * L_1=1   * L_i=L_{i-1}+L_{i-2} (i≥2)

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

if N == 1:
  print(1)
  exit()

L = [0]*(N+1)
for i in range(2, N+1):
  L[i] = L[i-1] + L[i-2]

print(L[N])


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

if N == 1:
  print(1)
  exit()

L = [0]*(N+1)
L[0] = 2
L[1] = 1
for i in range(2, N+1):
  L[i] = L[i-1] + L[i-2]

print(L[N])
Problem:
Write a program which calculates the area and perimeter of a given rectangle.

Incorrect submission (verdict: Wrong Answer):
line=input().split()
a=int(line[0])
b=int(line[1])
print(a*b)
print((2*a)+(2*b))


Fixed, accepted submission:
line=input().split()
a=int(line[0])
b=int(line[1])
print(a*b,2*(a+b))
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):
l = list(map(int, input().split()))
K = int(input())

l.sort()
for i in range(K):
    l[0] = 2*l[0]
    
print(l[0] + l[1] + l[2])

Fixed, accepted submission:
l = list(map(int, input().split()))
K = int(input())

l.sort()
for i in range(K):
    l[2] = 2*l[2]
    
print(l[0] + l[1] + l[2])
Problem:
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems.  The score allocated to the i-th (1≦i≦N) problem is i points.  Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.  As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.  Determine the set of problems that should be solved.

Incorrect submission (verdict: Wrong Answer):
def solve():
    N = int(input())
    
    s = sum([i for i in range(1, N+1)])
    for i in reversed(range(1, N+1)):
        if s - i <= N:
            return i
        s -= i
        
print(solve())

Fixed, accepted submission:
def solve():
    N = int(input())
    score = 0
    for i in range(1, N+1):
        score += i
        if score >= N:
            break
    x = score - N
    res = list(range(1, x)) + list(range(x+1, i+1))
    return '\n'.join(map(str, res))
    
print(solve())