alexjercan/bugnet huggingface dataset:
Problem p02890 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter
from itertools import accumulate

# from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

# for k in range(1, n + 1):
#     cx = deepcopy(c)

#     count = 0

#     while k <= len(cx):
#         # print(cx)
#         mc = cx.most_common()
#         for key, _ in mc[:k]:
#             cx[key] -= 1
#             if cx[key] < 1:
#                 del cx[key]
#         count += 1

#     print(count)

cv = Counter(c.values())
max_take = max(cv.keys())

lx = list(accumulate(cv[i] for i in range(max_take + 1)))
rx = list(accumulate(cv[i] * i for i in range(max_take + 1)))
ax = [rx[i] + (lx[-1] - lx[i]) * i for i in range(max_take + 1)]


def bisec(l0, r0, predicate):
    l, r = l0, r0

    while abs(l - r) > 1:
        mid = (l + r) // 2
        if predicate(mid):
            r = mid
        else:
            l = mid

    return r


for k in range(1, n + 1):
    print(bisec(n + 1, 0, lambda x: x * k <= ax[min(x, max_take)]))


Error: TLE

Fixed submission:

from collections import Counter
from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

for k in range(1, n + 1):
    cx = deepcopy(c)

    count = 0

    while k <= len(cx):
        # print(cx)
        mc = cx.most_common()
        for key, _ in mc[:k]:
            cx[key] -= 1
            if cx[key] < 1:
                del cx[key]
        count += 1

    print(count)
Problem p02891 (Python) — buggy submission, verdict: Runtime Error

