TnT/CodeNet4Repair huggingface dataset:
Problem:
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}.  Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.

Incorrect submission (verdict: Wrong Answer):
H, W = input().split(' ')
H = int(H)
W = int(W)
print('*'*(W+2))
for i in range(H):
  s = input()
  print('*'+s+'*')
print('*'*(W+2))

Fixed, accepted submission:
H, W = input().split(' ')
H = int(H)
W = int(W)
print('#'*(W+2))
for i in range(H):
  s = input()
  print('#'+s+'#')
print('#'*(W+2))
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: Time Limit Exceeded):
import sys

def main():
    N = int(input())
    A = list(map(int,input().split()))

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                break
        t += 1

main()


Fixed, accepted submission:
import sys

def main():
    N = int(input())
    A = list(map(int,input().split()))

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()
Problem:
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Incorrect submission (verdict: Wrong Answer):
nums = input()
nums = nums.split()
satu_num = int(nums[0])
sum_money = int(nums[1])

judge = True
count_one = -1
count_two = -1
count_three = -1

for a in range(0,satu_num+1):
  man = 10000*a
  for b in range(0,satu_num+1):
    go_senn = 5000*b
    senn = 1000*(satu_num-a-b)
    if senn<0:
      break
    else:
      ans = man+go_senn+senn
      if ans == sum_money:
        count_one += a+1
        count_two += b+1
        count_three += (satu_num-a-b)+1
        break
      else:
        pass
print(count_one,count_two,count_three)
     

Fixed, accepted submission:
nums = input()
nums = nums.split()
satu_num = int(nums[0])
sum_money = int(nums[1])

judge = True
count_one = -1
count_two = -1
count_three = -1

for a in range(0,satu_num+1):
  man = 10000*a
  for b in range(0,satu_num+1):
    go_senn = 5000*b
    senn = 1000*(satu_num-a-b)
    if satu_num-a-b<0:
      break
    else:
      ans = man+go_senn+senn
      if ans == sum_money:
        count_one = a
        count_two = b
        count_three = (satu_num-a-b)
        break
      else:
        pass
print(count_one,count_two,count_three)
Problem:
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.   The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.  An edge whose removal disconnects the graph is called a _bridge_.   Find the number of the edges that are bridges among the M edges.

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


def dfs(i):
    visited.add(i)
    for k in From[i]:
        if k not in visited:
            dfs(k)
    for k in To[i]:
        if k not in visited:
            dfs(k)

def bridge(j):
    for i in Edge:
        if i == j:
            continue
        else:
            From[i[0]-1].append(i[1]-1)
            To[i[1]-1].append(i[0]-1)
    dfs(0)
    return True if visited.__len__() != N else False
ans = 0
for j in Edge:
    From = [[] for i in range(N)]
    To = [[] for i in range(N)]
    visited = set()
    ans += bridge(j)
    print(From)
    print(To)
    print(visited)
print(ans)


Fixed, accepted submission:
N, M = map(int,input().split())
Edge = [list(map(int,input().split())) for i in range(M)]


def dfs(i):
    visited.add(i)
    for k in From[i]:
        if k not in visited:
            dfs(k)
    for k in To[i]:
        if k not in visited:
            dfs(k)

def bridge(j):
    for i in Edge:
        if i == j:
            continue
        else:
            From[i[0]-1].append(i[1]-1)
            To[i[1]-1].append(i[0]-1)
    dfs(0)
    return True if visited.__len__() != N else False
ans = 0
for j in Edge:
    From = [[] for i in range(N)]
    To = [[] for i in range(N)]
    visited = set()
    ans += bridge(j)
    #print(From)
    #print(To)
    #print(visited)
print(ans)
Problem:
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
c = [list(map(int, input().split())) for _ in range(N)]
a.sort(key=lambda x: (x[0], x[1]))
c.sort(key=lambda x: (x[0], x[1]))
cnt = 0

print(cnt)

Fixed, accepted submission:
import copy

N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
b = [list(map(int, input().split())) for _ in range(N)]

