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

Fixed submission:
from bisect import bisect_left
 
n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())
 
LR.sort(key=lambda x: (x[0], x[1]))
L = list(map(lambda x: x[0], LR))
#print(LR)
 
C = [[0]*(n+1) for _ in range(n+1)]
for i in range(1,n+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    #print(l, r, R2)
    for j in range(i,n+1):
        C[i][j] = bisect_left(R2, j+1)
    #print(i, C[i])
 
for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, m, q = map(int, input().split())
LR = [0]*m
for i in range(m):
    LR[i] = list(map(int, input().split()))
P = [0]*q
Q = [0]*q
for i in range(q):
    P[i], Q[i] = map(int, input().split())

LR.sort(key=lambda x: (x[0], x[1]))
L = list(map(lambda x: x[0], LR))
#print(LR)

C = [[0]*(m+1) for _ in range(m+1)]
for i in range(1,m+1):
    l = bisect_left(L, i)
    r = bisect_left(L, i+1)-1
    R2 = list(map(lambda x: x[1], LR[l:r+1]))
    #print(l, r, R2)
    for j in range(i,m+1):
        C[i][j] = bisect_left(R2, j+1)
    #print(i, C[i])

for i in range(q):
    ans = 0
    for j in range(P[i], Q[i]+1):
        ans += C[j][Q[i]]
    print(ans)
Problem p03297 (python)

Fixed submission:
from fractions import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
from math import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')
Problem p03323 (python)

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

if a > b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2 * a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':(')

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

if a < b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':')

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

if a < b:
    tmp = a
    a = b
    b = tmp

r = 16 - 2a
b = b - a

if r // 2 >= b:
    print('Yay!')
else:
    print(':')
Problem p03331 (python)

Fixed submission:
N = int(input())

def digit_sum(X):
    s = 0
    while(X > 0):
        s += X % 10
        X = int(X / 10)
    return s

min_ = 10 ** 5
for A in range(1, int(N/2)+1):
    B = N - A
    val = digit_sum(A) + digit_sum(B)
    min_ = min(min_, val)

print(min_)

Buggy submission (verdict: Runtime Error):
N, A, B, K = map(int, input().split())
M = 998244353

