TnT/CodeNet4Repair huggingface dataset:
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):
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            flag = True
    if flag:
        continue
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))


Fixed, accepted submission:
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            break
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))
Problem:
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.  To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Incorrect submission (verdict: Wrong Answer):
haiku = list(int(i) for i in input().split())
seven = 0
five = 0
for i in range(3):
    if int(haiku[i]) == 7:
        seven += 1
    elif int(haiku[i]) == 5:
        five += 1
if seven == 2 and five == 1:
    print("YES")
else:
    print("NO")

Fixed, accepted submission:
haiku = list(int(i) for i in input().split())
seven = 0
five = 0
for i in range(3):
    if int(haiku[i]) == 7:
        seven += 1
    elif int(haiku[i]) == 5:
        five += 1
if seven == 1 and five == 2:
    print("YES")
else:
    print("NO")
Problem:
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.

Incorrect submission (verdict: Wrong Answer):
n, k = [int(x) for x in input().split()]
if n % 2 == 1:
    ans = 'yes' if (n + 1) / 2 >= k else 'no'
else :
    ans = 'yes' if n / 2 >= k else 'no'

print(ans)

Fixed, accepted submission:
N, K = map(int, input().split())
print('YES' if (N + 1) // 2 >= K else 'NO')
Problem:
Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently.

Incorrect submission (verdict: Wrong Answer):
import sys
from itertools import dropwhile
a = []
try:
    for v in sys.stdin:
        a.append(int(v))

except:
    m = max([a.count(v) for v in set(a)])
    next(dropwhile(lambda x: True, (print(v) for v in set(a) if a.count(v) == m)))

Fixed, accepted submission:
a = [0] * 101
while True:
    try:
        a[int(input())] += 1
    except:
        break
maxv = max(a)
for i, v in enumerate(a):
    if maxv == v:
        print(i)
Problem:
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.  In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.  When activated, each type of robot will operate as follows.    * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.    * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.  Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
k = int(input())
x = list(map(int, input().split()))

ans = 0
for i in x:
  ans += min(i, abs(k - i))
print(ans)

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

ans = 0
for i in x:
  ans += 2 * min(i, abs(k - i))
print(ans)
Problem:
0 から 9 の数字から異なる n 個の数を取り出して合計が s となる組み合わせの数を出力するプログラムを作成してください。n 個の数はおのおの 0 から 9 までとし、１つの組み合わせに同じ数字は使えません。たとえば、n が 3 で s が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、      1 + 2 + 3 = 6   0 + 1 + 5 = 6   0 + 2 + 4 = 6      の 3 通りとなります。

Incorrect submission (verdict: Wrong Answer):
def f2(cnt, n, ci):
    if n < ci:
        return 0
    elif n == ci and cnt > 1:
        return 0
    elif n == ci and cnt == 1:
        return 1
    else:
        v = f2(cnt - 1, n - ci, ci + 1)
        v += f2(cnt, n, ci + 1)
        return v


n, s = map(int, input().split())
print(f2(n, s, 0))

Fixed, accepted submission:
def f2(cnt, n, ci):
    if ci >= 10 or n > 45:
        return 0
    elif n < ci:
        return 0
    elif n == ci and cnt > 1:
        return 0
    elif n == ci and cnt == 1:
        return 1
    else:
        v = f2(cnt - 1, n - ci, ci + 1)
        v += f2(cnt, n, ci + 1)
        return v


while 1:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    print(f2(n, s, 0))
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):
# -*- coding: utf-8 -*-
r,g,b = list(map(int, input().split()))
print('YES' if 10*(g + b)%4==0 else 'NO')

Fixed, accepted submission:
# -*- coding: utf-8 -*-
r,g,b = list(map(int, input().split()))
print('YES' if (10*g + b)%4==0 else 'NO')
Problem:
Snuke has a favorite restaurant.  The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.  So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.

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



y = int( 200 * N / 15 )

print( x - y )

Fixed, accepted submission:
N = int( input() )
x = int( 800 * N )

y = N // 15 * 200
 
print( x - y )
Problem:
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.

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

import math

h = math.floor(x/60)
m = math.floor((x -h*60)/60)
s = math.floor(x - h*60 - m*60)
print(h, ':',m , ':', s)



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

h = x // 3600
m = (x % 3600)//60
s = x % 60

print(h, m, s, sep=":")
Problem:
You went shopping to buy cakes and donuts with X yen (the currency of Japan).  First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.  How much do you have left after shopping?

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

