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

Fixed submission:
S = input().strip()

answer = 0

for n in range(2**(len(S)-1)):
    A = [0]
    for d in range(9):
        if n & (1 << d):
            A.append(d+1)
    T = []
    #print("A", A)
    for l, r in zip(A, A[1:]):
        T.append(int("".join(S[l:r])))
    T.append(int("".join(S[A[-1]:])))
    answer += sum(T)

print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
TA = []
for i in range(N):
    T, A = map(int, input().split())
    TA.append((T, A))

T, A = TA[0]
answer = T+A
p = 1
prev = p
pT, pA = T, A
for i in range(1,N):
    # (T+A) * p >= prev
    # p >= prev/(T+A)
    T, A = TA[i]
    s = T+A
    p = (answer+s-1)//s
    p1 = (pT+T-1)//T
    p2 = (pA+A-1)//A
    p = max([p,p1,p2])
    pT, pA = p*T, p*A
    answer =  pT+pA
    #print(T, A, p, answer, sep="\t")
print(answer)
Problem p04012 (python)

Fixed submission:
from collections import Counter
r = 0
cnt = Counter(input())
for c in cnt:
    r += cnt[c] % 2
if r == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from collections import Counter
r = 0
cnt = Counter(input()):
for c in cnt:
    r += cnt[c] % 2
if r == 0:
    print("Yes")
else:
    print("No")
Problem p04013 (python)

Fixed submission:
N, A = map(int, input().split())
X = sorted([int(x) for x in input().split()])
from collections import defaultdict , Counter
dp = defaultdict(Counter)

dp[0] = Counter({0:1})

for i in range(1, N+1):
    x = X[i-1]
    k = 0
    update = []
    for s, counter in list(dp.items()):
        for nCard, count in counter.items():
            update.append((s+x, nCard+1, count))

    for key, value, diff in update:
        dp[key][value] += diff

def printCounter(counter):
    if len(counter) == 0:
        return ""
    return dict(counter)
if False:
    for s in range(0, max(X)*N):
        print("%2d" % s, "|", printCounter(dp[s]))

answer = 0
for s, counter in dp.items():
    q, r = divmod(s, A)
    if r != 0:
        continue
    answer += counter[q]
print(answer-1)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

@lru_cache(1000000000, False)
def solve(i, n, s):
    if s < 0:
        return -1
    if N-i+1 < n:
        return -1
    if n == 0:
        if s == 0:
            return 1
        else:
            return -1
    if i == N:
        return -1
    s1 = solve(i+1, n-1,s-X[i])
    s2 = solve(i+1, n, s)
    if s1 == -1 and s2 == -1:
        return -1
    if s1 == -1:
        return s2
    if s2 == -1:
        return s1
    return s1 + s2


answer = 0
for n in range(1, N+1):
    s = solve(0, n, n*A)
    if s != -1:
        #print(n, s)
        answer += s
print(answer)

def test():
    import itertools
    for a in itertools.combinations(X,3):
        if sum(a) == A*3:
            print(a)
Problem p04032 (python)

Fixed submission:
def solve(S):
    N = len(S)
    # N <= 10**5
    if N == 2:
        if S[0] == S[1]:
            return 1, 2
    for i in range(0, N-2):
        if S[i] == S[i+2]:
            return i+1, i+3
        if S[i] == S[i+1]:
            return i+1, i+3
        if S[i+1] == S[i+2]:
            return i+1, i+3
    return -1, -1
S = input()
print(*solve(S))

Buggy submission (verdict: Runtime Error):
def solve(S):
    N = len(S)
    if N == 2:
        if S[0] == S[1]: # oxx
            return i+1,i+2
    for i in range(N-2):
        if S[i] ==  S[i+1]:  # xxo
            return i+1,i+2
        if S[i+1] == S[i+2]: # oxx
            return i+2,i+3
        if S[i] == S[i+2]:   # xox
            return i+1,i+3
    return -1, -1
def solv(s):
    a, b = solve(s)
    print(s[a-1:b])
    return a, b
