Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

for a in A:
    if a in vis:
        c = town2cnt[a]
        rem = K - cnt
        num_loop = cnt - c

        k = rem % num_loop
        print(cnt2town[c + k + 1])
        exit()

    if cnt == K:
        print(a)
        exit()

    cnt += 1
    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)


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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

cnt = 1
prev = 1
while cnt <= K:
    a = A[prev - 1]

    if a in vis:
        c = town2cnt[a]

        rem = K - cnt
        num_loop = cnt - c

        r = rem % num_loop
        print(cnt2town[c + r])

        exit()

    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

    prev = a
    cnt += 1


print(a)

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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

for a in A:
    if a in vis:
        c = town2cnt[a]
        rem = K - cnt
        num_loop = cnt - c

        k = rem % num_loop
        print(cnt2town[c + k + 1])
        exit()

    if cnt == K:
        print(a)
        exit()

    cnt += 1
    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)




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

vis = set()
vis.add(1)
cnt = 0
cnt2town = {}
town2cnt = {}
cnt2town[0] = 1
town2cnt[1] = 0

cnt = 1
prev = 1
while cnt <= K:
    a = A[prev - 1]

    if a in vis:
        c = town2cnt[a]

        rem = K - cnt
        num_loop = cnt - c

        r = rem % num_loop
        print(cnt2town[c + r])

        exit()

    cnt2town[cnt] = a
    town2cnt[a] = cnt
    vis.add(a)

    prev = a
    cnt += 1


print(a)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

moji = ''
cnt = 0

lst = [0] * 2020
lst[0] = 1

for s in S[::-1]:
    moji = s + moji
    r = int(moji) % 2019
    cnt += lst[r]
    lst[r] += 1

print(cnt)


Fixed submission:
S = input()

num = 0

r_lst = [0] * 2019
r_lst[0] = 1
cnt = 0
for i, s in enumerate(S[::-1]):
    num = (num + pow(10, i, 2019) * int(s)) % 2019
    cnt += r_lst[num]

    r_lst[num] += 1


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

rem = {}
rem[0] = 1

moji = ''
MOD = 2019
cnt = 0

for i in range(1, len(S) + 1):
    moji = S[-i:]
    r = int(moji) % 2019
    if r in rem:
        cnt += rem[r]

    if r not in rem:
        rem[r] = 1
    else:
        rem[r] += 1

print(cnt)


Fixed submission:
S = input()

num = 0

r_lst = [0] * 2019
r_lst[0] = 1
cnt = 0
for i, s in enumerate(S[::-1]):
    num = (num + pow(10, i, 2019) * int(s)) % 2019
    cnt += r_lst[num]

    r_lst[num] += 1


print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

rem = {}
rem[0] = 1

moji = ''
MOD = 2019
cnt = 0

for s in S[::-1]:
    moji = s + moji

    r = int(moji) % 2019
    if r in rem:
        cnt += rem[r]

    if r not in rem:
        rem[r] = 1
    else:
        rem[r] += 1

print(cnt)


Fixed submission:
S = input()

num = 0

r_lst = [0] * 2019
r_lst[0] = 1
cnt = 0
for i, s in enumerate(S[::-1]):
    num = (num + pow(10, i, 2019) * int(s)) % 2019
    cnt += r_lst[num]

    r_lst[num] += 1


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

A.sort(reverse=True)

s = sum(A)
c = s / (4 * M)

if A[M] < c:
    print('No')
else:
    print('Yes')



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

A.sort(reverse=True)

s = sum(A)
c = s / (4 * M)

if A[M - 1] < c:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = list(map(int, input().split()))

dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1


for k in range(N):
    t = A[k]

    dic[t] -= 1

    cnt = 0

    for key, val in dic.items():
        if val < 2:
            continue

        cnt += int((val * (val - 1)) / 2)

    print(cnt)
    dic[t] += 1


Fixed submission:
N = int(input())

A = list(map(int, input().split()))

dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

dic2 = {}
sum_ = 0
for key, val in dic.items():
    if val < 2:
        dic2[key] = (0, 0)
    elif val == 2:
        dic2[key] = (1, 0)
        sum_ += 1
    else:
        x = int((val * (val - 1)) / 2)
        val -= 1
        y = int((val * (val - 1)) / 2)

        dic2[key] = (x, y)
        sum_ += x

for k in range(N):
    t = A[k]

    print(sum_ - dic2[t][0] + dic2[t][1])
Buggy python submission (verdict: Runtime Error):
import bisect
from collections import defaultdict

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


alpha_dic = defaultdict(list)

for i, s in enumerate(S):
    alpha_dic[s].append(i)