X = set()
for n in range(0, K//A+1):
    m = (K - n * A) // B
    if n <= N and m <= N and n * A + m * B == K:
        X.add((n, m))

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

ans = 0
for n, m in X:
    ans += comb[n] * comb[m]
    ans = ans % M
print(ans)
Problem p03341 (python)

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

from collections import defaultdict
wc = defaultdict(int)
ec = defaultdict(int)

if S[0] == 'W':
    wc[0] = 1
for i in range(1, N):
    wc[i] = wc[i-1]
    if S[i] == 'W':
        wc[i] += 1

if S[N-1] == 'E':
    ec[N-1] = 1
for i in range(N-2, -1, -1):
    ec[i] = ec[i+1]
    if S[i] == 'E':
        ec[i] += 1

min_ = N
for i in range(1, N-1):
    v = wc[i-1] + ec[i+1]
    if v < min_:
        min_ = v
v0 = ec[1]
if v0 < min_:
    min_ = v0
vn = wc[N-1]
if vn < min_:
    min_ = vn
print(min_)

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

answer = N
mark = 0
for i in range(N-1):
    #print('%d, %d, %d' % (i, mark, answer))
    if i < mark:
        answer += mark - i
        v = A[i]
        for x in range(i+1, mark+1):
            v += A[x]
        start_j = mark + 1
    else:
        v = A[i]
        start_j = i + 1
    for j in range(start_j, N):
        vx = v ^ A[j]
        vp = v + A[j]
        if vx == vp:
            answer += 1
            v = vx
            mark = j
        else:
            break
print(answer)

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

answer = N
for i in range(N-1):
    v = A[i]
    for j in range(i+1, N):
        vx = v ^ A[j]
        vp = v + A[j]
        if vx == vp:
            answer += 1
            v = vx
        else:
            break
print(answer)
Problem p02705 (python)

Fixed submission:
import math 

R = int(input())

circle_pond = 2*R*math.pi
print(circle_pond)

Buggy submission (verdict: Runtime Error):
import math 

R = int(input())

pai = 3.1415926535

circle_pond = 2*R*math.pai
print(circle_pond)
Problem p02811 (python)

Fixed submission:
inp = input()
arr = [int(i) for i in inp.split() if i.isdigit()]
total = arr[0]*500
if total >= arr[1]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
coin = int(input())
Max = int(input())
total = coin*500
if total >= Max:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
coin = int(input())
max = int(input())
total = coin*500
if total >= max:
    print("Yes")
else:
    print("No")
Problem p02630 (python)

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

heavy = [0] * (10 ** 5 + 1)
for x in A:
    heavy[x] += 1
suma = sum(A)

for i in range(Q):
    B, C = map(int, input().split())
    suma -= B * heavy[B]
    suma += C * heavy[B]
    heavy[C] += heavy[B]
    heavy[B] = 0
    print(suma)

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

val = []
heavy = []

for x in A:
    if x in heavy:
        val[heavy.index(x)] += 1
    else:
        heavy.append(x)
        val.append(1)

for i in range(Q):
    B, C = input().split()
    B = int(B)
    C = int(C)
    if C not in heavy:
        heavy.append(C)
        val.append(0)
    val[heavy.index(C)] += val[heavy.index(B)]
    val[heavy.index(B)] = 0
    sum = 0
    for x, y in zip(val, heavy):
        sum += x * y
    print(sum)
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
p = [int(i) for i in input().split()]

min = 1000
pre_i = 0
for i in range(102):
    if i in p:
        continue
    if min > abs(x - i):
        min = abs(x - i)
    else:
        break
    pre_i = i

print(pre_i)

Buggy submission (verdict: Runtime Error):
import sys
x, n = map(int, input().split())

if n > 0:
    p_list = [int(i) for i in input().split()]
else:
    print(x)
    sys.exit(0)

table = {i for i in range(1, 101)}
table = list(table - set(p_list))
diff = 0
d_min = 101
pre_i = table[0]

for i in table:
    diff = abs(x - i)
    if d_min > diff:
        d_min = diff
    else:
        break
    pre_i = i

print(pre_i)

Buggy submission (verdict: Runtime Error):
import sys
x, n = map(int, input().split())

if n > 0:
    p_list = [int(i) for i in input().split()]
else:
    print(x)
    sys.exit(0)

table = {i for i in range(101)}
table = table - set(p_list)
diff = 0
d_min = 100

for i in table:
    diff = abs(x - i)
    if d_min > diff:
        d_min = diff
    else:
        break
    pre_i = i

print(pre_i)
Problem p02999 (python)

Fixed submission:
X, A = list(map(int, input().split()))
if X < A :
	print(0)
else :
	print(10)

Buggy submission (verdict: Runtime Error):
X, A = list(map(input().split()))
if X < A :
	print(0)
else :
	print(10)
Problem p03085 (python)

Fixed submission:
b = str(input())
if b == "A" : print("T")
elif b == "T" : print("A")
elif b == "C" : print("G")
else : print("C")

Buggy submission (verdict: Runtime Error):
if input() == "A" : print("T")
elif input() == "T" : print("A")
elif input() == "C" : print("G")
else : print("C")
Problem p03635 (python)

Fixed submission:
n, m = list(map(int, input().split()))
print((n - 1) * (m - 1))

Buggy submission (verdict: Runtime Error):
print((int(input()) - 1) * (int(input()) - 1))

Buggy submission (verdict: Runtime Error):
print(int(input() - 1) * int(input() - 1))
Problem p03844 (python)

Fixed submission:
A, op, B = input().split()
if str(op) == "+" :
  print(int(A) + int(B))
else :
  print(int(A) - int(B))

Buggy submission (verdict: Runtime Error):
A, op, B = intput().split()
if str(op) == "+" :
  print(int(A) + int(B))
else :
  print(int(A) - int(B))
Problem p03852 (python)

Fixed submission:
c = str(input())
if c == "a" or c == "e" or c == "i" or c == "o" or c == "u" :
  print("vowel")
else :
  print("consonant")

Buggy submission (verdict: Runtime Error):
c = str(intput())
if c == "a" or c == "e" or c == "i" or c == "o" or c == "u" :
  print("vowel")
else :
  print("consonant")
Problem p02717 (python)

Fixed submission:
X, Y, Z = map(int, input().split())
print(Z, X, Y)

Buggy submission (verdict: Runtime Error):
import numpy as np
import pandas as pd

X, Y, Z = map(int, input().split())
print(Z, X, Y)

Buggy submission (verdict: Runtime Error):
import numpy as np
import pandas as pd

X, Y, Z = map(int, input().split())
print(Z, X, Y)
Problem p02761 (python)

Fixed submission:
import numpy as np

N, M = list(map(int, input().split()))
s = [0]*M
c = [0]*M
check = 1
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))
    if ((N > 2) & (s[i] == 1) & (c[i] == 0)):
        check = 0