#solv("oxx")
print(*solve(input()))

Buggy submission (verdict: Runtime Error):
def solve(S):
    N = len(S)
    if N == 2:
        if S[0] == S[1]: # oxx
            return 1,2
    for i in range(N-2):
        if S[i] ==  S[i+1]:  # xxo
            return i+1,i+2
        if S[i+1] == S[i+2]: # oxx
            return i+2,i+3
        if S[i] == S[i+2]:   # xox
            return i+1,i+3
    return -1, -1
def solv(s)print(*solve(input()))

Buggy submission (verdict: Runtime Error):
def solve(S):
    N = len(S)
    if N == 2:
        if S[0] == S[1]: # oxx
            return i+1,i+2
    for i in range(N-2):
        if S[i] ==  S[i+1]:  # xxo
            return i+1,i+2
        if S[i+1] == S[i+2]: # oxx
            return i+2,i+3
        if S[i] == S[i+2]:   # xox
            return i+1,i+3
    return -1, -1
def solv(s):
    a, b = solve(s)
    print(s[a-1:b])
    return a, b
#solv("oxx")
print(*solve(input()))
Problem p04045 (python)

Fixed submission:
N, K = map(int, input().split())
D = [x for x in input().split()]

while True:
    S = str(N)
    if not any(d in S for d in D):
        break
    N += 1
print(N)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)

print(func(str(N), 0, over=False))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)

print(func(str(N), 0, over=False))
Problem p02664 (python)

Fixed submission:
T = str(input())
T=list(T)
if not T[0]=='?':
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'
else:
    T[0]='D'
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'

print(''.join(T))

Buggy submission (verdict: Runtime Error):
T = str(input())
T=list(T)
if not T[0]=='?':
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'
else:
    T[0]='D'
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)]=='?':
        T[len(T)]='D'

print(''.join(T))

Buggy submission (verdict: Runtime Error):
T = str(input())
T=list(T)
if not T[0]=='?':
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)]='D'
else:
    T[0]='D'
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)]=='?':
        T[len(T)]='D'
print(','.join(T))
Problem p02678 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
#print(AB)
links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)
#print(AB)
#print(links)
result = [-1] * (N + 1)
q = deque([1])
#print(q)
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
            #print(q)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
print(AB)
links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)
print(AB)
print(links)
result = [-1] * (N + 1)
q = deque([1])
print(q)
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
            print(q)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))
Problem p02684 (python)

Fixed submission:
N,K = map(int, input().split())
List = list(map(int, input().split()))

a=[]

for i in range(N):
    a.append(-1)
#print(a)
b=1
for i in range(N):
    if a[b-1]==-1:
        a[b-1]=i+1
        b=List[b-1]
        
    else:
        c=i
        break
#print(a)
#print(b,c)

num=a[b-1]-1
T=c-num
#print(T)
e=1
if K<num:
    for i in range(K):
        e=List[e-1]
    print(e)
else:
    qw=(K-num)%T
    List_new=[]
    for i in range(T):
        List_new.append(b)
        b=List[b-1]
    print(List_new[qw])

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

a=[]

for i in range(N):
    a.append(-1)
#print(a)
b=1
for i in range(N):
    if a[b-1]==-1:
        a[b-1]=i+1
        b=List[b-1]
        
    else:
        c=i
        break
#print(a)
#print(b,c)

num=a[b-1]-1
T=c-num
#print(T)
e=1
if K<num:
    for i in range(K):
        e=List(e-1)
    print(e)
else:
    qw=(K-num)%T
    List_new=[]
    for i in range(T):
        List_new.append(b)
        b=List[b-1]
    print(List_new[qw])

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

a=[]
b=1
for i in range(N):
    if not b in a:
        a[i]=b
        b=List[b-1]
    else:
        c=i
        break
#print(a)
#print(b,c)
num=a.index(b)
#print(T,num)
T=c-num
if K<num:
    print(a[K])
else:
    print(a[num:][(K-num)%T])

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

a=[]

for i in range(N):
    a.append(-1)
