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

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

anslist = []

if S < 10**9:
    for i in range(K):
        anslist.append(S)
    for i in range(N-K):
        anslist.append(S+1)
elif S == 10**9:
    for i in range(K):
        anslist.append(S)
    for i in range(N-K):
        anslist.append(1)

ansString = [str(i) for i in anslist]

print(" ".join(ansString))

Buggy submission (verdict: Runtime Error):
import random

N,K,S = map(int,input().split())

limit = 0

if K == 0:
    for i in range(N):
        ramdam = 0
        while(True):
            ramdam = random.randint(1, 10**9)
            if not ramdam == S:
                break
        anslist.append(str(ramdam))
    print(" ".join(anslist))


elif N == K:
    anslist = [str(S) for i in range(N)]
    ansString = " ".join(anslist)
    print(ansString)
    exit()

else:
    if S%2 == 0:
        anslist = [str(S//2) for i in range(K+1)]
        for i in range(N - len(anslist)):
            ramdam = 0
            while(True):
                ramdam = random.randint(1, 10**9)
                if not ramdam == S:
                    break
            anslist.append(str(ramdam))
        print(" ".join(anslist))
    else:
        anslist = []
        t = 1
        for i in range(K-1):
            item = [str(t),str(S-t)]
            anslist.extend(item)
            t += 1
        anslist.append(str(S))
        for i in range(N - len(anslist)):
            ramdam = 0
            while(True):
                ramdam = random.randint(1, 10**9)
                if not ramdam == S:
                    break
            anslist.append(str(ramdam))
        print(" ".join(anslist))

Buggy submission (verdict: Runtime Error):
import random

N,K,S = map(int,input().split())

limit = 0
if N == K:
    anslist = [str(S) for i in range(N)]
    ansString = anslist.join(anslist)
    print(ansString)
    exit()

else:
    if S%2 == 0:
        anslist = [str(S//2) for i in range(K+1)]
        for i in range(N - len(anslist)):
            ramdam = 0
            while(True):
                ramdam = random.randint(1, 10**9)
                if not ramdam == S:
                    break
            anslist.append(str(ramdam))
        print(" ".join(anslist))
    else:
        anslist = []
        t = 1
        for i in range(K-1):
            item = [str(t),str(S-t)]
            anslist.extend(item)
            t += 1
        anslist.append(str(S))
        for i in range(N - len(anslist)):
            ramdam = 0
            while(True):
                ramdam = random.randint(1, 10**9)
                if not ramdam == S:
                    break
            anslist.append(str(ramdam))
        print(" ".join(anslist))
Problem p02802 (python)

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

ac = [0 for i in range(N)]
wa = [0 for i in range(N)]

for i in range(M):
    s = int(ps[i][0])-1
    if ps[i][1] == "WA" and ac[s] == 0:
        wa[s] += 1

    if ps[i][1] == "AC" and ac[s] == 0:
        ac[s] = 1

for i in range(N):
    if ac[i] == 0:
        wa[i] = 0

print(str(sum(ac)) + " " + str(sum(wa)))

Buggy submission (verdict: Runtime Error):
N ,M = map(int, input().split())
ps = [list(input().split()) for i in range(M)]

ac = [0 for i in range(N)]
wa = [0 for i in range(N)]

for i in range(M):
    s = int(ps[i][0])-1
    if ps[i][1] == "WA" and ac[s] == 0:
        wa[s] += 1

    if ps[i][1] == "AC" and ac[s] == 0:
        ac[s] = 1

for i in range(M):
    if ac[i] == 0:
        wa[i] = 0

print(str(sum(ac)) + " " + str(sum(wa)))

Buggy submission (verdict: Runtime Error):
N ,M = map(int, input().split())
ps = [list(input().split()) for i in range(M)]

ac = [0 for i in range(N)]
wa = [0 for i in range(N)]

for i in range(M):
    s = int(ps[i][0])-1
    if ps[i][1] == "WA" and ac[s] == 0:
        wa[s] += 1

    if ps[i][1] == "AC" and ac[s] == 0:
        ac[s] = 1

for i in range(M):
    if ac[i] == 0:
        wa[i] == 0

print(str(sum(ac)) + " " + str(sum(wa)))
Problem p02803 (python)

Fixed submission:
from collections import deque

h,w = map(int, input().split())
l = [list(input()) for _ in range(h)]

# 最大値の格納する
ans = 0

def bfs(y,x,m):#未実装
    #表の初期化
    graph = [[None] * w for i in range(h)]
    #最初の地点のコストは0
    graph[y][x] = 0

    q = deque()
    q.append((y,x))

    for i in range(h):
        for j in range(w):
            if l[i][j] == '#':
                graph[i][j] = -1

    #ノードの移動方向 左が縦軸, 右が横軸
    move = ((0, 1), (0, -1), (1, 0), (-1, 0))

    while q: #wがからになるまで続ける while len(q):でもOK
        #que左端から取り出す
        i, j = q.popleft()

        for di, dj in move:
            #ni, nj 遷移先の座標
            ni , nj = i + di, j + dj
            #遷移先がフィールド内であるか、Noneかどうかをチェックする
            if 0 <= ni < h and 0 <= nj < w and graph[ni][nj] is None:
                #遷移可能であれば現在のコストに1足して渡す
                #print(type(graph[i][j]))
                graph[ni][nj] = graph[i][j] + 1
                #queに格納する
                q.append((ni, nj))

    #queが空になると移動コストtableが完成
    #表中の最大値返す
    return max(max(r) for r in graph)

for i in range(h):
    for j in range(w):
        #'.'であればスタート地点になり得るので、それをbfsにかける
        if l[i][j] == '.':
            d = bfs(i,j,l) # (x, y) = (j, i), lは入力の表の情報
            #返り値が現在の最大値より大きければ値を更新する
            if ans < d:
                ans = d
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = []
for i in range(h):
    a.extend(list(input()))

#print(*a, sep = "\n")

l = h*w
INF = 10**5

dp = [[INF]*(l) for i in range(l)]

for i in range(l):
    if a[i] == "#":
        for j in range(l):
            dp[i][j] = "#"
            dp[j][i] = "#"
            continue

    for j in range(l):
        if i == j:
            dp[i][j] = 0

    #左右上下を1にする
    #右
    if i%w+1 < w:
        dp[i][i+1] = 1
        dp[i+1][i] = 1
    #左
    if i%w-1 > 0:
        dp[i][i-1] = 1
        dp[i-1][i] = 1
    #上
    if i//h-1 > 0:
        dp[i][i-w] = 1
        dp[i-w][i] = 1
    #下
    if i//h+1 < h:
        dp[i][i+w] = 1
        dp[i+w][i] = 1

max = 0
for k in range(l):
    for i in range(l):
        for j in range(l):
            if dp[i][j] == -1:
                continue
            try:
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            except:
                dp[i][j] = dp[i][j]
max = 0
for i in dp:
    for j in i:
        try:
            if max < j:
                max = j
        except:
            pass

#print(*dp, sep="\n")
print(max)
Problem p02811 (python)

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

ans  = 500*A - B

if ans >= 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b: a, b = b, a % b
    return a

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers, N):

    ans = numbers[0]

    for i in range(1,N):
        ans = lcm_base(ans,numbers[i])

    return ans

N ,M = map(int, input().split())
A_n = list(map(int,input().split()))

a_lcm = lcm_list(A_n,N)
ans = 0
interval = a_lcm//2

amari = M // interval

if amari%2 == 1:
    amari = (amari+1)//2
else:
    amari = amari//2
print(amari)
Problem p02911 (python)

Fixed submission:
n,k,q = map(int,input().split())
a_n = [int(input()) for i in range(q)]

p_n = [k-q for i in range(n)]

for a_i in a_n:
    p_n[a_i-1] += 1

[print("Yes") if p_i > 0 else print("No") for p_i in p_n]

Buggy submission (verdict: Runtime Error):
n,k,q = map(int,input().split())
a_n = [int(input()) for i in range(q)]

p_n = [k-q for i in range(n)]

for a_i in a_n:
    p_n[a_i] += 1

[print("Yes") if p_i > 0 else print("No") for p_i in p_n]
Problem p02921 (python)

Fixed submission:
predict = list(input())
result = list(input())

count = 0

for i in range(len(predict)):
    if predict[i] == result[i]:
        count += 1

print(count)

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

amount = 0
count = 0

while amount < list[1]:
    count += 1
    amount = count * (list[0] - 1) + 1 

print(count)
Problem p02923 (python)

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

time = 0
max = 0

def down(i):
    global time
    for j in range(i, number-1):
        if lower[j] >= lower[j+1]:
            time += 1
        else:
            return j+1

    return 0

now = 0
for i in range(len(lower)):

    if now > i:
        continue

    if max > (number-i+1):
        break

    now = down(i)

    if max < time:
        max = time
    time = 0



print(max)

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

time = 0
max = 0

def down(i):
    global max
    global time

    if max > (number-i+1):
        break

    for j in range(i, number-1):
        if lower[j] >= lower[j+1]:
            time += 1
        else:
            return


for i in range(len(lower)):
    down(i)
    if max < time:
        max = time
    time = 0

print(max)

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

time = 0
max = 0

def down(i):
    global max
    global time

    if max > range(i, number):
        return

    for j in range(i, number-1):
        if lower[j] >= lower[j+1]:
            time += 1
        else:
            return


for i in range(len(lower)):
    down(i)
    if max < time:
        max = time
    time = 0

print(max)
Problem p02945 (python)

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

_sum = A + B
_sub = A - B
_mul = A * B

_list = [_sum,_sub,_mul]

print(max(_list))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())

_sum = A + B
_sub = A - B
_mul = A * B

_list = [_sum,_sub,_mul]

print(max(_list))
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(int, input().split())

#正方形なら複数　これも面積半分?
#長方形なら一つ 点対称の線を引けば面積半分にできる

if W/2 == x and H/2 == y:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)

Buggy submission (verdict: Runtime Error):
if W/2 == x and H/2 == y:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)