if check == 0:
    print('-1')
else:
    if N > 1:
        max = 10 ** N - 1
        min = 10 ** (N - 1)
    else:
        max = 9
        min = 0

    answer = -1

    for i in range(max, min-1, -1):
        flag = 1
        for j in range(M):
            if s[j] <= N:
                if int(str(i)[s[j]-1]) != c[j]:
                    flag = 0
        if flag == 1:
            answer = i
    print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = list(map(int, input().split()))
s = [0]*M
c = [0]*M
check = 1
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))
    if ((N > 2) & (s[i] == 1) & (c[i] == 0)):
        check = 0

if check == 0:
    print('-1')
else:
    max = 10 ** N - 1
    #print(max)

    smax = np.max(s)
    if smax != 1:
        min = 10 ** (smax - 1)
    else:
        min = 0
    #print(min)

    answer = -1

    for i in range(max, min-1, -1):
        flag = 1
        for j in range(M):
            if s[j] <= N:
                if int(str(i)[s[j]-1]) != c[j]:
                    flag = 0
        if flag == 1:
            answer = i
    print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = list(map(int, input().split()))
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))

max = 10 ** N - 1

smax = np.max(s)
if smax != 1:
    min = 10 ** (smax - 1)
else:
    min = 0

answer = -1
for i in range(max, min-1, -1):
    flag = 1
    for j in range(M):
        if int(str(i)[s[j]-1]) != c[j]:
            flag = 0
    if flag == 1:
        answer = i
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = list(map(int, input().split()))
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))

max = 10 ** N - 1

smax = np.max(s)
min = 10 ** (smax - 1)

answer = -1
for i in range(max, min-1, -1):
    flag = 1
    for j in range(M):
        if int(str(i)[s[j]-1]) != c[j]:
            flag = 0
    if flag == 1:
        answer = i
print(answer)
Problem p02971 (python)

Fixed submission:
import numpy as np
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

tmp = copy.deepcopy(A)
tmp = list(sorted(A, reverse=True))

Amax = tmp[0]
Asecond = tmp[1]

for i in range(N):
    if A[i] != Amax:
        print(Amax)
    else:
        print(Asecond)

Buggy submission (verdict: Runtime Error):
import numpy as np
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

tmp = copy.deepcopy(A)
tmp = list(sorted(A, reverse=True))

Amax = tmp[0]
Asecond = tmp[1]

for i in range(N):
    if A[i] != Amax:
        print(Amax)
    else:
        print(Asecond)