print(a)
b=1
for i in range(N):
    if not b in a:
        a[i]=b
        b=List[b-1]
    else:
        c=i
        break
print(a)
print(b,c)
num=a.index(b)
print(T,num)
T=c-num
if K<num:
    print(a[K])
else:
    print(a[num:][(K-num)%T])
Problem p02690 (python)

Fixed submission:
#D
X=int(input())
for i in range(1000):
    for a in range(1000):
        if a**5-(a-i)**5==X:
            print(a,a-i)
            break

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
X= int(input())

B=-X**(1/5)
while True:
    print(B)
    A= Decimal((X+B**5)**(1/5))
    
    if int(A)==A and A>B:
        print(A,B)
        break
    else:
        B=B+1

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
X= int(input())
B=1
while True:
    A=Decimal((X+B**5)**(1/5))
    if int(A)==A and A>B:
        print(A,B)
        break
    else:
        if B>=0:
            B=-1*B       
        else:
            B=-1*B+1
Problem p02756 (python)

Fixed submission:
S = str(input())
Q = int(input())
List = [list(map(str, input().split())) for i in range(Q)]

#print(List)

#S='a'
#Q=4
#List=[['2', '1', 'p'], ['1'], ['2', '2', 'c'], ['1']]
han=0
b=''
for a in List:
    if a[0]=='1':
        han+=1
    if a[0]=='2':
        if (a[1]=='1' and han%2==0) or (a[1]=='2' and han%2==1):
            b+=a[2]
        if (a[1]=='2' and han%2==0) or (a[1]=='1' and han%2==1):
            S=S+a[2]
#print(S)
#print(b)
if han%2==0:
    print(b[::-1]+S)
else:
    print(S[::-1]+b)

Buggy submission (verdict: Runtime Error):
S = str(input())
Q = int(input())
List = [list(map(str, input().split())) for i in range(Q)]

#print(List)

#S='a'
#Q=4
#List=[['2', '1', 'p'], ['1'], ['2', '2', 'c'], ['1']]
han=0
b=''
for a in List:
    if a[0]=='1':
        han+=1
    if a[0]=='2':
        if (a[1]=='1' and han%2==0) or (a[1]=='2' and han%2==1):
            b=+a[2]
        if (a[1]=='2' and han%2==0) or (a[1]=='1' and han%2==1):
            S=S+a[2]
            
if han%2==0:
    print(b[::-1]+S)
else:
    print(S[::-1]+b)
Problem p02761 (python)

Fixed submission:
N,M = map(int, input().split())
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i]= map(int, input().split())
    
n=[-1]*N
w=True
for i in range(M):
    if n[s[i]-1]==-1:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]==c[i]:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]!=c[i]:
        w=False
if  n[0]==0 and N!=1:
    w=False
if  n[0]==-1 and N!=1:
    n[0]=1
if n[0]==-1 and N==1:
    n[0]=0
if N==3:
    if n[1]==-1:
        n[1]=0
    if n[2]==-1:
        n[2]=0
if N==2:
    if n[1]==-1:
        n[1]=0
num=''
for i in n:
    num+=str(i)
if w:
    print(num)
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i]= map(int, input().split())
    
n=[-1]*N
w=True
for i in range(M):
    if n[s[i]-1]==-1:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]==c[i]:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]!=c[i]:
        w=False
if  n[0]==0 and N!=1:
    w=False
if  n[0]==-1 and N!=1:
    n[0]=1
if n[0]==-1 and N==1:
    n[0]=0
if N=3:
    if n[1]==-1:
        n[1]=0
    if n[2]==-1:
        n[2]=0
if N=2:
    if n[1]==-1:
        n[1]=0
num=''
for i in n:
    num+=str(i)
if w:
    print(num)
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i]= map(int, input().split())
    
n=[-1]*N
w=True
for i in range(M):
    if n[s[i]-1]==-1:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]==c[i]:
        n[s[i]-1]=c[i]
    if n[s[i]-1]!=-1 and n[s[i]-1]!=c[i]:
        w=False