[n, m] = map(int, input().split())

_map = {}
for i in range(n):
    _map[i+1] = []

for i in range(m):
    [x1, y1] = map(int, input().split())

    _map[y1].append(x1)

_memo = {}

def lpath(vertex):
    if vertex in _memo:
        return _memo[vertex]

    if len(_map[vertex]) == 0:
        return 0
    else:
        _max = 0
        for nv in _map[vertex]:
            # print(nv)
            x = lpath(nv)
            if (x > _max):
                _max = x

        _memo[vertex] = _max + 1
        return _max + 1

global_longest_path = 0
for i in range(n):
    longest_path_to_cur_node = lpath(i + 1)
    if global_longest_path < longest_path_to_cur_node:
        global_longest_path = longest_path_to_cur_node

print(global_longest_path)

Buggy submission (verdict: Runtime Error):
[n, m] = map(int, input().split())

_map = {}
for i in range(n):
    _map[i+1] = []

for i in range(m):
    [x1, y1] = map(int, input().split())

    _map[y1].append(x1)

_memo = {}

def lpath(vertex):
    if vertex in _memo:
        return _memo[vertex]

    if len(_map[vertex]) == 0:
        return 0
    else:
        _max = 0
        for nv in _map[vertex]:
            # print(nv)
            x = lpath(nv)
            if (x > _max):
                _max = x

        _memo[vertex] = _max + 1
        return _max + 1