for _ in range(Q):
    l, m, n = input().split()

    if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            x = len(val)

            if left_idx > right_idx or left_idx == x or (left_idx == 0 and right_idx == 0 and val[0] != m and val[0] != n):
                continue
            else:
                cnt += 1

        print(cnt)


Fixed submission:
import bisect
from collections import defaultdict

N = int(input())
S = list(input())
Q = int(input())

alpha_dic = defaultdict(list)

for i, s in enumerate(S):
    alpha_dic[s].append(i)

for _ in range(Q):
    l, m, n = input().split()

    if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

        print(cnt)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

l = len(S)

MOD = 1000000007

dp = [[[0] * (l + 1) for _ in range(2)] for _ in range(l + 1)]

dp[0][False][0] = 1

for i in range(l):
    cur = int(S[i])

    for j in range(i + 1):
        for k in range(10):
            if k == 0:
                dp[i + 1][True][j] += dp[i][True][j]
            else:
                dp[i + 1][True][j + 1] += dp[i][True][j]
                
        for k in range(cur):
            if k == 0:
                dp[i + 1][True][j] += dp[i][False][j]
            else:
                dp[i + 1][True][j + 1] += dp[i][False][j]

        if cur == 0:
            dp[i + 1][False][j] += dp[i][False][j]
        else:
            dp[i + 1][False][j + 1] += dp[i][False][j]


print(dp[l][True][K] + dp[l][False][K])


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

l = len(S)

MOD = 1000000007

# [桁数][未満][0でない数の合計数]
dp = [[[0] * (l + 1) for _ in range(2)] for _ in range(l + 1)]


# 初期化
dp[0][False][0] = 1

for i in range(l):
    cur = int(S[i])

    for j in range(i + 1):
        # true -> true
        for k in range(10):
            if k == 0:
                dp[i + 1][True][j] += dp[i][True][j]
            else:
                dp[i + 1][True][j + 1] += dp[i][True][j]

        # false -> true
        for k in range(cur):
            if k == 0:
                dp[i + 1][True][j] += dp[i][False][j]
            else:
                dp[i + 1][True][j + 1] += dp[i][False][j]

        # false -> false
        if cur == 0:
            dp[i + 1][False][j] += dp[i][False][j]
        else:
            dp[i + 1][False][j + 1] += dp[i][False][j]

if K > l:
    print(0)
else:
    print(dp[l][True][K] + dp[l][False][K])
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b if amt - a >= 0 else float('inf') for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)


Fixed submission:
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)

Buggy python submission (verdict: Runtime Error):
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b if amt - a >= 0 for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)


Fixed submission:
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [float('inf')] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b if amt - a >= 0 else float('inf') for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)


Fixed submission:
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)



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

if N == M:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)



Fixed submission:
from collections import defaultdict

d = defaultdict(int)
N = int(input())

for n in range(1, N + 1):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

cnt = 0
for i in range(1, N + 1):
    n_str = str(i)

    pre = n_str[0]
    suf = n_str[-1]

    if suf == '0':
        continue

    for j in range(1, N + 1):
        m_str = str(j)

        pre1 = m_str[0]
        suf1 = m_str[-1]

        if suf1 == '0':
            continue

        if pre == suf1 and suf == pre1:
            cnt += 1

print(cnt)

Fixed submission:
from collections import defaultdict

d = defaultdict(int)
N = int(input())

for n in range(1, N + 1):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

cnt = 0
for i in range(1, N + 1):
    n_str = str(i)

    pre = n_str[0]
    suf = n_str[-1]

    if suf == '0':
        continue

    for j in range(1, N + 1):
        m_str = str(j)

        pre1 = m_str[0]
        suf1 = m_str[-1]

        if suf1 == '0':
            continue

        if pre == suf1 and suf == pre1:
            cnt += 1

print(cnt)

Fixed submission:
from collections import defaultdict

d = defaultdict(int)
N = int(input())

for n in range(1, N + 1):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))

MOD = 1000000007

def combinations(n, r):
    r = min(r, n - r)

    num = 1
    den = 1

    for i in range(1, r + 1):
        num = num * (n + 1 - i) % MOD
        den = den * i % MOD

    return num * pow(den, MOD - 2, MOD) % MOD


A.sort()

max_sum = 0
min_sum = 0
for i, a in enumerate(A):
    # max
    if i >= K - 1:
        max_sum += a * combinations(i, K - 1)

    # min
    if i <= N - K:
        min_sum += a * combinations(N - i - 1, K - 1)


print(int((max_sum - min_sum) % MOD))


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

A = list(map(int, input().split()))

MOD = 1000000007