if  n[0]==0 and N!=1:
    w=False
if  n[0]==-1 and N!=1:
    n[0]=1
if N>1:
    if n[1]==-1:
        n[1]=0
    if n[2]==-1:
        n[2]=0
num=''
for i in n:
    num+=str(i)
if w:
    print(num)
else:
    print('-1')
Problem p02768 (python)

Fixed submission:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
 
def comb(N, x):
    numerator = 1
    for i in range(N-x+1, N+1):
        numerator = numerator * i % mod
    denominator = 1
    for j in range(1, x+1):
        denominator = denominator * j % mod
    d = pow(denominator, mod-2, mod)
    return numerator * d
 
a = comb(n, a)
b = comb(n, b)
 
print((pow(2, n, mod) -1 -a -b) % mod)

Buggy submission (verdict: Runtime Error):
import math
from operator import mul
from functools import reduce
n, a, b = map(int, input().split())
s=0
mod = pow(10, 9) + 7
def combinations_count(n, r):
    #return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
if n==2:
    print('0')
a=combinations_count(n, a)

b=combinations_count(n, b)
else:
    print((pow(2, n, mod) -1 -a -b) % mod)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
 
 
N, M = map(int, input().split())
 
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = map(int, input().split())
    G[x] += [y]
# print(G)
 
dp = [-1] * (N + 1)
 
 
def func(n):
    if dp[n] != -1:
        return dp[n]
    cnt = 0
	# 先にノードが存在する場合
	# ノードが存在しない場合は、cnt=0のままforをすっ飛ばす
    for m in G[n]:
        cnt = max(cnt, func(m) + 1)
    dp[n] = cnt
    return cnt
 
 
for i in range(1, N + 1):
    func(i)
 
# print(dp)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
 
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = map(int, input().split())
    G[x] += [y]
# print(G)
 
dp = [-1] * (N + 1)
 
 
def func(n):
    if dp[n] != -1:
        return dp[n]
    cnt = 0
	# 先にノードが存在する場合
	# ノードが存在しない場合は、cnt=0のままforをすっ飛ばす
    for m in G[n]:
        cnt = max(cnt, func(m) + 1)
    dp[n] = cnt
    return cnt
 
 
for i in range(1, N + 1):
    func(i)
 
# print(dp)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
 
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = map(int, input().split())
    G[x] += [y]
# print(G)
 
dp = [-1] * (N + 1)
 
 
def func(n):
    if dp[n] != -1:
        return dp[n]
    cnt = 0
	# 先にノードが存在する場合
	# ノードが存在しない場合は、cnt=0のままforをすっ飛ばす
    for m in G[n]:
        cnt = max(cnt, func(m) + 1)
    dp[n] = cnt
    return cnt
 
 
for i in range(1, N + 1):
    func(i)
 # print(dp)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
edge=[[] for j in range(N+1)]
x = [0] * M
y = [0] * M

#N,M=4,5
#x=[1, 1, 3, 2, 3]
#y=[2, 3, 2, 4, 4]
#edge=[[], [2, 3], [4], [2, 4], []]  

for i in range(M):
    x[i], y[i] = map(int, input().split())
    edge[x[i]].append(y[i])
dp=[-1]*(N+1)
def f(x):
    if dp[x]!=-1:
        return dp[x]
    num=0
   
    for i in edge[x]:
        num=max(num,f(i)+1)
    
    dp[x]=num
    return dp[x]
m=0
for i in range(1,N+1):
    m=max(m,f(i))
print(m)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
edge=[[] for j in range(N+1)]
x = [0] * M
y = [0] * M

#N,M=4,5
#x=[1, 1, 3, 2, 3]
#y=[2, 3, 2, 4, 4]
#edge=[[], [2, 3], [4], [2, 4], []]  

for i in range(M):
    x[i], y[i] = map(int, input().split())
    edge[x[i]].append(y[i])
