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

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

if m*k == 1:
    print(-1)
    exit()

if 1 << m <= k:
    print(-1)
    exit()

if k == 0:
    t = []
    for i in range(1 << m):
        for _ in range(2):
            t.append(i)
    print(*t)
    exit()

b = []
for i in range(1 << m):
    if i != k:
        b.append(i)

c = b[::-1]

a = b + [k] + c + [k]
print(*a)

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

u = [0, 2, 3, 0, 1, 3, 2, 1]
x = 2**m
a = []
if k == 0:
    for i in range(x):
        a.append(i)
        a.append(i)
    print(*a)
    exit()

if x % (2 * k) != 0:
    print(-1)
    exit()

check = [False] * x
t = 0

while t < x:
    y = []
    for _ in range(2):
        while t < x:
            if check[t]:
                t += 1
            else:
                break
        if t >= x:
            break
        if t ^ k >= x:
            break
        if check[t ^ x]:
            break
        check[t] = True
        check[t ^ k] = True
        y.append(t)
        y.append(t ^ k)

    if len(y) != 4:
        break
    for r in u:
        a.append(y[r])

if len(a) == 2 * x:
    print(*a)
else:
    print(-1)
Problem p03085 (python)

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

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

Fixed submission:
from bisect import bisect_left, bisect_right
a, b, q = map(int, input().split())
inf = 10**18
shrine = [-inf] + [int(input()) for _ in range(a)] + [inf]
temple = [-inf] + [int(input()) for _ in range(b)] + [inf]

for _ in range(q):
    ans = inf
    x = int(input())
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        s = shrine[i]
        i_t = index_t
        t0, t1 = temple[i_t-1], temple[i_t]
        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )

    for i in range(index_t-1, index_t+1):
        t = temple[i]
        i_s = index_s
        s0 = shrine[i_s - 1]
        s1 = shrine[i_s]
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
a, b, q = map(int, input().split())
shrine = [int(input()) for _ in range(a)]
temple = [int(input()) for _ in range(b)]

inf = 10**18
for _ in range(q):
    ans = inf
    x = int(input())
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        if i == a:
            continue
        s = shrine[i]
        i_t = bisect_left(temple, s)

        if i_t == 0:
            t0 = inf
        else:
            t0 = temple[i_t - 1]
        if i_t <= b:
            t1 = temple[i_t]
        else:
            t1 = inf

        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )
    for i in range(index_t-1, index_t+1):
        if i == b or i < 0:
            continue
        t = temple[i]
        i_s = bisect_left(shrine, t)
        if i_s == 0:
            s0 = inf
        else:
            s0 = shrine[i_s - 1]

        if i_s <= a-1:
            s1 = shrine[i_s]
        else:
            s1 = inf
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)
Problem p03160 (python)

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros(N+1, dtype=int)
dp[2] = abs(h[0]-h[1])
for i in range(2, N):
    dp[i+1] = min(
        dp[i] + abs(h[i-1]-h[i]),
        dp[i-1] + abs(h[i-2]-h[i])
    )
print(dp[N])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
n = int(input())
inf = 10**10
h = list(map(int, input().split()))


@lru_cache(maxsize=None)
def dp(i):
    if i == 0:
        return 0
    if i == 1:
        return dp(i-1) + abs(h[i] - h[i-1])
    if i >= 2:
        return min(dp(i-2) + abs(h[i] - h[i-2]), dp(i-1) + abs(h[i] - h[i-1]))


print(dp(n-1))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
n = int(input())
inf = 10**10
h = list(map(int, input().split())) + [inf] * 10


@lru_cache(maxsize=None)
def dp(i):
    if i == 0:
        return 0
    if i >= 2:
        return min(dp(i-2) + abs(h[i] - h[i-2]), dp(i-1) + abs(h[i] - h[i-1]))
    if i == 1:
        return dp(i-1) + abs(h[i] - h[i-1])


print(dp(n-1))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
n = int(input())
inf = 10**10
h = list(map(int, input().split())) + [inf] * 10


@lru_cache
def dp(i):
    if i == 0:
        return 0
    if i >= 2:
        return min(dp(i-2) + abs(h[i] - h[i-2]), dp(i-1) + abs(h[i] - h[i-1]))
    if i == 1:
        return dp(i-1) + abs(h[i] - h[i-1])


print(dp(n-1))
Problem p03161 (python)

Fixed submission:
N, K= map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(N+1)
for i in range(1, N):
    dp[i+1] = min(
        [
            abs(h[i]-h[i-k]) + dp[i+1-k]
            for k in range(1, min(K, i)+1)
        ]
    )
print(dp[N])