global_longest_path = 0
for i in range(n):
    longest_path_to_cur_node = lpath(i + 1)
    if global_longest_path < longest_path_to_cur_node:
        global_longest_path = longest_path_to_cur_node

print(global_longest_path)

Buggy submission (verdict: Runtime Error):

[n, m] = map(int, input().split())

_map = {}
for i in range(n):
    _map[i+1] = []

for i in range(m):
    [x1, y1] = map(int, input().split())

    _map[y1].append(x1)

_memo = {}

def lpath(vertex):
    if vertex in _memo:
        return _memo[vertex]

    if len(_map[vertex]) == 0:
        return 0
    else:
        _max = 0
        for nv in _map[vertex]:
            # print(nv)
            x = lpath(nv)
            if (x > _max):
                _max = x

        _memo[vertex] = _max + 1
        return _max + 1

global_longest_path = 0
for i in range(n):
    longest_path_to_cur_node = lpath(i + 1)
    if global_longest_path < longest_path_to_cur_node:
        global_longest_path = longest_path_to_cur_node

print(global_longest_path)
Problem p02696 (python)

Fixed submission:
import math
A,B,N = map(int,input().split())
if B-1>N:
    print(math.floor((A*N)/B)-A*math.floor(N/B))
else:
    print(math.floor((A*(B-1))/B)-A*math.floor((B-1)/B))

Buggy submission (verdict: Runtime Error):
import math as mt
A,B,N = map(int,input().split())
print(math.floor((A*N)/B)-A*math.floor(N/B))

Buggy submission (verdict: Runtime Error):
import math as mt
A,B,N = map(int,input().split())
print(math.floor((A*N)/B)-A*math.floor(N/B)
Problem p02767 (python)

Fixed submission:
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]+1):
    b=0
    for j in range(0,N):
        if i-X[j]>10**5:
            break
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]):
    b=0
    for j in range(0,N):
        if i-X[j]>10**5:
            break
        b+=(i-X[j])**2
    a.append(b)