dp=[-1]*(N+1)
def f(x):
    if dp[x]!=-1:
        return dp[x]
    num=0
   
    for i in edge[x]:
        num=max(num,f(i)+1)
    
    dp[x]=num
    return dp[x]
for i in range(1,N+1):
    i,f(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
edge=[[] for j in range(N+1)]
x = [0] * M
y = [0] * M

#N,M=4,5
#x=[1, 1, 3, 2, 3]
#y=[2, 3, 2, 4, 4]
#edge=[[], [2, 3], [4], [2, 4], []]  

for i in range(M):
    x[i], y[i] = map(int, input().split())
    edge[x[i]].append(y[i])
dp=[0]*(N+1)
def f(x):
    if edge[x]==[]:
        return dp[x]
    #num=0
    if edge[x]!=[]:
        num=0
        for i in edge[x]:
            num=max(num,f(i)+1)
        #del edge[x][0]
        dp[x]=max(dp[x],num)
        dp[x]=num
        return dp[x]
for i in range(N):
    f(i+1)
print(max(dp))
Problem p03171 (python)

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

dp=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    dp[i][i]=a[i-1]
for j in range(1,N+1):
    for i in reversed(range(1,N+1)):
        if i>j:
            continue
        if i==j:
            dp[i][j]=a[i-1]
        if i<j:
            dp[i][j]=max(a[i-1]-dp[i+1][j],a[j-1]-dp[i][j-1])
print(dp[1][N])

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

dp=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    dp[i][i]=a[i-1]
for j in range(1,N+1):
    for i in reversed(range(1,N+1)):
        if i>j:
            continue
        if i==j:
            dp[i][j]=a[i-1]
        if i<j:
            dp[i][j]=max(a[i-1]-dp[i+1][j],a[j-1]-dp[i][j-1])
print(dp[1][N]
Problem p03050 (python)

Fixed submission:
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
    if plus == 0:
        break

    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))

Buggy submission (verdict: Runtime Error):
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
        
    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))
Problem p03694 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int.input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))
Problem p02684 (python)

Fixed submission:
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')

MOD =    1000000007
MAX=2147483647
MIN=-2147483648
p=input
l,l1,l2,l3=[],[],[],[]
# for _ in range(o()):
n,k=io()
l=op()
x=y=0
i=0
fr=[0]*(200002)
while 1:
    if fr[l[i]]==0:
        l1.append(l[i])
        fr[l[i]]=1
        i=l[i]-1
    else:
        y=l1.index(l[i])
        x=len(l1)-y
        break
if k<=len(l1):
    print(l1[k-1])
else:
    k-=y
    k%=x
    if k==0:
        k=x
    print(l1[y+k-1])

Buggy submission (verdict: Runtime Error):
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')

MOD =    1000000007
MAX=2147483647
MIN=-2147483648
p=input
l,l1,l2,l3=[],[],[],[]
# for _ in range(o()):
n,k=io()
l=op()
x=y=0
i=0
fr=[0]*(2*(10**5))
while 1:
    if fr[l[i]]==0:
        l1.append(l[i])
        fr[l[i]]=1
        i=l[i]-1
    else:
        y=l1.index(l[i])
        x=len(l1)-y
        break
if k<=len(l1):
    print(l1[k-1])
else:
    k-=y
    k%=x
    print(l1[y+k-1])
Problem p02687 (python)

Fixed submission:
s=input()
if s=="ABC":
    print("ARC")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
s=input()
if s=="ABC":
  print("ARC")
else:
  print("ABC)
Problem p02694 (python)

Fixed submission:
n=int(input())
c=1
x=100
while x<n:
    x=x*(1.01)
    x=int(x)
    c+=1
print(c-1)

Buggy submission (verdict: Runtime Error):
from collections import  *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n=int(input())
c=1
x=100
while 1:
    x=x*(1.01)
    x=int(x)
    if x==n:
        break
    c+=1
print(c)
Problem p02744 (python)

Fixed submission:
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 11):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

print("\n".join(sorted(outs)))

Buggy submission (verdict: Runtime Error):
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 10):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

print("\n".join(sorted(outs)))