def combinations(n, r, MOD):
    if (r < 0) or (n < r):
        return 0

    r = min(r, n - r)
    return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD


A.sort()
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)

max_sum = 0
min_sum = 0

for i, a in enumerate(A):
    # max
    if i >= K - 1:
        max_sum += a * combinations(i, K - 1, MOD)

    # min
    if i <= N - K:
        min_sum += a * combinations(N - i - 1, K - 1, MOD)

print(int((max_sum - min_sum) % MOD))

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

A = list(map(int, input().split()))

MOD = 1000000007


def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


A.sort()

max_sum = 0
min_sum = 0
for i, a in enumerate(A):
    # max
    if i >= K - 1:
        max_sum += a * combinations(i, K - 1)

    # min
    if i <= N - K:
        min_sum += a * combinations(N - i - 1, K - 1)


print(int((max_sum - min_sum) % MOD))


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

A = list(map(int, input().split()))

MOD = 1000000007


def combinations(n, r, MOD):
    if (r < 0) or (n < r):
        return 0

    r = min(r, n - r)
    return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD


A.sort()
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)

max_sum = 0
min_sum = 0

for i, a in enumerate(A):
    # max
    if i >= K - 1:
        max_sum += a * combinations(i, K - 1, MOD)

    # min
    if i <= N - K:
        min_sum += a * combinations(N - i - 1, K - 1, MOD)

print(int((max_sum - min_sum) % MOD))
Buggy python submission (verdict: Runtime Error):
import math

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


def get_lcm(a, b):
    return (a * b) // math.gcd(a, b)


print(get_lcm(A, B))


Fixed submission:
import fractions

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


def get_lcm(a, b):
    return (a * b) // fractions.gcd(a, b)


print(get_lcm(A, B))
Buggy python submission (verdict: Runtime Error):
s = 0
S = [0]
for i, a in enumerate(A):
    s += a
    S.append(s % K)

cnt = 0
dic = {}

for i, s in enumerate(S):
    x = (s - i) % K

    if x in dic:
        cnt += dic[x]
        dic[x] += 1
    else:
        dic[x] = 1

    K_prev = i - K + 1

    if K_prev >= 0:
        y = (S[K_prev] - (K_prev)) % K
        dic[y] -= 1


print(cnt)


Fixed submission:
from collections import defaultdict
import bisect

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

s = 0
S = [0]
for i, a in enumerate(A):
    s += a
    S.append(s % K)

cnt = 0
dic = {}

for i, s in enumerate(S):
    x = (s - i) % K

    if x in dic:
        cnt += dic[x]
        dic[x] += 1
    else:
        dic[x] = 1

    K_prev = i - K + 1

    if K_prev >= 0:
        y = (S[K_prev] - (K_prev)) % K
        dic[y] -= 1


print(cnt)
Buggy python submission (verdict: Runtime Error):
import math

if (X + Y) % 3 != 0:
    print(0)
    exit()

m = (2 * Y - X) / 3
n = (2 * X - Y) / 3
m = int(m)
n = int(n)

if m < 0 or n < 0:
    print(0)
    exit()

num = 1

for x in range(m + n, n, -1):
    num *= x

den = 1
for x in range(1, m + 1):
    den *= x

print(int(num / den) % MOD)


Fixed submission:
import math
X, Y = map(int, input().split())

MOD = 1000000007


def combination(n, r):
    r = min(r, n - r)

    num = 1
    den = 1

    for i in range(1, r + 1):
        num = num * (n + 1 - i) % MOD
        den = den * i % MOD

    return num * pow(den, MOD - 2, MOD) % MOD


if (X + Y) % 3 != 0:
    print(0)
    exit()

m = (2 * Y - X) / 3
n = (2 * X - Y) / 3
m = int(m)
n = int(n)

if m < 0 or n < 0:
    print(0)
    exit()

print(int(combination(m + n, n)) % MOD)

Buggy python submission (verdict: Runtime Error):
from collections import deque, defaultdict
# import sys
# sys.setrecursionlimit(1000000)
X, Y = map(int, input().split())

MOD = 1000000007

dp = defaultdict(int)
def search(r, c):
    if (r > X) or (c > Y):
        return 0

    # if dp[r][c] is not None:
    #     return dp[r][c]
    if (r, c) in dp:
        return dp[(r, c)]

    if (r == X) and (c == Y):
        return 1

    ret = search(r + 1, c + 2) + search(r + 2, c + 1)

    # dp[r][c] = ret
    dp[(r, c)] = ret
    return ret
  
print(search(0, 0) % MOD)

Fixed submission:
import math
X, Y = map(int, input().split())