chk = [0] * (2 * N)
cpchk =[]
pare = [-1] * (2 * N)
ans = 0

d = [[] for _ in range(2 * N)]
for i in range(N):
    for j in range(N):
        if a[i][0] < b[j][0] and a[i][1] < b[j][1]:
            d[i].append(j + N), d[j + N].append(i)

def dfs(v):
    cpchk[v] = 1
    for i in range(len(d[v])):
        u = d[v][i]
        w = pare[u]
        if w < 0 or cpchk[w] == 0 and dfs(w):
            pare[v] = u
            pare[u] = v
            return True
    return False

def bipartite_mattinc():
    global ans
    global cpchk
    for i in range(2 * N):
        if pare[i] < 0:
            cpchk = copy.deepcopy(chk)
            if dfs(i):
                ans += 1
    return ans

print(bipartite_mattinc())
Problem:
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.  However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.  Find the number of ways she can travel to the bottom-right cell.  Since this number can be extremely large, print the number modulo 10^9+7.

Incorrect submission (verdict: Time Limit Exceeded):
H, W, A, B = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
fac = [1 for _ in range(10**6+1)]
for i in range(1, 10 **6):
    fac[i+1] = fac[i] * (i + 1)

def combination(n, r):
    result = fac[n] // (fac[r] * fac[n-r])
    return result

for i in range(B, W):
    ans += (combination(H - A - 1 + i, i) * combination(A - 1 + W - i - 1, W - i -1))
    ans %= mod
print(ans)


Fixed, accepted submission:
H, W, A, B = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod


def combination(x, y):
    return X[x] * Y[y] * Y[x - y] % mod


for i in range(B, W):
    ans += (combination(H - A - 1 + i, i) * combination(A - 1 + W - i - 1, W - i -1))
    ans %= mod
