Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02947 (python)

Fixed submission:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Buggy submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        for t in range(T,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
    else:
        continue
print(int(cnt))

Buggy submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    v=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))

Buggy submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))

Buggy submission (verdict: Runtime Error):
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
cnt=0
print(S.values())
for i in S.values():
    mul=1
    if i!=0 and i!=1:
        for t in range(i,1,-1):
            mul*=t
        v=mul/2
        cnt+=v
print(int(cnt))
Problem p02969 (python)

Fixed submission:
r=int(input())
print(3*(r**2))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)
Problem p02995 (python)

Fixed submission:
import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy submission (verdict: Runtime Error):
import fraction
A,B,C,D=map(int,input().split())
L=C*D//(fraction.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D=map(int,input().split())
L=C*D//(math.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D=map(int,input().split())
L=A*B//(math.gcd(A,B))
print(int(B-A+1-(B//C-A//C)-(B//D-A//D)+(B//L-A//L)))
Problem p03206 (python)

Fixed submission:
D=int(input())
if D==25:
    print('Christmas')
elif D==24:
    print('Christmas Eve')
elif D==23:
    print('Christmas Eve Eve')
else:
    print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
D=int(input())
if D==25:
    print('Christmas')
elif D==24:
    print('Christmas Eve')
elif D=23:
    print('Christmas Eve Eve')
else:
    print('Christmas Eve Eve Eve')
Problem p03238 (python)

Fixed submission:
N=int(input())
if N==1:
    print('Hello World')
else:
    A=int(input())
    B=int(input())
    print(A+B)

Buggy submission (verdict: Runtime Error):
N,T=map(int,input().split())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

print(ct[0])
for i in range(N):
    if ct[i][1]<=t:
        print(ct[i][0])
        break
else:
    print('TLE')
Problem p03239 (python)

Fixed submission:
N,T=map(int,input().split())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

for i in range(N):
    if ct[i][1]<=T:
        print(ct[i][0])
        break
else:
    print('TLE')

Buggy submission (verdict: Runtime Error):
N,T=map(int,input().split())
ct=[list(map(int,input().split())) for a in range(N)]

ct=sorted(ct, key=lambda x:(x[0],x[1]))

for i in range(N):
    if ct[i][1]<=t:
        print(ct[i][0])
        break
else:
    print('TLE')
Problem p03262 (python)

Fixed submission:
import fractions
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
A=[]
for t in x:
    A.append(abs(t-X))
ans=A[0]
for s in A:
    ans=fractions.gcd(ans,s)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
A=[]
for t in x:
    A.append(abs(t-X))
ans=A[0]
for s in A:
    ans=math.gcd(ans,s)
print(ans)
Problem p03264 (python)

Fixed submission:
K=int(input())
print(int((K/2)**2) if K%2==0 else int(K/2)*(int(K/2)+1))

Buggy submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
print(x2-(y2-y1),y2-(x1-x2),x1-(y2-y1),y1-(x1-x2),end='')
Problem p03323 (python)

Fixed submission:
A,B= map(int,input().split())
print(":(" if A>8 or B>8 else "Yay!")

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
print((100**D)*N if N<100 else print((N+1)*(100+D))
Problem p03324 (python)

Fixed submission:
D,N=map(int,input().split())
print(((100**D)*N) if N<100 else ((N+1)*(100**D)))

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
print((100**D)*N if N<100 else print((N+1)*(100**D))
Problem p03385 (python)

Fixed submission:
S=input()
line=set(S)
if len(line)==3:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
C=set()
for i in range(A,A+K):
    C.add(i)
for t in range(B-K-1,B+1):
    C.add(t)
for s in C:
    print(s)
Problem p03473 (python)

Fixed submission:
print(48-int(input()))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==x+y+1:
    print('Yes')
else:
    print('No')
Problem p03474 (python)

Fixed submission:
A,B=map(int,input().split())
S=input()
if S[:A].isdecimal() and S[A+1:].isdecimal() and S.count('-')==1 and len(S)==(A+B+1):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==(x+y+1):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-') and len(S)==x+y+1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
if (S[0:A].isdecimal()==True) and (S[A+1:-1].isdecimal()==True) and (S[A]=='-':
    print('Yes')
else:
    print('No')
Problem p03543 (python)

Fixed submission:
N=input()
print('Yes' if N[0]==N[1]==N[2] or N[1]==N[2]==N[3] else 'No')

Buggy submission (verdict: Runtime Error):
N=input()
print('Yes' if N[0]==N[1]==N[2] or N[1]==N[2]==M[3] else 'No')
Problem p03555 (python)

Fixed submission:
C1=list(input())
C2=list(input())
if C1[0]==C2[2] and C1[1]==C2[1] and C1[2]==C2[0]:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N=int(input())
print(int(N**(1/2))**2)
Problem p03556 (python)

Fixed submission:
N=int(input())
print(int(N**(1/2))**2)

Buggy submission (verdict: Runtime Error):
N=int(input())
for t in range(N//2):
    if t**2<=N:
        i=t**2
    else:
        break
print(i)
Problem p03760 (python)

Fixed submission:
O=input()
E=input()
for i in range(len(O)*2-1 if len(O)!=len(E) else len(O)*2):
    if i%2==0:
        print(O[i//2],end="")
    else:
        print(E[i//2],end="")

Buggy submission (verdict: Runtime Error):
O=input()
E=input()
for i in range(len(O)*2):
    if i%2==0:
        print(O[i//2],end="")
    else:
        print(E[i//2],end="")
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))

s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
mind = abs(x - p[0])
pos = [p[0]]
for q in p:
	if abs(x - q) < mind:
		#print(q)
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))
mind = abs(x - p[0])
pos = []
s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
for q in p:
	if abs(x - q) < mind:
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])
Problem p02658 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(x) for x in input().split()]

x = np.prod(a)

if x > 10**18:
    print("-1")
else:
    print(x)
Problem p02743 (python)

Fixed submission:
from decimal import Decimal

a, b, c = map(int, input().split())

a = Decimal(a)
b = Decimal(b)
c = Decimal(c)

if a.sqrt() + b.sqrt() < c.sqrt():
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sympy
a, b, c = map(int, input().split())

if sympy.sqrt(a) + sympy.sqrt(b) >= sympy.sqrt(c):
    print("No")
else:
    print("Yes")
Problem p02748 (python)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

min_cost = min(a) + min(b)

for i in range(M):
    x, y, c = map(int, input().split())
    min_cost = min(a[x-1] + b[y-1] - c, min_cost)

print(min_cost)

Buggy submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())

min_cost = min(a) + min(b)

for i in range(M):
    min_cost = min(a[x[i]-1] + b[x[i]-1] - c[i], min_cost)

print(min_cost)
Problem p02818 (python)

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

p = k
if a < k:
    k = k - a
    a = 0
else:
    k = k - a
    a = a - p

if k < 0:
    k = 0
b = b - k
if b < 0:
    b = 0

print("{}".format(a) + " {}".format(b))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

a, b, k = map(int, input().split())

if k > 10**9:

for i in range(k):
    if a >= 1:
        a = a - 1
    elif b >= 1:
        b = b - 1

print("{}".format(a) + " {}".format(b))
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
count = 0

for i in range(len(s)):
    if s[i] == t[i]:
        count = count + 1

print(count)

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))

c = 0

if b == 1:
    c = 0
elif b / a == 1:
    c = b // a
else:
    c = b // a + 1

print(c)
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d = map(int, input().split())

cnt_c = b // c - (a-1) // c
cnt_d = b // d - (a-1) // d
lcm = c * d // fractions.gcd(c, d)
cnt_cd = b // lcm - (a-1) // lcm

mul = cnt_c + cnt_d - cnt_cd

print(b - a + 1 - mul)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int, input().split())

count_c = int(b / c) - int((a-1) / c)
count_d = int(b / d) - int((a-1) / d)
lcm_cd = c * d / math.gcd(c, d)
count_cd = int(b / lcm_cd) - int((a-1) / lcm_cd)

print(b - a - int(count_c+count_d-count_cd) + 1)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int, input().split())

count_c = (b // c) - ((a-1) // c)
count_d = (b // d) - ((a-1) // d)
lcm_cd = c * d / math.gcd(c, d)
count_cd = (b // lcm_cd) - ((a-1) // lcm_cd)

print(b - a - int(count_c+count_d-count_cd) + 1)

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int, input().split())

count_c = b // c - (a-1) // c
count_d = b // d - (a-1) // d
lcm_cd = c * d / math.gcd(c, d)
count_cd = b // lcm_cd - (a-1) // lcm_cd

print(b - a - int(count_c+count_d-count_cd) + 1)
Problem p02639 (python)

Fixed submission:
A = list(map(int, input().split()))

for i in range(len(A)):
    if A[i] != i+1:
        print(i+1)

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))

for i in range(A):
    if A[i] == i+1:
        print(i+1)
Problem p02657 (python)

Fixed submission:
A, B = map(int, input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
return A*B
Problem p02683 (python)

Fixed submission:
import copy
N, M, X = map(int, input().split())


C =[]
A = {}

for i in range(N):
    ipt = list(map(int, input().split()))
    C.append(ipt[0])
    A[i] = ipt[1:]

bestscore = 99999999999
def rec(n, score, money):
    global bestscore
    if n==N: return
    s = copy.deepcopy(score)
    rec(n+1, s, money)

    money += C[n]
    for i in range(M):
        score[i] += A[n][i]
    

    for i in range(M):
        if score[i] < X:
            s = copy.deepcopy(score)
            rec(n+1, s, money)
            return
    bestscore = min(bestscore, money)

score = [0 for i in range(M)]

rec(0, score, 0)
if bestscore == 99999999999:
    print(-1)
else:
    print(bestscore)

Buggy submission (verdict: Runtime Error):
import copy
N, M, X = map(int, input().split())


C =[]
A = {}

for i in range(N):
    ipt = list(map(int, input().split()))
    C.append(ipt[0])
    A[i] = ipt[1:]

bestscore = 99999999999
def rec(n, score, money):
    global bestscore
    if n==N: return
    s = copy.deepcopy(score)
    rec(n+1, s, money)

    money += C[n]
    for i in range(M):
        score[i] += A[n][i]
    

    for i in range(M):
        if score[i] < X:
            s = copy.deepcopy(score)
            rec(n+1, s, money)
            return
    bestscore = min(bestscore, money)

score = [0 for i in range(N)]

rec(0, score, 0)
if bestscore == 99999999999:
    print(-1)
else:
    print(bestscore)

Buggy submission (verdict: Runtime Error):
N, M, X = map(int, input().split())


C =[]
A = {}

for i in range(N):
    ipt = list(map(int, input().split()))
    C.append(ipt[0])
    A[i] = ipt[1:]

bestscore = 99999999999
def rec(n, score, money):
    global bestscore
    if n==N: return
    rec(n+1, score[:], money)

    money += C[n]
    for i in range(M):
        score[i] += A[n][i]
    

    for i in range(M):
        if score[i] < X:
            rec(n+1, score[:], money)
            return
    bestscore = min(bestscore, money)

score = [0 for i in range(N)]

rec(0, score, 0)
if bestscore == 99999999999:
    print(-1)
else:
    print(bestscore)
Problem p02756 (python)

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy submission (verdict: Runtime Error):
    S = input()
    Q = int(input())
     
    # print(S, Q)
     
    queries = []
    for i in range(Q):
        query = input()
        queries.append(query)
     
    from collections import deque
    slist = deque()
	slist.append(S)
    for query in queries:
        if query == "1":
            isReversed = not isReversed
        else:
            t, f, c = query.split()
            if f == '1':
                if isReversed:
                    slist.append(c)
                else:
                    slist.appendleft(c)
            else:
                if isReversed:
                    slist.appendleft(c)
                else:
                    slist.append(c)
     
    if isReversed:
        slist.reverse()
    print("".join(slist))

Buggy submission (verdict: Runtime Error):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f=="1"
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
if isReversed:
    slist.reverse()

print("".join(slist))
Problem p04001 (python)

Fixed submission:
def f(n):
    if n <= 0:
        return 1
    return 2**(n-1)

s = input()

score = 0
for blocksize in range(1,len(s)+1):
    for startpoint in range(len(s)):
        if startpoint+blocksize >= (len(s)+1): continue
        block = s[startpoint:startpoint+blocksize]  
        ss = int(block) * f(startpoint) * f(len(s) - (startpoint+blocksize))
        # print("{} ({}, {}): {}".format(block, startpoint, len(s) - (startpoint + blocksize), ss))
        score += ss
print(score)
exit()

Buggy submission (verdict: Runtime Error):
s = input()
# print(s)

score = 0
for blocksize in range(1,len(s)+1):
    for startpoint in range(len(s)):
        # print("hi", startpoint+blocksize)
        if startpoint+blocksize >= (len(s)+1): continue
        block = s[startpoint:startpoint+blocksize]
        ss = int(block) * math.factorial(startpoint) * math.factorial(len(s) - (startpoint+blocksize))
        # print("{} ({}, {}): {}".format(block, startpoint, len(s) - (startpoint + blocksize), ss))
        score += ss
print(score)
exit()
Problem p02660 (python)

Fixed submission:
from collections import deque
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a.sort()
    return a

q = deque()
prime = prime_factorize(N)
for x in prime:
  q.append(x)

#print(q)
count = 0
done = []
while N != 1:
  break_flag = False
  if len(q) == 0:
    break
  x = q.popleft()
  #print(N, q, x)
  if x == 1:
    continue
  
  if x in done:
    mul = x
    while mul in done:
      if len(q) == 0:
        break_flag = True
        break
      pop = q.popleft()
      #print(x, pop)
      if x != pop:
        #print(x, pop, q)
        q.appendleft(pop)
        #print(q)
        break_flag = True
        break
      mul *= pop
    x = mul
    if break_flag:
      continue
  
  if N % x == 0:
    N = N // x
    count += 1
    done.append(x)

print(count)
#print(done)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    divisors.sort()
    return divisors

q = deque()
for x in make_divisors(N):
  q.append(x)
  
count = 0
done = []
while N != 1:
  x = q.popleft()
  if x == 1:
    continue
  
  if x in done:
    mul = x
    while mul in done:
      mul *= q.popleft()
    
  if N % x == 0:
    N = N // x
    count += 1
    done.append(x)

print(count)
Problem p02664 (python)

Fixed submission:
T = list(input())
N = len(T)

for i in range(N):
  if T[i] == '?':
    if T == ['?']:
      print('D')
      exit()
    if i == 0:
      if T[1] == 'D':
        T[0] = 'P'
      elif T[1] == 'P':
        T[0] = 'D'
      else:
        T[0] = 'P'
    elif i == N - 1:
      T[i] = 'D'
    else:
      if T[i-1] == 'P':
        T[i] = 'D'
      else:
        if T[i+1] == '?':
          T[i] = 'P'
        else:
          if T[i+1] == 'D':
            T[i] = 'P'
          else:
            T[i] = 'D'
          
print("".join(T))

Buggy submission (verdict: Runtime Error):
T = list(input())
N = len(T)

for i in range(N):
  if T[i] == '?':
    if i == 0:
      if T[1] == 'D':
        T[0] = 'P'
      elif T[1] == 'P':
        T[0] = 'D'
      else:
        T[0] = 'P'
    elif i == N - 1:
      T[i] = 'D'
    else:
      if T[i-1] == 'P':
        T[i] = 'D'
      else:
        if T[i+1] == '?':
          T[i] = 'P'
        else:
          if T[i+1] == 'D':
            T[i] = 'P'
          else:
            T[i] = 'D'
          
print("".join(T))
Problem p02678 (python)

Fixed submission:
from collections import deque, defaultdict
N, M = map(int, input().split())
D = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    D[s].append(t)
    D[t].append(s)
    
q = deque()
q.append(1)
d = defaultdict(lambda: float("inf"))
d[1] = 0

while q:
  u = q.popleft()
  
  for v in D[u]:
    if d[v] == float("inf"):
      d[v] = u
      q.append(v)
      
if len(d) == N:
  print("Yes")
else:
  print("No")
  exit()
  
for i in range(2, N+1):
  print(d[i])

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
N, M = (int(i) for i in input().split())  

arr = np.array([[0] * N] * N)

for _ in range(M):
  A, B = (int(i) for i in input().split())  
  arr[A-1][B-1] = 1
  arr[B-1][A-1] = 1

lis = [-1] * (N-1)
def recur(bef, visit_list):
  all_visited = True
  #print(bef, visit_list)
  for i, x in enumerate(arr[bef-1]):
    if x and i+1 not in visit_list:
      recur(i+1, visit_list + [bef])
      lis[i+1 - 2] = bef
      all_visited = False
      
  if all_visited:
    return
  
recur(1, [])
if -1 in lis:
  print('No')
else:
  print('Yes')
  for x in lis:
    print(x)
Problem p02684 (python)

Fixed submission:
import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) - 1 for i in input().split()] 
N = len(A)

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

now = 0
lis = []
p = {}
for i in range(N):
  now = A[now]
  if now in p:
    break
  
  p[now] = i
  lis.append(now)

if K < i:
  print(lis[K-1] + 1)
else:
  print(lis[(K-i-1) % (i - p[now]) + p[now]] + 1)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) - 1 for i in input().split()] 