from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    x, y = a[0], a[-1]
    b = (x + y) // 2 if s[0] == s[-1] else x // 2 + y // 2
    print(x // 2 + y // 2 + sum(x // 2 for x in a[1:-1]) * k + b * (k - 1))


Error: 0

Fixed submission:

from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if s[0] == s[-1]:
    a[0] += a.pop()
print(sum(x // 2 for x in a) * k)
Problem p02891 (Python) — buggy submission, verdict: Runtime Error

def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res


S = input()
N = len(S)
K = int(input())
T = run_length_compress(S)
if T[0][1] == N:
    print(N * K // 2)
    exit()
ans = sum(l // 2 for _, l in T) * K
if T[0][0] == T[-1][0]:
    head, tail = T[0][1], T[-1][1]
    ans += ((head + tail) // 2 - head // 2 - tail // 2) * (K - 1)
print(ans)


Error: 0

Fixed submission:

S = input()
N = len(S)
K = int(input())

i = 0
T = []
U = []
while i <= N - 1:
    if i == N - 1:
        T.append(S[-1])
        if S[-2] == S[-1]:
            U.append("?")
        else:
            U.append(S[-1])
        break
    if S[i] == S[i + 1]:
        T.append(S[i] + "?")
        U.append("?" + S[i])
        i += 2
    else:
        T.append(S[i])
        U.append(S[i])
        i += 1

T = "".join(T)
U = "".join(U)
if T[0] == T[-1]:
    print((K + 1) // 2 * T.count("?") + K // 2 * U.count("?"))
else:
    print(K * T.count("?"))
Problem p02891 (Python) — buggy submission, verdict: Runtime Error

def main():
    S = input()
    K = int(input())
    ans = 0

    if len(set(S)) is 1:
        print(len(S) * K // 2)
        return

    i = 0
    cnt = [1]
    while i < len(S) - 1:
        if S[i] is S[i + 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
        i += 1

    for v in cnt:
        ans += (v // 2) * K

    if S[0] is S[-1]:
        if cnt[0] % 2 == cnt[-1] % 2 == 1:
            ans += K - 1

    print(ans)


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

def main():
    S = input()
    K = int(input())
    ans = 0

    if S[0] is S[-1]:
        length = len(S)
    else:
        length = len(S) - 1

    i = 0
    while i < length:
        if S[i] is S[i + 1]:
            ans += 1
            i += 1
        i += 1

    print(ans * K)


if __name__ == "__main__":
    main()
Problem p02891 (Python) — buggy submission, verdict: Runtime Error

S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] == X[-1][0]:
    s = X.pop(0)
    e = X.pop()
    for x in X:
        result += x[1] // 2
    result *= K

    result += s[1] // 2
    result += e[1] // 2
    x = (s[1] + e[1]) // 2
    result += x * (K - 1)
    print(result)
else:
    for x in X:
        result += x[1] // 2
    result *= K
    print(result)


Error: WA

Fixed submission:

S = input()
K = int(input())

print(S * K)

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] // 2

result = result * K
if X[0][0] == X[-1][0]:
    result += 1
print(result)
Problem p02892 (Python) — buggy submission, verdict: Runtime Error

import collections

n = int(input())
s = []
for _ in range(n):
    ch = input()
    s.append([int(c) for c in ch])


def graph(i, n, s):
    flag = [-2 for _ in range(n)]
    flag[i] = 1
    que = collections.deque([i])
    while que:
        target = que.popleft()
        for j in range(n):
            if s[target][j] == 1:
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    return [-1, -1]
    mf = max(flag)
    return [flag.index(mf), mf]


r1 = graph(0, n, s)
if r1[0] == -1:
    print(-1)
else:
    res = r1[1]
    for i in range(1, n):
        r = graph(i, n, s)
        res = max(res, r[1])
    print(res)


Error: 0

Fixed submission:

n = int(input())
s = []
for _ in range(n):
    s.append(input())
check = []
testc = 1000
for i in range(n):
    test = 0
    for c in s[i]:
        test += int(c)
    if test == testc:
        check.append(i)
    elif test < testc:
        check.clear()
        testc = test
        check.append(i)

res = -1
if testc > 1:
    check = check[0]

for i in check:
    tres = 1
    flag = [-2 for i in range(n)]

    flag[i] = 1
    que = [i]
    while que:
        target = que.pop()
        for j in range(n):
            if s[target][j] == "1":
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    tres = -1
                    break
        if tres == -1:
            break

    if tres == -1:
        continue
    else:
        res = max(res, max(flag))

print(res)
Problem p02897 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
odds = list(filter(lambda x: x % 2 != 0, range(1, N + 1)))
print("{:.10f}".format(len(odds) / float(N)))


Error: TypeError: object of type 'filter' has no len()
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s177857539.py", line 3, in <module>
    print(len(nums) / float(N))
TypeError: object of type 'filter' has no len()


Fixed submission:

N = int(input())
nums = filter(lambda x: x % 2 != 0, range(1, N + 1))
print(len(nums) / float(N))
Problem p02897 (Python) — buggy submission, verdict: Runtime Error

x = int(input())
if x == 1:
    print(1)
elif x % 2 == 0:
    print(0.5)
else:
    print((x // 2 + 1) / x)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s963162599.py", line 3, in <module>
    elif int(input()) % 2 == 0:
EOFError: EOF when reading a line


Fixed submission:

if int(input()) == 1:
    print(1)
elif int(input()) % 2 == 0:
    print(0.5)
else:
    print(0.6)
Problem p02897 (Python) — buggy submission, verdict: Runtime Error

N = int(input())

if N % 2 == 0:
    print((N / 2) / N)

else:
    print(((N + 1) / 2) / N)


Error: TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s639132796.py", line 3, in <module>
    if N % 2 == 0:
TypeError: not all arguments converted during string formatting


Fixed submission:

N = input()

if N % 2 == 0:
    print((N / 2) / N)

else:
    print(((N + 1) / 2) / N)
Problem p02897 (Python) — buggy submission, verdict: Runtime Error

n = int(input())

a = int(n / 2)
b = n % 2

c = a + b

print(c / n)


Error: TypeError: unsupported operand type(s) for /: 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02897/Python/s076405761.py", line 3, in <module>
    a = int(n / 2)
TypeError: unsupported operand type(s) for /: 'str' and 'int'


Fixed submission:

n = input()

a = int(n / 2)
b = n % 2

c = a + b

print(c)
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
H = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if H[i] >= k:
        cnt += 1
print(cnt)


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s127858228.py", line 4, in <module>
    for i in n:
TypeError: 'int' object is not iterable


Fixed submission:

n, k = map(int, input().split())
H = list(map(int, input().split()))
cnt = 0
for i in n:
    if H[i] >= k:
        cnt += 1
print(cnt)
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

NK_lis = list(map(int, input().split()))
h_lis = list(map(int, input().split()))
a = 0
for i in range(NK_lis[0]):
    if h_lis[i] >= NK_lis[1]:
        a += 1
print(a)


Error: ValueError: invalid literal for int() with base 10: '4 150'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s286734935.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


Fixed submission:

N = int(input())
K = int(input())
h = []
a = 0
for i in range(N):
    b = int(input())
    h.append(b)
    if h[i] >= K:
        a += 1
print(a)
Problem p02898 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
h = list(map(int, input().split()))
i = 0
ans = 0
for i in range(n):
    if h[i] >= k:
        ans += 1
print(ans)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
    if a[i] >= k:
        ans += 1
        i += 1
print(ans)
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

n, min_height = map(int, input().split())
height = list(map(int, input().split()))
height.sort(reverse=True)

cnt = 0
for h in height:
    if h < min_height:
        break
    cnt += 1
print(cnt)


Error: ValueError: invalid literal for int() with base 10: '4 150'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s709157737.py", line 1, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


Fixed submission:

n = int(input())
min_height = int(input())

height = []
for _ in range(n):
    height.append(int(input()))
height.sort(reverse=True)

cnt = 0
for h in height:
    if h < min_height:
        break
    cnt += 1
print(cnt)
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(len(list(filter(lambda x: x >= k, h))))


Error: TypeError: object of type 'filter' has no len()
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s747999474.py", line 3, in <module>
    print(len(filter(lambda x: x >= k, h)))
TypeError: object of type 'filter' has no len()


Fixed submission:

n, k = map(int, input().split())
h = list(map(int, input().split()))
print(len(filter(lambda x: x >= k, h)))
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

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

count = 0
for i in range(N):
    if ar[i] >= K:
        count += 1

print(count)


Error: TypeError: list expected at most 1 argument, got 2
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s440277663.py", line 2, in <module>
    ar = list(map, input().split())
TypeError: list expected at most 1 argument, got 2


Fixed submission:

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

count = 0
for i in range(N):
    if ar[i] >= K:
        count += 1

print(count)
Problem p02898 (Python) — buggy submission, verdict: Runtime Error

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


count = 0
for i in h:
    if i >= K:
        count += 1

print(count)


Error: ValueError: invalid literal for int() with base 10: '4 150'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02898/Python/s129159641.py", line 1, in <module>
    N = int(input())
ValueError: invalid literal for int() with base 10: '4 150'


Fixed submission:

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


count = 0
for i in h:
    if i >= K:
        count += 1

print(count)
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

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

lis = []
for i in range(N):
    lis.append([A[i], i + 1])

lis.sort()
ans = []
for i in range(N):
    ans.append(lis[i][1])

print(" ".join(map(str, ans)))


Error: TLE

Fixed submission:

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

order = [0] * N
flag = 0
for i in range(0, N):
    flag = A.index(min(A))
    order[i] = flag + 1
    A[flag] = N + 1

print(" ".join(map(str, order)))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    x.append((a[i], i + 1))
x.sort()
y = []
for i in range(n):
    y.append(x[i][1])
print(" ".join(map(str, y)))


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
x = []
x = [0 for i in range(n)]
for j in range(n):
    x.pop(a[j] - 1)
    x.insert(a[j] - 1, j + 1)
print(" ".join(map(str, x)))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))

    result = []
    for i, a in enumerate(A, start=1):
        result.append([i, a])
    result = sorted(result, key=lambda x: x[1])

    print(*[i for i, a in result])


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = list(map(int, input().split()))
    print(*[S.index(i + 1) + 1 for i in range(N)])


if __name__ == "__main__":
    main()
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans_list = [None for _ in range(N)]

    for i in range(N):
        ans_list[A[i] - 1] = i

    for v in ans_list:
        print(v + 1, end=" ")

    print()


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    N = int(input())
    A = list(map(int, input().split()))

    for v in range(1, N + 1):
        print(A.index(v) + 1, end=" ")

    print()


if __name__ == "__main__":
    main()
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

# https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
a = list(map(int, input().split()))
#### TLE ####
# ans = [str(a.index(i + 1) + 1) for i in range(n)]
# print(" ".join(ans))

b = [" "] * n
for i in range(n):
    b[a[i] - 1] = str(i + 1)

print(" ".join(b))


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
ans = [str(a.index(i + 1) + 1) for i in range(n)]
print(" ".join(ans))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
output = [0] * n
for i, a in enumerate(a):
    output[a - 1] = i + 1

print(*output)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))

for i in range(1, n + 1):
    print(a.index(i) + 1)
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

import numpy as np

N = int(input())
A = list(map(int, input().split()))
T = [0] * N
for i in range(N):
    T[A[i] - 1] = i + 1
print(*T)


Error: TLE

Fixed submission:

import numpy as np

N = int(input())
A = list(map(int, input().split()))
T = [0] * N
for i in range(N):
    t = np.argmin(A)
    T[i] = t + 1
    A[t] = N + 1
print(*T)
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

for i in range(1, N + 1):
    ans[A[i - 1] - 1] = i

print(*ans)


Error: TLE

Fixed submission:

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

ans = [0] * len(A)

for i in A:
    ans[i - 1] = A.index(i) + 1

print(*ans)
Problem p02899 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

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

AA = np.argsort(A) + 1

print(*AA)


Error: TLE

Fixed submission:

import numpy as np

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

AA = np.argsort(A) + 1

print(AA.to_list())
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = [int(i) for i in input().split()]

ans = [0] * N
for i in range(N):
    ans[A[i] - 1] = i + 1

print(*ans)


Error: TLE

Fixed submission:

N = int(input())
A = [int(i) for i in input().split()]

ans = []
for i in range(1, N + 1):
    ans.append(A.index(i) + 1)

print(*ans)
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = [0] * N
    for i in range(N):
        ans[A[i] - 1] = i + 1
    print(*ans)


resolve()


Error: TLE

Fixed submission:

def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N):
        if i > 0:
            print(" ", end="")
        print(A.index(i + 1) + 1, end="")
    print()


resolve()
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))

ans = [0] * n

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

print(*ans)


Error: TLE

Fixed submission:

n = input()
a = input().split()

result = []

for i in range(len(a)):
    result.append(a.index(str(i + 1)) + 1)

print(*result)
Problem p02899 (Python) — buggy submission, verdict: Runtime Error

N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append([A[i]])
    B[i].append(i + 1)  # 出席番号をそれぞれ追加している
B = sorted(B)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(B[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))


Error: 0

Fixed submission:

N = int(input())
A = list(map(list, input().split()))
for i in range(N):
    A[i].append(i + 1)  # 出席番号をそれぞれ追加している
A = sorted(A)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(A[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A_i = list(map(int, input().split()))

B_i = [0 for s in range(N)]

for i in range(1, N + 1):
    B_i[A_i[i - 1] - 1] = str(i)


print(" ".join(B_i))


Error: TLE

Fixed submission:

N = int(input())
A_i = list(map(int, input().split()))

B_i = []

for i in range(1, N + 1):
    B_i.append(str(A_i.index(i) + 1))

print(" ".join(B_i))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

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

d = dict(zip(range(N), A))

ans = [str(k + 1) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))


Error: TLE

Fixed submission:

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

d = {}
for a in A:
    d[A.index(a) + 1] = a

ans = [str(k) for k, _ in sorted(d.items(), key=lambda x: x[1])]
print(" ".join(ans))
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
out = [""] * n
out_str = ""
for i in range(n):
    out[a[i] - 1] = str(i + 1)

out_str = " ".join(out)

print(out_str)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
out = [""] * n
count = 0
out_str = ""
for i in range(n):
    out_str += str(a.index(i + 1) + 1) + " "

print(out_str[:-1])
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys
import collections
import bisect


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] * n
    for i in range(n):
        B[A[i] - 1] = str(i + 1)
    print(" ".join(B))


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
b = [None] * n
print(str(a.index(1) + 1), end=" ")
for i in range(1, n):
    print(str(a.index(i + 1) + 1), end=" ")
print()
Problem p02899 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = [0] * n
    for i in range(n):
        ans[a[i] - 1] = i + 1
    print(*ans)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys


def main():
    n = int(input())
    a = [int(i) for i in sys.stdin.readline().split()]
    ans = []
    ans_append = ans.append
    for i in range(n):
        ans_append(a.index(i + 1) + 1)
    print(*ans)


if __name__ == "__main__":
    main()
Problem p02900 (Python) — buggy submission, verdict: Time Limit Exceeded

aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)


def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c


def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


B = get_max(A, B)
factors = factorize(B)

if len(factors) == 0:
    print(1)
else:
    count = 1
    for i in range(0, len(factors) - 1):
        if factors[i] != factors[i + 1]:
            count += 1
    print(count + 1)


Error: TLE

Fixed submission:

aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)


def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c


B = get_max(A, B)

temp = []
for i in range(1, B + 1):
    if B % i == 0:
        temp.append(i)

flag = [0] * len(temp)
count = len(temp)
for i in range(0, len(temp)):
    for j in range(i + 1, len(temp)):
        if flag[j] == 0:
            max_ = get_max(temp[i], temp[j])
            if max_ != 1:
                flag[j] = 1
                count -= 1

print(count)