print(ans)
Problem:
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.  He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.  So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`.  Find the minimum number of iterations for the rewrite operation.

Incorrect submission (verdict: Wrong Answer):
S=input()
print(sum(s=="CODEFESTIVAL2016"[i] for i,s in enumerate(S)))

Fixed, accepted submission:
S=input()
print(sum(s!="CODEFESTIVAL2016"[i] for i,s in enumerate(S)))
Problem:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.    An example of a trapezoid  Find the area of this trapezoid.

Incorrect submission (verdict: Wrong Answer):

a = int(input())
b = int(input())
h = int(input())

# (a+b)*h/2
answer = (a + b) * h / 2
print(answer)


Fixed, accepted submission:

a = int(input())
b = int(input())
h = int(input())

# (a+b)*h/2
answer = (a + b) * h / 2
print(int(answer))
Problem:
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:    * For any two vertices painted in the same color, the distance between them is an even number.  Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
from collections import deque
n = int(input())

tree = [[] for _ in range(n+1)]
color1 = [-1] * (n+1)
color1[1] = 0
color2 = [-1] * (n+1)
color2[1] = 1
for _ in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

print(tree)
q = deque([1])
visited = {1}
while len(q) > 0:
    now = q.popleft()
    visited.add(now)
    for v, w in tree[now]:
        if v in visited:
            pass
        else:
            q.append(v)
            if w % 2 == 0:
                color1[v] = color1[now]
                color2[v] = color2[now]
            else:
                color1[v] = int(not color1[now])
                color2[v] = int(not color2[now])

print("\n".join(tuple(map(str, color1[1:]))))







Fixed, accepted submission:
from collections import deque
n = int(input())

tree = [[] for _ in range(n+1)]
color1 = [-1] * (n+1)
color1[1] = 0
color2 = [-1] * (n+1)
color2[1] = 1
for _ in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

q = deque([1])
visited = {1}
while len(q) > 0:
    now = q.popleft()
    visited.add(now)
    for v, w in tree[now]:
        if v in visited:
            pass
        else:
            q.append(v)
            if w % 2 == 0:
                color1[v] = color1[now]
                color2[v] = color2[now]
            else:
                color1[v] = int(not color1[now])
                color2[v] = int(not color2[now])

print("\n".join(tuple(map(str, color1[1:]))))
Problem:
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i.  The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.  When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.  What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Incorrect submission (verdict: Wrong Answer):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[0]
    for i in range(1, n//2):
        ans += a[i]*2
    if n%2 == 1:
        ans += a[n//2]
    print(ans)

if __name__ == "__main__":
    main()

Fixed, accepted submission:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(key=lambda x: -x)
    ans = a[0]
    for i in range(1, n//2):
        ans += a[i]*2
    if n%2 == 1:
        ans += a[n//2]
    print(ans)

if __name__ == "__main__":
    main()
Problem:
There are N integers a_1, a_2, ..., a_N not less than 1. The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P.  Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N.

Incorrect submission (verdict: Wrong Answer):
import math
from collections import Counter
n, p = [int(_) for _ in input().split()]

def isprime_alpha(n):
    if n == 1:
        return True
    elif n == 2:
        return True
    elif n == 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    else:
        for j in range(5, math.ceil(n ** (1/2))+1):
            if n % j == 0:
                return False
        return True

def factor(n, fac_list):
    if isprime_alpha(n):
        fac_list.append(n)
        return fac_list
    else:
        for i in range(2, math.ceil(n ** (1/2))+1):
            if n % i == 0:
                fac_list.append(i)
                return factor(n // i, fac_list)

list = []
list_result = factor(p, list)
print(list_result)
counter_dict = Counter(list_result)
print(counter_dict)

result = 1
for key, value in counter_dict.items():
    if value % n != 0:
        value -= value % n
    for j in range(value // n):
        result *= key

print(result)

Fixed, accepted submission:
import math
from collections import Counter
n, p = [int(_) for _ in input().split()]

def isprime_alpha(n):
    if n == 1:
        return True
    elif n == 2:
        return True
    elif n == 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    else:
        for j in range(5, math.ceil(n ** (1/2))+1):
            if n % j == 0:
                return False
        return True

def factor(n, fac_list):
    if isprime_alpha(n):
        fac_list.append(n)
        return fac_list
    else:
        for i in range(2, math.ceil(n ** (1/2))+1):
            if n % i == 0:
                fac_list.append(i)
                return factor(n // i, fac_list)

list = []
list_result = factor(p, list)
counter_dict = Counter(list_result)

result = 1
for key, value in counter_dict.items():
    if value % n != 0:
        value -= value % n
    for j in range(value // n):
        result *= key

print(result)
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):
S = input()[::-1]

DREAM = 'dream'[::-1]
DREAMER = 'dreamer'[::-1]
ERASE = 'erase'[::-1]
ERASER = 'eraser'[::-1]

keywords = (DREAM, DREAMER, ERASE, ERASER)

while len(S) > 0:
    for keyword in keywords:
        if S.startswith(keyword):
            S = S[len(keyword):]
            break
    else:
        break

if len(S) == 0:
    print('YES')
else:
    print('NO')


Fixed, accepted submission:
N = int(input())
records = [tuple(map(int, input().split(' '))) for _ in range(N)]

pre_t = 0
pre_x = 0
pre_y = 0

for t, x, y in records:
    turn = t - pre_t
    dx = abs(x - pre_x)
    dy = abs(y - pre_y)

    if turn < (dx + dy):
        print('No')
        break

    if turn % 2 != (dx + dy) % 2:
        print('No')
        break

    pre_t = t
    pre_x = x
    pre_y = y
else:
    print('Yes')
Problem:
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".

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

for i in [2, 5, 6, 7 ,8]:
    if i in a:
        print("No")
        break
    else:
        if i == 8:
            print("Yes")

Fixed, accepted submission:
a = [int(i) for i in input().split()] 
b = []
for i in a:
    if i in [2, 3, 5, 6, 8]:
        print("NO")
        break
    elif i in b:
        print("NO")
        break
    else:
        b.append(i)
        if len(b) == 4:
            print("YES")
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()
print("2018/01"+S[-2:])

Fixed, accepted submission:
S=input()
print("2018/01/"+S[-2:])
Problem:
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.  Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:    * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.  For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.    Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.

Incorrect submission (verdict: Wrong Answer):
a=int(input())
ans=a//11*2
a%=11
if a>=6>=1:ans+=1
elif a!=1:ans+=2
print(ans)

Fixed, accepted submission:
a=int(input())
ans=a//11*2
a%=11
if 6>=a>=1:ans+=1
elif a!=0:ans+=2
print(ans)
Problem:
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.  You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.  Find B_i for each i = 1, 2, ..., N.

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

XX = sorted(X)
before = XX[N//2 -1]
after = XX[N//2]

print(X)
for i in X:
    if i <= before:
        print(after)
    else:
        print(before)

Fixed, accepted submission:
N = int(input())
X = list(map(int, input().split()))

XX = sorted(X)
before = XX[N//2 -1]
after = XX[N//2]

for i in X:
    if i <= before:
        print(after)
    else:
        print(before)
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):
if __name__ == '__main__':
    r, g, b = map(int, input().split())
    num = 100 * r + 10 * g + b
    if num % 4 == True:
        print("YES")
    else:
        print("NO")

Fixed, accepted submission:
if __name__ == '__main__':
    r, g, b = map(int, input().split())
    num = 100 * r + 10 * g + b
    if num % 4 == 0:
        print("YES")
    else:
        print("NO")
Problem:
太郎君は10冊の本を購入した． 後日， レシートをもとに価格を調べようとしたが， レシートには汚れがあり， ある本の価格が読み取れなかった． その本の価格を， 10冊の総額と他の9冊の価格から計算することにした．  価格が読み取れなかった本の価格を出力するプログラムを書け． なお，本の価格はすべて正の整数である． また，消費税を考慮する必要はない．

Incorrect submission (verdict: Wrong Answer):
n=int(input())
l=[]
for i in range(9):
	tmp=int(input())
	l.append(tmp)
	ans=0
for i in range(9):
	ans+=l[i]
	print(n-ans)
	

Fixed, accepted submission:
while(1):
	N=int(input())
	if(N==0):
 	  exit()
	l=[]
	for i in range(9):
		tmp=int(input())
		l.append(tmp)
	ans=0
	for i in range(9):
		ans+=l[i]
		a=N-ans
	print(a)
Problem:
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.     

Incorrect submission (verdict: Wrong Answer):
print(
    (lambda out: 'No' if out else 'Yes')(
        (lambda w, h, x, y, r: x-r < 0 or x+r < w or y-r < 0 or y+r < h)(
            *map(int, input().split()))))

Fixed, accepted submission:
print(
    (lambda out: 'No' if out else 'Yes')(
        (lambda w, h, x, y, r: x-r < 0 or w < x+r or \
                               y-r < 0 or h < y+r)(
            *map(int, input().split()))))
Problem:
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Incorrect submission (verdict: Wrong Answer):
import math
a = int(input())
if a%2 == 0:
    print(a/2-1)
else:
    print(math.floor(a/2))

Fixed, accepted submission:
import math
a = int(input())
if a%2 == 0:
    print(int((a/2-1)))
else:
    b = int(math.floor(a/2))
    print(b)
Problem:
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.  To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:    * The `0` key: a letter `0` will be inserted to the right of the string.   * The `1` key: a letter `1` will be inserted to the right of the string.   * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.  Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?

Incorrect submission (verdict: Wrong Answer):
a = str(input())
s = len(a)
x = ""
while s > 0:
    if a[0] == "0":
        x += "0"
    elif a[0] == "1":
        x += "1"
    else:
        x += "\b"
    s = s - 1
    a = a[1:]
print(x)

Fixed, accepted submission:
a = str(input())
s = len(a)
x = ""
while True:
    if s == 0:
        break
    elif a[0] == "0":
        x += "0"
    elif a[0] == "1":
        x += "1"
    elif a[0] == "B":
        x = x[:-1]
    s = s - 1
    a = a[1:]
print(x)