N = len(A)

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

now = 0
lis = []
p = {}
for i in range(N):
  now = A[now]
  if now in p:
    break
  
  p[now] = i
  lis.append(now)

if K < i:
  print(lis[i] + 1)
else:
  print(lis[(K-i-1) % (i - p[now]) + p[now]] + 1)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = (int(i) for i in input().split())  
A = [int(i) for i in input().split()] 

def has_duplicates(seq):
  return len(seq) != len(set(seq))

lis = [1]
idx = 0

check_l = [0] * N
for i in range(N):
  lis.append(A[idx])
  if check_l[A[idx]] != 1:
    lis.pop(-1)
    found = lis.index(A[idx])
    lis.append(A[idx])
    break
  check_l[A[idx]] == 1
  idx = A[idx]-1
  
print(lis[found:i+1][(K-found) % (i - found + 1)])
Problem p02687 (python)

Fixed submission:
S = input()

if S == 'ARC':
  print('ABC')
else:
  print('ARC')

Buggy submission (verdict: Runtime Error):
S = input()

if S == 'ARC':
  print('ABC')
else:
  print('ARC)
Problem p02720 (python)

Fixed submission:
K = int(input())
lis = []

lis = []
def search(s):
  lis.append(s)
  
  if int(s) > 3234566667:
    return
  
  it = int(s[-1])
  if it == 0:
    search(s + '0')
    search(s + '1')
  elif it == 9:
    search(s + '8')
    search(s + '9')
  else:
    search(s + str(it - 1))
    search(s + str(it))
    search(s + str(it + 1))
  

for i in range(1, 10):
  search(str(i))

x = list(map(int, lis))
x.sort()
print(x[K-1])

Buggy submission (verdict: Runtime Error):
K = int(input())
lis = []

def search(s):
  lis.append(s)
  
  if int(s) > 3234566667:
    return
  
  it = int(s[-1])
  if it == 0:
    search(s + '1')
  elif it == 9:
    search(s + '8')
  else:
    search(s + str(it - 1))
    search(s + str(it + 1))
  

for i in (1, 10):
  search(str(i))
  
ans = sorted(map(int,lis))
print(ans[K-1])