Buggy submission (verdict: Runtime Error):
import numpy as np
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

for i in range(N):
    tmp = A[i]
    A[i] = 0
    print(np.max(A))
    A[i] = tmp
Problem p02995 (python)

Fixed submission:
import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

A, B,C,D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))

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

large = np.max([C, D])
small = np.min([C, D])
quo = large // small
rem = large % small
g = small
while rem != 0:
    large = small 
    small = rem
    quo = large // small
    rem = large % small

g = small
#print(g)

l = C / g * D

#num_B_1 = math.floor(B / C)
#num_B_2 = math.floor(B / D)
#num_B_3 = math.floor(B / l)
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

#num_A_1 = math.floor((A - 1) / C)
#num_A_2 = math.floor((A - 1) / D)
#num_A_3 = math.floor((A - 1) / l)
num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = ((A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)
Problem p03037 (python)

Fixed submission:
import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]

Rmin = np.min(R)
Lmax = np.max(L)
if Rmin >= Lmax:
    num = np.min(R) - np.max(L) + 1
else:
    num = 0
print(num)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]

Rmin = np.min(R)
Lmax = np.max(L)
if Rmin >= Lmax:
    num = np.min(R) - np.max(L) + 1
else
    num = 0
print(num)
Problem p03407 (python)

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


have_money = a + b

print( "Yes" if( have_money >= c ) else "No" )

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

have_money = a + b*2

print( "Yes" if( have_money >= C ) else "No" )
Problem p03563 (python)

Fixed submission:
x, y = int(input()), int(input())
print( (y - x)*2 + x )

Buggy submission (verdict: Runtime Error):
#include<stdio.h>

int main( void )
{
    int r, g;
    scanf("%d", &r);
    scanf("%d", &g);

    printf("%d\n", r + (g-r)*2);
    return 0;
}
Problem p03609 (python)

Fixed submission:
(a,b)=list(map(int,input().split()))
print( a-b if( a > b ) else 0 )

Buggy submission (verdict: Runtime Error):
(a,b)=list(map(int,input()));print( a-b if( a > b ) else 0 )
Problem p02612 (python)

Fixed submission:
N = int(input()) # yen

number_of_bills = int(N / 1000)
change = number_of_bills*1000 - N
if change < 0:
    change += 1000
print(str(int(change)))

Buggy submission (verdict: Runtime Error):
import math
import tensorflow as tf
N = int(input()) # yen

number_of_bills = N / 1000
change = number_of_bills*1000 - N
if change < 0:
    change += 1000
print(str(int(change)))

Buggy submission (verdict: Runtime Error):

N = int(input()) # yen

number_of_bills = ceil(N / 1000)
change = number_of_bills*1000 - N
print(str(change), flush=True)
Problem p02612 (python)

Fixed submission:
n = int(input())
a = n%1000
if a == 0:
  print(0)
else:
  print(1000 - a)

Buggy submission (verdict: Runtime Error):
n = input()
a = n%1000
if a == 1000:
  print(0)
else:
  print(a)
Problem p02640 (python)