MOD = 1000000007


def combination(n, r):
    r = min(r, n - r)

    num = 1
    den = 1

    for i in range(1, r + 1):
        num = num * (n + 1 - i) % MOD
        den = den * i % MOD

    return num * pow(den, MOD - 2, MOD) % MOD


if (X + Y) % 3 != 0:
    print(0)
    exit()

m = (2 * Y - X) / 3
n = (2 * X - Y) / 3
m = int(m)
n = int(n)

if m < 0 or n < 0:
    print(0)
    exit()

print(int(combination(m + n, n)) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

max_a = max(A)
max_f = max(F)

left = 0
right = max_a * max_f

while left <= right:
    x = (left + right) // 2

    sum_ = 0
    for i in range(N):
        if A[i] * F[i] > x:
            sum_ += (A[i] - int(x / F[i]))

    if sum_ > K:
        left = x + 1

    if sum_ <= K:
        right = x - 1


print(left)


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

A.sort()
F.sort(reverse=True)

max_a = max(A)
max_f = max(F)

left = 0
right = max_a * max_f

while left <= right:
    x = (left + right) // 2

    sum_ = 0
    for i in range(N):
        if A[i] * F[i] > x:
            sum_ += (A[i] - int(x / F[i]))

    if sum_ > K:
        left = x + 1

    if sum_ <= K:
        right = x - 1


print(left)
Buggy python submission (verdict: Runtime Error):
import bisect

N = int(input())
L = sorted(list(map(int, input().split())))

cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
        cnt += max(0, idx - (j + 1))
        
print(cnt)

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


print(max(A - B * 2, 0))
Buggy python submission (verdict: Runtime Error):
    from heapq import heapify, heappop, heappush, nlargest, nsmallest
     
     
    N, M, L = map(int, input().split())
     
    G = [list(map(int, input().split())) for _ in range(M)]
    Q = int(input())
    Query = [list(map(int, input().split())) for _ in range(Q)]
     
    nei_graph = [[float('inf')] * N for _ in range(N)]
    for a, b, c in G:
        if c <= L:
            nei_graph[a - 1][b - 1] = c
            nei_graph[b - 1][a - 1] = c
     
    for a, b, c in G:
        nei_graph[a - 1][a - 1] = 0
     
     
    def dijkstra(start_node, end_node, nei_graph):
        visited = set()
     
        nodes = []
        heapify(nodes)
        heappush(nodes, [start_node, 0, L, 0])
     
        dist = [float('inf')] * N
        dist[start_node] = 0
     
        while nodes:
            node, d, remain, cnt = heappop(nodes)
            if node in visited:
                continue
     
            if node == end_node:
                return cnt
     
            visited.add(node)
     
            for i, edge in enumerate(nei_graph[node]):
                if edge == float('inf') or d + edge > dist[i]:
                    continue
     
                dist[i] = d + edge
     
                if remain < edge:
                    new_remain = L - edge
                    new_cnt = cnt + 1
                else:
                    new_remain = remain - edge
                    new_cnt = cnt
     
                heappush(nodes, [i, dist[i], new_remain, new_cnt])
     
        if end_node not in visited:
            return -1
     
     
    for start, end in Query:
        print(dijkstra(start - 1, end - 1, nei_graph))

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())

G = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

# neighborhood graph
nei_graph = [[0] * N for _ in range(N)]
for a, b, c in G:
    nei_graph[a - 1][b - 1] = c
    nei_graph[b - 1][a - 1] = c

# Warshall Floyd
nei_graph = floyd_warshall(nei_graph)

# 1 if distance is less than L
for i in range(N):
    for j in range(N):
        if nei_graph[i][j] <= L:
            nei_graph[i][j] = 1
        else:
            nei_graph[i][j] = 0

nei_graph = floyd_warshall(nei_graph)

for start, end in Query:
    if nei_graph[start - 1][end - 1] - 1 == float('inf'):
        print(-1)
    else:
        print(int(nei_graph[start - 1][end - 1] - 1))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

import math


def dv(x1, x2):
    ret = []
    v = int(math.sqrt(min(x1, x2))) + 1

    check = [0] * (v + 1)

    for n in range(2, v):
        if check[n] == 1:
            continue

        if x1 % n == 0 and x2 % n == 0:
            ret.append(n)

            cnt = 1
            while n * cnt <= v:
                check[n * cnt] = 1
                cnt += 1

    return ret


cf = [1] + dv(A, B)
print(len(cf))


Fixed submission:
N = int(input())

x = N % 2

if x == 0:
    print(1/2)
else:
    y = N // 2 + 1
    print(y / N)