print(min(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
X = list(map(int,input().split()))
X.sort()
a=list()
c=N-1
for i in range(X[0],X[c]):
    b=0
    for j in range(0,N):
        b+=(i-X[j])**2
    a.append(b)
print(min(a))
Problem p02783 (python)

Fixed submission:
H,A=map(int,input().split())
a=int(H/A)
if H%A!=0:
    a+=1
print(a)

Buggy submission (verdict: Runtime Error):
H=int(input())
A=int(input())
a=int(H/A)
if H%A!=0:
    a+=1
print(a)
Problem p02823 (python)

Fixed submission:
import numpy as np
N,A,B = map(int,input().split())
x=abs(A-B)
    

if x%2==0:
    print(x//2)
else:
    y,z=max(N-A,N-B),max(A-1,B-1)
    a,b=min(A-1,B-1),min(N-A,N-B)
    c,d=max(A-1,B-1)-a,max(N-A,N-B)-b
    e,f=c//2+a+1,d//2+b+1
    if y>z:
        print(min(z,e,f))
    else:
        print(min(y,e,f))

Buggy submission (verdict: Runtime Error):
import numpy as np
while(1):
    N,A,B = map(int,input().split())
    x=abs(A-B)
    

    if x%2==0:
        print(x//2)
    else:
        y,z=max(N-A,N-B),max(A-1,B-1)
        a,b=min(A-1,B-1),min(N-A,N-B)
        c,d=max(A-1,B-1)-a,max(N-A,N-B)-b
        e,f=c//2+a+1,d//2+b+1
        if y>z:
            print(min(z,e,f))
        else:
            print(min(y,e,f))
Problem p02830 (python)

Fixed submission:
N=int(input())
S,T=map(str,input().split())
S,T=list(S),list(T)
x=list("a"*(N*2))
for i in range(0,N*2):
    if i%2==0:
        x[i]=S[i//2]
    else:
        x[i]=T[i//2]
x="".join(x)
print(x)

Buggy submission (verdict: Runtime Error):
N=int(input())
S,T=map(str,input().split())
S,T=list(S),list(T)
print(S[2])
x=list("a"*(N*2))
for i in range(0,N*2):
    if i%2==0:
        x[i]=S[i//2]
    else:
        x[i]=T[i//2]
x="".join(x)
print(x)
Problem p02630 (python)

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

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)

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

l = {}
ans = []
for e in a:
    l[e] = l[e] + 1 if l.get(e) else 1

for _ in range(q):
    b, c = map(int, input().split())
    l[c] = l[c] + l[b] if l.get(c) else l[b]
    del l[b]
    sum = 0
    for k, v in l.items():
        sum += k * v
    ans.append(sum)

for sum in ans:
    print(sum)
Problem p02838 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = [[0, 0] for _ in range(l)]
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i][0] += 1
        else:
            bits[i][1] += 1

sumation = 0
div = (10**9+7)
for i in range(l):
    sumation += (bits[i][0]) * (bits[i][1]) * (2**(l-i-1) % div)
print(int(sumation % (10**9+7)))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = np.zeros((l,2))
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i,0] += 1
        else:
            bits[i,1] += 1

sumation = 0
for i in range(l):
    sumation += bits[i,0] * bits[i, 1] * 2**(l-i-1)
print(int(sumation % (10**9+7)))
Problem p02687 (python)

Fixed submission:
def main():
    N = input()  # 文字列または整数(一変数)

    if N == "ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())  # 文字列または整数(一変数)
    A = list(map(int, input().split()))  # 整数のリスト

    answer = 0

    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if A[j-1] + A[i-1] == abs(j - i):
                answer += 1

    print(answer)

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

Fixed submission:
def main():
    N = int(input())
    a = map(int, input().split())
    d = {i: 0 for i in range(-1, 100001)}

    for i in a:
        d[i-1] += 1
        d[i] += 1
        d[i+1] += 1

    print(max(d.values()))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    a = map(int, input().split())
    d = {i: 0 for i in range(100001)}

    for i in a:
        d[i-1] += 1
        d[i] += 1
        d[i+1] += 1

    print(max(d.values()))

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

Fixed submission:
N = int(input())

import heapq 





def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i,i, cnt])

    if temp!=1:
        arr.append([temp,temp, 1])

    if arr==[]:
        arr.append([n,n,1])

    return arr

# for N in range(1,100000):
# N = 288
# print(N)

heap = factorization(N) 
# print(heap)
# print(heap)
heapq.heapify(heap)
ans = 0

while(heap):
    # print(heap)
    if N == 1:
        break
    sub,prime,cnt = heapq.heappop(heap)
    if N < sub:
        break
    if N % sub == 0:
        N = N // sub
        ans += 1
        if cnt > 0:
            cnt -= 1
            sub *= prime
            heapq.heappush(heap, [sub,prime,cnt])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

import heapq 


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i,i, cnt])

    if temp!=1:
        arr.append([temp,temp, 1])

    if arr==[]:
        arr.append([n,n,1])

    return arr

heap = factorization(N) 
# print(heap)
heapq.heapify(heap)
ans = 0

while(1):
    if N == 1:
        break
    sub,prime,cnt = heapq.heappop(heap)
    if N < sub:
        break
    if N % sub == 0:
        N = N // sub
        ans += 1
        if cnt > 1:
            cnt -= 1
            sub *= prime
            heapq.heappush(heap, [sub,prime,cnt])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

import heapq 
from collections import defaultdict
import numpy as np
import math

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum




if is_prime(N):
    ans = 1
elif N == 1:
    ans = 0
else:
    heap = seachPrimeNum(int(math.sqrt(N)))
    # print(heap)
    heapq.heapify(heap)
    ans = 0
    dict_prime = defaultdict(int)

    while(1):
        # print(N)
        # cnt += 1
        # if cnt > 10:break
        # print(N)
        sub = heapq.heappop(heap)
        # print(sub)
        # print(cand)
        # print(heap)
        # print(cand)
        # print(heapq)
        if N < sub:
            # print(N,sub)
            # print("a")
            break
        if N % sub == 0:
            N = N // sub
            ans += 1
            if sub not in dict_prime:
                dict_prime[sub] = sub
                dict_prime[sub*sub] = sub
            else:
                dict_prime[sub*dict_prime[sub]] = dict_prime[sub]
                # print("a")
            heapq.heappush(heap, sub*dict_prime[sub])


print(ans)
Problem p02684 (python)

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


#一回あたりのループを計算（何回で戻ってくるか）
#ループの箇所を見つける
trace = [0]*N
loop_start = 0
loop_before = 0
cnt = 0
all_cnt = 0

if K > N:
    loop = 0
    now = 0
    while(1):
        # print(trace)
        trace[now] += 1
        if trace[now] == 3:
            break
        if trace[now] == 2:
            cnt += 1
            loop += 1 
            if cnt == 1: 
                loop_start = now
                loop_before = all_cnt
        now = A[now]-1
        all_cnt += 1

    loop_before = loop_before - loop 

    # print(loop)
    # print(loop_start)
    # print(loop_before)
    # print(loop)
    min_K = (K-1-loop_before) % loop
    # print(min_K)
    # print(loop_before)
    now = 0
    for i in range(loop_before):
        now = A[now]-1
    for i in range(min_K):
        now = A[now]-1
    print(A[now])

if K <= N:
    now = 0
    for i in range(K-1):
        now = A[now]-1
    print(A[now])


# print(K % 3)

# print(now+1)

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


#一回あたりのループを計算（何回で戻ってくるか）
#ループの箇所を見つける
trace = [0]*N
loop_start = 0
loop_before = 0
cnt = 0
all_cnt = 0

if K > N:
    loop = 0
    now = 0
    while(1):
        # print(trace)
        trace[now] += 1
        if trace[now] == 3:
            break
        if trace[now] == 2:
            cnt += 1
            loop += 1 
            if cnt == 1: 
                loop_start = now
                loop_before = all_cnt
        now = A[now]-1
        all_cnt += 1

loop_before = loop_before - loop 

# print(loop)
# print(loop_start)
# print(loop_before)
# print(loop)
min_K = (K-1-loop_before) % loop
# print(min_K)
# print(loop_before)
now = 0
for i in range(loop_before):
    now = A[now]-1
for i in range(min_K):
    now = A[now]-1
print(A[now])

# print(K % 3)

# print(now+1)
Problem p02690 (python)

Fixed submission:
X = int(input())

for a in range(-120,120):
    for b in range(-120,120):
        if a**5 - b**5 == X:
            ans_a,ans_b = a,b
            break


print(ans_a,ans_b)

Buggy submission (verdict: Runtime Error):
X = int(input())

for b in range(-100,100):
    is_minus = False
    if (X + b**5) < 0 : is_minus = True
    result = abs((X + b**5))**(1/5)

    if type(result) is complex:
        continue
    if result - round(result) == 0:
        if is_minus:
            ans_a,ans_b = -b,-round(result)
        else:
            ans_a,ans_b = abs(b),-round(result)


print(ans_a,ans_b)

Buggy submission (verdict: Runtime Error):
X = int(input())

for b in range(-100,100):
    result = (X + b**5)**(1/5).real
    if type(result) is complex:
        continue
    if result - round(result) == 0:
        ans_a,ans_b = b,round(result)


print(ans_a,ans_b)