Fixed submission:
x,y = map(int,input().split())
kame=(y//2)-x
if y%2!=0:
    print("No")
elif (kame>=0)&(kame<=x):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def abc2(x,y):
    if y%2!=0:
        return print("No")
    kame = (y//2)-x
    if (kame>=0)&(kame<=x):
        return print("Yes")
    else:
        return print("No")
x,y = map(int,input().split())
abs2(x,y)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
ans = 'No'
    for a in range(X + 1):
        b = X - a
        if 2 * a + 4 * b == Y:
            ans = 'Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
ans = 'No'
    for a in range(X + 1):
        b = X - a
        if 2 * a + 4 * b == Y:
        ans = 'Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
if y%2!=0:
    print("No")
kame=(y//2)-x
tsuru = (-y//2)+2x
if kame + tsuru == x:
    print("Yes")
else:
    print("No")
Problem p02812 (python)

Fixed submission:
N = int(input())
S = input()
S = list(S)
count = 0
for i in range(N-2):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count+=1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)
count = 0
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count+=1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)
count = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count = count+1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)
count = 0
for i in range(len(S)):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                count = count+1
print(count)
Problem p02612 (python)

Fixed submission:
N = int(input())
print((1000 - N % 1000) % 1000 )

Buggy submission (verdict: Runtime Error):
N = int(input())
thousand = 1000*M
thousand - N < 1000
print(M)
Problem p02612 (python)

Fixed submission:
N = int(input())
if N % 1000 == 0:
  print(0)
else:
  k = int(N/1000) + 1
  print(1000*k - N)

Buggy submission (verdict: Runtime Error):
N = int(input())
if k % 1000 == 0:
  print(0)
else:
  
	k = int(N/1000) + 1
    print(1000*k - N)
Problem p02618 (python)

Fixed submission:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]
    for i in range(d):
        print(s[i].index(max(s[i])) + 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from random import randint

    def score(t):
        memo = [0] * 26
        ans = 0
        for i, tt in enumerate(t):
            ans += s[i][tt - 1]
            memo[tt - 1] = i + 1
            for m, cc in zip(memo, c):
                ans -= cc * (i + 1 - m)
        return ans

    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]
    t = [0] * d
    r = [0] * d
    check = 0
    for i in range(d):
        t[i] = s[i].index(max(s[i])) + 1
        check = score(t)
    for i in range(10 ** 4):
        for j in range(d):
            r[j] = randint(1, d)
        if check < score(r):
            t = r
    print('\n'.join(map(str, t)))


if __name__ == '__main__':
    main()
Problem p02683 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n, m, x = map(int, readline().split())
ca = [list(map(int, readline().split())) for _ in range(n)]
ans = float('inf')
for bit in product([0, 1], repeat=n):
    cnt = 0
    memo = [0] * m
    for i in range(n):
        if bit[i] == 1:
            cnt += ca[i][0]
            for j in range(m):
                memo[j] += ca[i][j + 1]
    for j in range(m):
        if memo[j] < x:
            break
    else:
        ans = min(ans, cnt)
if ans == float('inf'):
    ans = -1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n, m, x = map(int, readline().split())
ca = [list(map(int, readline().split())) for _ in range(n)]
ans = float('inf')
for bit in product([0, 1], repeat=n):
    cnt = 0
    memo = [0] * n
    for i in range(n):
        if bit[i] == 1:
            cnt += ca[i][0]
            for j in range(m):
                memo[j] += ca[i][j + 1]
    for j in range(m):
        if memo[j] < x:
            break
    else:
        ans = min(ans, cnt)
if ans == float('inf'):
    ans = -1
print(ans)
Problem p02684 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
a = list(map(int, readline().split()))
dict = [-1] * (n + 1)
now = a[0]
dict[0] = 0
for i in range(1, n * 2):
    if i == k:
        print(now)
        exit()
    now = a[now - 1]
    if dict[now] != -1:
        k -= (i + 1)
        k %= (i - dict[now])
        break
    else:
        dict[now] = i
for i in range(k):
    now = a[now - 1]
print(now)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
a = list(map(int, readline().split()))
roop = 0
dict = [False] * n
now = a[0]
for i in range(n + 1):
    if i + 1 == k:
        print(a[now - 1])
        exit()
    now = a[now - 1]
    if dict[now - 1]:
        k -= (i + 1)
        dict = [False] * n
        dict[now - 1] = True
        check = a[now - 1]
        for j in range(n + 1):
            print(dict)
            now = a[now - 1]
            if dict[now - 1]:
                k %= (j + 1)
                k += 1
                break
            else:
                dict[now - 1] = True
        break
    else:
        dict[now - 1] = True
now = check
for i in range(k):
    now = a[now - 1]
print(now)