Buggy submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros((N+1, K+1), dtype=int)
for i in range(1, N):
    for k in range(1, K+1):
        if i >= k:
            dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k][1:K + 1])
        else:
            w = i
            dp[i+1][k] = dp[i+1][k-1]
print(min(dp[N][1:K+1]))

Buggy submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k >= 0:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))

Buggy submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k >= 0:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k])
        k += 1
print(int(min(dp[N])))

Buggy submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.full((N+1, K+1), np.inf, dtype=float)
dp[1] = np.zeros(K+1)
for i in range(1, N):
    k = 1
    while i >= k:
        dp[i+1][k] = abs(h[i] - h[i - k]) + min(dp[i + 1 - k][1:K + 1])
        k += 1
print(int(min(dp[N][1:K+1])))

Buggy submission (verdict: Runtime Error):
N, K= map(int, input().split())
h = list(map(int, input().split()))
import numpy as np
dp = np.zeros(N+1, dtype=int)
for i in range(1, N):
    if i >= k:
        dp[i+1] = min(
            [
                abs(h[i]-h[i-k]) + dp[i+1-k]
                for k in range(1, K+1)
            ]
        )
    else:
        dp[i + 1] = min(
            [
                abs(h[i] - h[i - k]) + dp[i + 1 - k]
                for k in range(1, i + 1)
            ]
        )
print(dp[N])
Problem p03164 (python)

Fixed submission:
n, w = map(int, input().split())

inf = 10 ** 10
dp = [[inf] * (10**5+3) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    weight, value = map(int, input().split())
    for j in range(10**5 + 3):
        if j - value >= 0:
            dp[i+1][j] = min(
                dp[i][j - value] + weight,
                dp[i][j]
            )
        else:
            dp[i+1][j] = dp[i][j]
for i in reversed(range(10**5+3)):
    if dp[n][i] <= w:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros((n+1, W+1), dtype=int)

for i in range(n):
    dp[i+1][:wv[i][0]] = dp[i][:wv[i][0]]
    dp[i+1][wv[i][0]:] = np.maximum(dp[i][:-wv[i][0]] + wv[i][1], dp[i][wv[i][0]:])
print(dp[n][W])

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

dp = [[0]*(N+1) for w in range(W+1)]
for w in range(1, W+1):
    for i in range(N):
        if w - item[i][0] >= 0:
            dp[w][i+1] = max(
                dp[w][i],
                dp[w-item[i][0]][i] + item[i][1]
            )
        else:
            dp[w][i+1] = dp[w][i]
print((dp[N][W]))

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

dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    for w in range(1, W+1):
        if w - item[i][0] >= 0:
            dp[i+1][w] = max(
                dp[i][w],
                dp[i][w-item[i][0]] + item[i][1]
            )
        else:
            dp[i+1][w] = dp[i][w]
print((dp[N][W]))
Problem p03353 (python)

Fixed submission:
S = input()
n = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, i+k+1):
                ans.add(S[i:j])
    cnt += len(ans)
    if cnt >= k:
        break
    else:
        ans.clear()

ans = list(ans)
ans.sort()
index = k - 1 - (cnt - len(ans))
print(ans[index])

Buggy submission (verdict: Runtime Error):
S = input()
n = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, n+1):
                ans.add(S[i:j])
                cnt += 1
                if cnt == k:
                    break

    ans.clear()

ans = list(ans)
ans.sort()
index = k - 1 - (cnt - len(ans))
print(ans[index])
Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())
mass = [list(input()) for _ in range(h)]

ans = "Yes"
for i in range(h):
    for j in range(w):
        if mass[i][j] == "#":
            if i < h-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < w-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

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

ans = "Yes"
for i in range(h):
    for j in range(w):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

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

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)

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

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

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

ans = "Yes"
for i in range(w):
    for j in range(h):
        if mass[i][j] == "#":
            if i < w-1:
                if mass[i+1][j] == "#":
                    continue
            if 0 < i:
                if mass[i-1][j] == "#":
                    continue
            if j < h-1:
                if mass[i][j+1] == "#":
                    continue
            if 0 < j:
                if mass[i][j-1] == "#":
                    continue
            ans = "No"
            break

print(ans)
Problem p03425 (python)

Fixed submission:
from collections import Counter
march = "MARCH"
n = int(input())
initial = Counter([input()[0] for _ in range(n)])
ans = []
for i, num in initial.items():
    if i in march:
        ans.append(num)

x = len(ans)
if x < 3:
    print(0)
elif x >= 3:
    y = 0
    for i in range(0, x-2):
        for j in range(i+1, x-1):
            for k in range(j+1, x):
                y += ans[i] * ans[j] * ans[k]
    print(y)

Buggy submission (verdict: Runtime Error):
from collections import Counter
march = "MARCH"
n = int(input())
initial = Counter([input()[0] for _ in range(n)])
ans = []
for i, num in initial.items():
    if i in march:
        ans.append(num)