print(a-(((a-b)//c)*c))


Fixed, accepted submission:
x,a,b = [int(input()) for i in range(3)]
print((x-a)%b)
Problem:
You are parking at a parking lot. You can choose from the following two fee plans:    * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.   * Plan 2: The fee will be B yen, regardless of the duration.  Find the minimum fee when you park for N hours.

Incorrect submission (verdict: Wrong Answer):
n,a,b = map(int, input().split())
if n*a > b:
  print(n*a)
else:
  print(b)

Fixed, accepted submission:
n,a,b = map(int, input().split())
if n*a <= b:
  print(n*a)
else:
  print(b)
Problem:
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not.  You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.

Incorrect submission (verdict: Wrong Answer):
S = input()
if len(S)%2 != 0:
  S = S + '?'
for i in range(len(S)-1)[::-2]:
  if S[:i//2] == S[i//2+1:i]:
    print(i//2)
    break

Fixed, accepted submission:
S = input()
if len(S)%2 != 0:
  S = S + '?'
for i in range(len(S)-1)[::-2]:
  if S[:i//2] == S[i//2:i]:
    print(i)
    break
Problem:
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.  To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    str_list = [map(int, input().split())]
    if str_list.count(5) == 2 and str_list.count(7) == 1:
        print('YES')
    else:
        print('NO')





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

if __name__ == "__main__":
    str_list = list(map(int, input().split()))
    if sum(str_list) == 17:
        print('YES')
    else:
        print('NO')
Problem:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Incorrect submission (verdict: Wrong Answer):
N,a,b = (int(x) for x in input().split())
z = 0
for I in range (N+1):
    o = 0
    i = I
    while True:
        o += i%10
        i = round (i/10)
        if i == 0:
            if a <= o <= b:
                print (I)
                z += I
            break
print (z)

Fixed, accepted submission:
import math
N,a,b = (int(x) for x in input().split())
z = 0
for I in range (N):
    o = 0
    i = I+1
    while True:
        o += i%10
        i = math.floor(i/10) 
        if i == 0:
            if a <= o <= b:
                z += I+1
            break
print (z)
Problem:
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.

Incorrect submission (verdict: Wrong Answer):
a,b,c=map(int,input().split())
if (a<c and b<c) or (a>c and b<c):
  print('Yes')
else:
  print('No')

Fixed, accepted submission:
a,b,c=map(int,input().split())
if (a<c and b>c) or (a>c and b<c):
  print('Yes')
else:
  print('No')
Problem:
There is a grid with H rows and W columns.  The square at the i-th row and j-th column contains a string S_{i,j} of length 5.  The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet.    Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location.  For example, the square at the 6-th row and 8-th column should be reported as `H6`.

Incorrect submission (verdict: Wrong Answer):
H,W = map(int,input().split())
L = [list(map(str,input().split())) for i in range(H)]
A = [chr(i) for i in range(ord("A"),ord("Z")+1)]
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "snuke" :
            ans = A[y]+str(x+1)
            print(ans)
            exit()
            

Fixed, accepted submission:
H,W = map(int,input().split())
L = [list(map(str,input().split())) for i in range(H)]
A = [chr(i) for i in range(ord("A"),ord("Z")+1)]
for y in range(H) :
    for x in range(W) :
        if L[y][x] == "snuke" :
            ans = A[x]+str(y+1)
            print(ans)
Problem:
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_

Incorrect submission (verdict: Wrong Answer):
a, b = map(int, input().split())
c = []
for i in range(a):
    x = i + 1
    if b%x == 0:
        c.append(x)
print(c[-1])



Fixed, accepted submission:
a, b = map(int, input().split())
c = []
if a > b:
    a, b = b, a
if b%a == 0:
    print(a)
else:
    while True:
        for i in range(a):
            x = i + 2
            if a%x == 0:
                if b%x == 0:
                    c.append(x)
                    a = a//x
                    b = b//x
                    break
                elif b%(a//x) == 0:
                    c.append(a//x)
                    a = x
                    b = b//(a//x)
                    break
            if x > a**0.5:
                break
        if x > a**0.5:
            break
    s = 1
    for j in c:
        s = s * j
    print(s)
Problem:
You are given a simple connected undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M.  Edge i connects Vertex a_i and b_i bidirectionally.  Determine if three circuits (see Notes) can be formed using each of the edges exactly once.

Incorrect submission (verdict: Wrong Answer):
# -*- coding: utf-8 -*-
from collections import defaultdict

def solve():
    N, M = map(int, input().split())
    D = defaultdict(int)
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1

    if all(d%2==0 for d in D.values()) and (sum(1 for d in D.values() if d>=4)>=2 or sum(1 for d in D.values() if d>=6)>=1):
        res = 'YES'
    else:
        res = 'NO'
    return str(res)
if __name__ == '__main__':
    print(solve())


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

def solve():
    N, M = map(int, input().split())
    F = [list() for _ in range(N+1)]
    D = [int() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        D[a] += 1
        D[b] += 1
        F[a].append(b)
        F[b].append(a)

    E = [0 for _ in range(7)]
    X = list()
    for a,d in enumerate(D[1:], start=1):
        if d%2==0:
            if d >= 6:
                E[6] += 1
            elif d == 4:
                E[4] += 1
                X.append(a)
            else:
                E[d] += 1
        else:
            return 'No'
            E[1] += 1

    if E[6]>0 or E[4]>2:
        return 'Yes'

    elif E[4]<2:
        return 'No'

    else:
        x, y = X
        q = set((y,))
        R = set((x,))
        while q:
            z = q.pop()
            R.add(z)
            q |= set(F[z])-R
        if set(F[x])&R == set(F[x]):
            return 'No'
        else:
            return 'Yes'

if __name__ == '__main__':
    print(solve())
Problem:
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search ”backtracks” to explore edges leaving the vertex from which $v$ was discovered.  This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source.  DFS timestamps each vertex as follows:    * $d[v]$ records when $v$ is first discovered.   * $f[v]$ records when the search finishes examining $v$’s adjacency list.  Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules:    * $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.   * IDs in the adjacency list are arranged in ascending order.   * The program should report the discover time and the finish time for each vertex.   * When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.   * The timestamp starts with 1.

Incorrect submission (verdict: Wrong Answer):
def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
_ = dfs(0, 1)
for i, (d, f) in enumerate(zip(D, F)):
    print(i, d, f)

Fixed, accepted submission:
def dfs(v, cnt):
    D[v] = cnt
    cnt += 1
    for c in edge[v]:
        if D[c] == -1:
            cnt = dfs(c, cnt)
    F[v] = cnt
    cnt += 1
    return cnt


V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
c = 1
for i in range(V):
    if D[i] == -1:
        c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
    print(i+1, d, f)
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())
a = [set() for _ in range(n+1)]
count = 0
for i in range(m):
    x,y = map(int,input().split())
    a[x].add(y)
    a[y].add(x)
    a[0].add((x,y))
    a[0].add((y,x))
for i in range(1, n + 1):
    print(a[i])
    if len(a[i]) == 1:
        count += 1
        continue
    elif len(a[i]) >= 3:
        continue
    if tuple(a[i]) in a[0]:
        continue
    count += 1
if count == n:
    count -= 1
print(count)

Fixed, accepted submission:
from collections import deque
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
deg = [0]*n
seen = [False]*n
for i in range(m):
    x,y = map(int,input().split())
    graph[x-1] += [y-1]
    graph[y-1] += [x-1]
    deg[x-1] += 1
    deg[y-1] += 1
q = deque([i for i in range(n) if deg[i] == 1])
while q:
    v = q.popleft()
    seen[v] = True
    for i in graph[v]:
        deg[i] -= 1
        if deg[i] == 1:
            q.append(i)
if all(seen[i] == 1 for i in range(n)):print(n-1);exit()
print(seen.count(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):
b, c = map(int, input().split())
x=int(b + c)
import math
sqrtx = math.sqrt(x)
flsqrtx = math.floor(sqrtx)
if sqrtx == flsqrtx :
  print("Yes")
else:
  print("No")

Fixed, accepted submission:
b, c = map(str, input().split())
x=int(b + c)
import math
sqrtx = math.sqrt(x)
flsqrtx = math.floor(sqrtx)
if sqrtx == flsqrtx :
  print("Yes")
else:
  print("No")
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):
def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        
            #times += 1
        A[i], A[minj] = A[minj], A[i]
    return A

def BubbleSort(A, N):
    for i in range(N):
        minj = i
        for j in range (i, N):
            if A[j][1:] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]

    return A

N = int(input())
A = [str(x) for x in input().split()]
#print(*A)
print(*BubbleSort(A, N))
print('Stable')
print(*SelectionSort(A, N))
if BubbleSort(A, N) == SelectionSort(A, N):
    print('Stable')
else:
    print('Not stable')

Fixed, accepted submission:
def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A

def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A

N= int(input())
A = [str(x) for x in input().split()]
B = [0 for i in range(N)]
for i in range(N):
    B[i] = A[i]
bubble = BubbleSort(A, N)
selection = SelectionSort(B, N)

#print(*A)
print(*bubble)
print('Stable')
print(*selection)
if bubble == selection:
    print('Stable')
else:
    print('Not stable')
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):
from sys import stdin
N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
v1 = 0
v2 = 0
v4 = 0
for i in a:
    if i % 4 == 0:
        v4 += 1
    elif i % 2 == 0:
        v2 += 1
    else:
        v1 += 1

if (v4 >= v1) and (v2 >= 2):
    print("Yes")
else:
    print("No")


Fixed, accepted submission:
from sys import stdin
N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
v1 = 0
v2 = 0
v4 = 0
for i in a:
    if i % 4 == 0:
        v4 += 1
    elif i % 2 == 0:
        v2 += 1
    else:
        v1 += 1
#print(v4,v2,v1)
if v4 >= (v1 + v2 - 1):
    print("Yes")
else:
    if (v4 >= v1) and (v2 >= 2):
      print("Yes")
    else:
      print("No")