x = len(ans)
if x < 3:
    print(0)
elif x >= 3:
    y = 0
    for i in range(1, x-1):
        for j in range(i+1, x):
            for k in range(j+1, x+1):
                y += ans[i] * ans[j] * ans[k]
    print(y)
Problem p03471 (python)

Fixed submission:
import sys
n, price = map(int, input().split())
ans = [-1, -1, -1]
for x in range(n+1):
    for y in range(n+1):
        z = n - x - y
        if z < 0:
            continue
        if 10000 * x + 5000 * y + 1000 * z == price:
            ans = [x, y, z]
            print(*ans)
            sys.exit()
print(*ans)

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


def calc(a, b, c):
    return 10000 * a + 5000 * b + 1000 * c


def dfs(pos, a, b, c):
    if pos == n:
        if calc(a, b, c) == y:
            return [a, b, c]
        else:
            return [-1, -1, -1]
    ret1 = [
        dfs(pos+1, a+1, b, c),
        dfs(pos+1, a, b+1, c),
        dfs(pos+1, a, b, c+1)
        ]
    ret1.sort(key=lambda x: x[0])
    return ret1[-1]


print(*dfs(0, 0, 0, 0))
Problem p03504 (python)

Fixed submission:
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = 10**5+1
record = [[0]*(T+3) for _ in range(c+1)]
channel = [[] for _ in range(c+1)]
stc.sort()

for s, t, c in stc:
    if not channel[c]:
        channel[c].append([s - 1, t])
        continue
    if channel[c][-1][1] == s:
        channel[c][-1][1] = t
    else:
        channel[c].append([s-1, t])

for i, v in enumerate(channel):
    for s, t in v:
        record[i][s] += 1
        record[i][t] -= 1

for i in record:
    for j in range(T+2):
        i[j+1] += i[j]

ans = 0
for i in range(T+2):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)

Buggy submission (verdict: Runtime Error):
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = max(stc, key=lambda x:x[1])[1]
record = [[0]*(T+2) for _ in range(c+1)]
for s, t, c in stc:
    record[c][s] += 1
    record[c][t] -= 1

for r in record:
    for i in range(T+3):
        r[i+1] += r[i]

for s, t, c in stc:
    record[c][s-1] += 1

ans = 0
for i in range(T+3):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)
Problem p03611 (python)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
cnt = sorted(x.items(), key=lambda x: x[0], reverse=True)
ans = 0
for i in range(len(cnt)):
    x = cnt[i][1]
    if i != 0:
        if cnt[i][0] == cnt[i-1][0] - 1:
            x += cnt[i-1][1]
    if i != len(cnt) - 1:
        if cnt[i][0] == cnt[i+1][0] + 1:
            x += cnt[i+1][1]
    ans = max(ans, x)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
cnt = sorted(x.items(), key=lambda x: x[0], reverse=True)
ans = 0
for i in range(len(cnt)):
    x = cnt[i][1]
    print(x)
    if i != 0:
        if cnt[i][0] == cnt[i-1][0] - 1:
            x += cnt[i-1][1]
    if i == len(cnt) - 1:
        if cnt[i][0] == cnt[i+1][0] + 1:
            x += cnt[i+1][1]
    ans = max(ans, x)
print(ans)
Problem p03946 (python)

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

ans = []
min_a = a[0]
for i in range(1, n):
    min_a = min(min_a, a[i-1])
    ans.append(a[i] - min_a)
r = max(ans)
print(ans.count(r))

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

ans = []
for i in range(n):
    b = max(a[i+1:]) - a[i]
    ans.append(b)

r = max(ans)
print(ans.count(r))
Problem p04045 (python)

Fixed submission:
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n))
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


if dfs(0, 0) != inf:
    print(dfs(0, 0))
else:
    stop += 1
    print(dfs(0, 0))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)

for i in num:
    if i >= int(str(n)[0]):
        ans = i
        break


def dfs(pos, x):
    if pos == len(str(n)):
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


print(dfs(1, ans))
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()

count = x.count("1")

mod1 = 0 # 1少ない
mod2 = 0 # 1多い

#　初回の各桁のbitを反転させた場合のmod結果を格納するリスト
mod1_list = [0]*n
mod2_list = [0]*n

now1 = 1

x = x[::-1]

# mod1の計算
for i in range(n):
    mod1_list[i] = now1
    if x[i] == "1":
        mod1 += now1%(count+1)
    now1 *= 2
    now1 %= (count+1)

mod1 %= (count+1)

now2 = 1

# mod2の計算
if count >= 3:
    for i in range(n):
        mod2_list[i] = now2
        if x[i] == "1":
            mod2 += now2%(count-1)
        now2 *= 2
        now2 %= (count-1)
    
    mod2 %= (count-1)

mod1_list = mod1_list[::-1]
mod2_list = mod2_list[::-1]
x = x[::-1]

for i in range(n):
    total = 1
    if x[i] == "1":
        if count == 1:
            print(0)
            continue
        elif count == 2:
            print(1)
            continue
        now = mod2-mod2_list[i]
        now %= (count-1)
    else:
        now = mod1+mod1_list[i]
        now %= (count+1)

    while now != 0:
        now = now%(bin(now).count("1"))
        total += 1

    print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()

count = x.count("1")

mod1 = 0 # 1少ない
mod2 = 0 # 1多い

#　初回の各桁のbitを反転させた場合のmod結果を格納するリスト
mod1_list = [0]*n
mod2_list = [0]*n

now1 = 1

x = x[::-1]

# mod1の計算
for i in range(n):
    mod1_list[i] = now1
    if x[i] == "1":
        mod1 += now1%(count+1)
    now1 *= 2
    now1 %= (count+1)

mod1 %= (count+1)

now2 = 1

# mod2の計算
if count >= 3:
    for i in range(n):
        mod2_list[i] = now2
        if x[i] == "1":
            mod2 += now2%(count-1)
        now2 *= 2
        now2 %= (count-1)
    
    mod2 %= (count-1)

mod1_list = mod1_list[::-1]
mod2_list = mod2_list[::-1]
x = x[::-1]

for i in range(n):
    total = 1
    if x[i] == "1":
        now = mod2-mod2_list[i]
        now %= (count-1)
    else:
        now = mod1+mod1_list[i]
        now %= (count+1)
        
    while now != 0:
        now = now%(bin(now).count("1"))
        total += 1

    print(total)
Problem p02631 (python)

Fixed submission:
import numpy as np

n = int(input())
a = list(map(int,input().split()))
now = 0
for i in a:
    now ^= i
li = []
for i in a:
    li.append(i^now)

print(*li)

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

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
b = [((a>>i)&1).sum() for i in range(21)]
li = []
for i in a:
    c = np.array([((i>>j)&1) for j in range(21)],dtype=np.int64)
    d = b-c
    point = 0
    for i in range(31):
        if d[i]%2 == 1:
            point += 2**(i)
    li.append(point)

print(*li)
Problem p02645 (python)

Fixed submission:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from copy import deepcopy

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*(n+1)

if k > 41:
    k = 41

for _ in range(k):
    b = [0]*(n+1)
    for i,j in enumerate(a):
        b[max(0,i-j)] += 1
        b[min(n,i+j+1)] -= 1
    a = list(accumulate(b))
    for i in range(n+1):
        if a[i] >= n:
            a[i] = n

print(*a[:-1])
Problem p02684 (python)

Fixed submission:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
a = [0]+a
bunki = 0
now = a[1]
lip = [1]
se = set()
while True:
    bunki += 1
    if now in se:
        break
    se.add(now)
    lip.append(now)
    now = a[now]

tenki = lip.index(now)
lis = lip[tenki:]
roop = bunki-tenki

if k < tenki: 
    print(lip[k])
    exit()
k -= tenki

print(lis[k%roop])

Buggy submission (verdict: Runtime Error):
from sys import stdin
from sys import setrecursionlimit
import numpy as np
setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
a = [0]+a
bunki = 0
now = a[1]
lip = [1]
while True:
    bunki += 1
    if now in lip:
        break
    lip.append(now)
    now = a[now]

tenki = lip.index(now)

lis = lip[tenki:]

roop = bunki-tenki

if k < tenki: 
    print(lip[k])
    exit()
k -= tenki

print(lis[k%roop])
Problem p02713 (python)

Fixed submission:
from math import gcd
k = int(input())
point = 0
li = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        li[i][j] = gcd(i,j)
lin = []
for i in li:
    for j in i:
        if j != 0:
            lin.append(j)
for i in lin:
    for j in range(1,k+1):
        point += li[i][j]
print(point)

Buggy submission (verdict: Runtime Error):
from math import gcd
import numpy as np
k = int(input())
point = 0
li = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        li[i][j] = gcd(i,j)
lin = []
for i in li:
    for j in i:
        if j != 0:
            lin.append(j)
for i in lin:
    for j in range(1,k+1):
        point += li[i][j]
print(point)
Problem p02755 (python)

Fixed submission:
from sys import stdin
a,b = map(int,stdin.readline().rstrip().split())
for i in range(1001):
    if int(i*0.08) == a and int(i*0.1) == b:
        print(i)
        exit()
print(-1)

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

for i in range(0,100):
    if int(i*1.08) == a and int(i*1.1) == b:
        print(i)
        exit()
        
print(-1)