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

Fixed submission:
import numpy as np

q = int(input())

# 素数列挙
n = 10**5 + 1
primes = set(range(3, n+1, 2))
for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)

arr = np.array(list(primes))
arr = np.bincount(arr)

# 素数かつ2017に似た数を列挙
like_2017 = np.zeros(n, bool)
for i in np.where(arr == 1)[0]:
    if (i + 1) // 2 in primes:
        like_2017[i] = True

like_2017 = like_2017.cumsum()


def cnt_primes(l, r):
    return like_2017[r] - like_2017[l - 1]


ans = []
for _ in range(q):
    tmp = 0
    l, r = map(int, input().split())
    tmp += cnt_primes(l, r)
    ans.append(tmp)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
import bisect
from collections import defaultdict

q = int(input())


n = 10**5 + 1
primes = set(range(2, n+1))

for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))

primes = list(primes)


def is_prime(i):
    p = bisect.bisect_left(primes, i)
    if primes[p] == i:
        return True
    else:
        return False


memo = defaultdict(bool)


ans = []
for _ in range(q):
    tmp = 0
    l, r = map(int, input().split())
    for i in range(l, r + 1, 2):
        if i in memo:
            tmp += memo[i]
        else:
            memo[i] = is_prime(i) and is_prime((i + 1) // 2)
            tmp += memo[i]
    ans.append(tmp)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
import bisect

q = int(input())


n = 100000
primes = set(range(2, n+1))

for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))

primes = list(primes)


def is_prime(i):
    p = bisect.bisect_left(primes, i)
    if primes[p] == i:
        return True
    else:
        return False


ans = []
for _ in range(q):
    tmp = 0
    l, r = map(int, input().split())
    tmp += sum([is_prime(x) and is_prime((x + 1) // 2) for x in range(l, r + 1, 2)])
    ans.append(tmp)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
import bisect

q = int(input())


n = 100000
primes = set(range(2, n+1))

for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))

primes = list(primes)


def is_prime(i):
    p = bisect.bisect_left(primes, i)
    if primes[p] == i:
        return True
    else:
        return False


ans = []
for _ in range(q):
    tmp = 0
    l, r = map(int, input().split())
    tmp += sum([is_prime(x) and is_prime((x + 1) // 2) for x in range(l, r + 1, 2)])
    ans.append(tmp)

print(*ans, sep="\n")
Problem p03477 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
diff = a + b - c - d
print("Left" if diff > 0 else "Balanced" if diff == 0 else "Right")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
diff = a + b - c - d
print("Left" if diff > 0 "Balanced" if diff == 0 else "Right")
Problem p03546 (python)

Fixed submission:
import copy

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

# ワーシャルフロイド法で更新がなくなるまで更新
while True:
    prev = copy.deepcopy(dp)
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if i == j:
                    continue
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    if prev == dp:
        break
    prev = dp

ans = 0
for i in range(h):
    arr = list(map(int, input().split()))
    ans += sum([dp[x][1] for x in arr if x != -1])

print(ans)

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

h, w = map(int, input().split())
dp = [list(map(int, input().split())) for _ in range(10)]
arr = np.array([list(map(int, input().split())) for h in range(h)])

# ワーシャルフロイド法で更新がなくなるまで更新
while True:
    prev = copy.deepcopy(dp)
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if i == j:
                    continue
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    if prev != dp:
        break
    prev = dp

arr = arr.flatten()

print(sum([dp[x][1] for x in arr if x != -1 or x != 1]))
Problem p03569 (python)

Fixed submission:
import sys
from collections import deque

s = deque(map(str, input().rstrip()))

cnt = 0
while s:
    if s[0] != s[-1]:
        if s[0] != "x" and s[-1] != "x":
            print(-1)
            sys.exit()
        elif s[0] == "x":
            tmp = s.popleft()
        else:
            tmp = s.pop()
        cnt += 1
    elif len(s) <= 1:
        break
    else:
        s.popleft()
        s.pop()

print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque

s = deque(map(str, input().rstrip()))

cnt = 0
while s:
    if s[0] != s[-1]:
        if s[0] != "x" and s[-1] != "x":
            print(-1)
            sys.exit()
        elif s[0] == "x":
            tmp = s.popleft()
        else:
            tmp = s.pop()
        cnt += 1
    elif len(s) <= 1:
        break
    else:
        s.popleft()
        s.pop()

print(cnt)
Problem p03578 (python)

Fixed submission:
from collections import defaultdict

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

memo = defaultdict(int)

for d in D:
    memo[d] += 1

for t in T:
    memo[t] -= 1

memo = list(memo.values())
memo.sort()

print("YES" if memo[0] >= 0 else "NO")

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

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

memo = defaultdict(int)

for d in D:
    memo[d] += 1

for t in T:
    memo[t] -= 1

memo.sort()

print("YES" if memo[0] >= 0 else "NO")
Problem p03593 (python)

Fixed submission:
from collections import Counter
import sys

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

arr = sum(arr, [])

c = Counter(arr)
c = list(c.values())

if h % 2 == 0 and w % 2 == 0:
    ans = all([x % 4 == 0 for x in c])  # 全て4個セットならOK

elif h % 2 == 1 and w % 2 == 1:
    even = (h + w) // 2 - 1  # 2個セットを許容できる個数
    odd_cnt = len([x for x in c if x % 2 == 1])
    if odd_cnt != 1:
        print("No")
        sys.exit()
    odd = sum([x for x in c if x % 2 == 1])
    if odd % 4 == 3:
        even -= 1
    c.remove(odd)
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

else:
    even = h // 2 if h % 2 == 0 else w // 2  # 2個セットを許容できる個数
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

print("Yes" if ans else "No")

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

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

arr = sum(arr, [])

arr = Counter(arr)
arr = np.array(list(arr.values()))


def solve(arr):
    # 偶数×偶数なら、制約がかなりきつい
    if h % 2 == 0 and w % 2 == 0:
        return np.all(c % 4 == 0)

    # 奇数×奇数なら、
    elif h % 2 == 1 and w % 2 == 1:
        even = (h + w) // 2 - 1
        if (arr % 2 == 1).sum() != 1:
            return False
        odd = arr[np.where(arr % 2 == 1)].sum()
        if odd % 4 == 3:
            even -= 1
        arr = arr[np.where(arr != odd)]
        ans = (arr % 4 == 2).sum() <= even
        ans &= np.all(arr[np.where(arr % 4 != 2)] % 4 == 0)
        return ans

    #　どちらかの辺が偶数なら
    else:
        even = h // 2 if h % 2 == 0 else w // 2
        ans = (arr % 4 == 2).sum() <= even
        ans &= np.all(arr[np.where(arr % 4 != 2)] % 4 == 0)
        return ans


print("Yes" if solve(arr) else "No")

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

arr = sum(arr, [])

c = Counter(arr)
c = list(c.values())

if h % 2 == 0 and w % 2 == 0:
    ans = all([x % 4 == 0 for x in c])  # 全て4個セットならOK

elif h % 2 == 1 and w % 2 == 1:
    even = (h + w) // 2 - 1  # 2個セットを許容できる個数
    odd_cnt = len([x for x in c if x % 2 == 1])
    if odd_cnt != 1:
        print("No")
        sys.exit()
    odd = sum([x for x in c if x % 2 == 1])
    if odd % 4 == 3:
        even -= 1
    c.remove(odd)
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

else:
    even = h // 2 if h % 2 == 0 else w // 2  # 2個セットを許容できる個数
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

print("Yes" if ans else "No")
Problem p03611 (python)

Fixed submission:
from collections import Counter

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

for i in range(N):
    a.append(a[i]+1)
    a.append(a[i]-1)

ans = Counter(a)

print(ans.most_common()[0][1])

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

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

d = defaultdict(int)

for x in arr:
    d[x] += 1

ans = []
for i in range(1, max(arr)):
    ans.append(d[i - 1] + d[i] + d[i + 1])

print(max(ans))

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

d = defaultdict(int)

for x in arr:
    d[x] += 1

ans = []
for i in range(1, max(arr)):
    ans.append(d[i - 1] + d[i] + d[i + 1])

print(max(ans))

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

ans = 0

for i in range(N):
    tmp = a.copy()
    tmp = np.abs(tmp - tmp[i])
    ans = max(ans, np.where(tmp<=1)[0].shape[0])

print(ans)
Problem p03624 (python)

Fixed submission:
S = set(input())

li = list({chr(ord('a') + i) for i in range(26)} - S)
li = sorted(li)

print(None) if len(li)==0 else print(li[0])

Buggy submission (verdict: Runtime Error):
S = set(input())

li = list({chr(ord('a') + i) for i in range(26)} - S)
li = sorted(li)

print(li[0])
Problem p03644 (python)

Fixed submission:
N = int(input())

cnt = 0
tmp = 0

while tmp<=N:
    cnt += 1
    tmp = 2**cnt

print(2**(cnt-1))

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

cnt = 0
tmp = 0

while tmp<=N:
    if N==1:
        print(ans)
        break
    else:
        cnt += 1
        tmp = 2**cnt

print(2**(cnt-1))
Problem p03657 (python)

Fixed submission:
a, b = map(int, input().split())
print("Possible" if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0 else "Impossible")

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

whole = a.sum()
div = np.abs(a.cumsum() - whole / 2).argmin()

if div == 0 or div == (n - 1):
    print(min(np.abs(a[0] - a[1:].sum()), np.abs(a[:-1].sum() - a[-1])))
else:
    print(np.abs(a[:div + 1].sum() - a[div + 1:].sum()))
Problem p03659 (python)

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

whole = sum(a)

if n == 2:
    print(abs(a[0] - a[1]))
else:
    now = 0
    ans = float("inf")
    for i in a[:-1]:
        now += i
        diff = abs(whole - 2 * now)
        ans = min(ans, diff)

    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

whole = a.sum()
div = np.abs(a.cumsum() - whole / 2).argmin()

if div == 0 or div == (n - 1):
    print(min(np.abs(a[0] - a[1:].sum()), np.abs(a[:-1] - a[-1].sum())))
else:
    print(np.abs(a[:div + 1].sum() - a[div + 1:].sum()))
Problem p03665 (python)

Fixed submission:
from collections import deque
import numpy as np
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

Buggy submission (verdict: Runtime Error):
from collections import deque

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

Buggy submission (verdict: Runtime Error):
from collections import deque
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
from collections import deque

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

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = comb(one, c, exact=True)
    right += tmp

print(2**zero * right)
Problem p03722 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(M)]

INF = 1 << 60
cost = [- INF] * (N + 1)
cost[1] = 0

for i in range(N):
    for n, nn, c in edge:
        if cost[nn] < cost[n] + c:
            # ワーシャルフロイド法の性質より、N回目に更新があるならinf
            if i == N - 1 and nn == N:
                print("inf")
                sys.exit()
            cost[nn] = cost[n] + c

print(cost[N])

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

INF = 1 << 60
cost = [- INF] * (N + 1)
cost[1] = 0

for i in range(N):
    for n, nn, c in edge:
        if cost[nn] < cost[n] + c:
            # ワーシャルフロイド法の性質より、N回目に更新があるならinf
            if i == N - 1 and nn == N:
                print("inf")
                sys.exit()
            cost[nn] = cost[n] + c

print(cost[N])

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
from collections import deque

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

graph = defaultdict(list)

for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))

INF = 1 << 60

cost = [- INF] * (n + 1)
cost[1] = 0
for _ in range(n):
    visited = [[False] * (n + 1) for _ in range(n + 1)]
    q = deque([1])
    while q:
        curr = q.popleft()
        for d in graph[curr]:
            n, c = d[0], d[1]
            if visited[curr][n]:
                if cost[n] < cost[curr] + c:
                    print("inf")
                    sys.exit()
                else:
                    continue
            cost[n] = max(cost[n], cost[curr] + c)
            q.append(n)
            visited[curr][n] = True

print(cost[n])
Problem p03848 (python)

Fixed submission:
import sys
from collections import Counter

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

if len(arr) % 2 == 0:
    if 0 in arr:
        print(0)
        sys.exit()
else:
    if arr.count(0) != 1:
        print(0)
        sys.exit()
    else:
        arr.remove(0)

cnt = Counter(arr)

values = list(cnt.values())

if values.count(2) != len(values):
    print(0)
    sys.exit()

mod = 10**9 + 7

print(2**(n // 2) % mod)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

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

if arr.count(0) > 1:
    print(0)
    sys.exit()

if len(arr) % 2 == 0 and arr.count(0) > 0:
    print(0)
    sys.exit()

cnt = Counter(arr)

li = list(cnt.values())

if li.count(2) != n // 2:
    print(0)
    sys.exit()

if not all([x <= 2 for x in li]):
    print(0)
    sys.exit(0)

print(reduce(mul, li))
Problem p04019 (python)

Fixed submission:
S = input()

NS = (("S" in S) & ("N" in S)) | (("S" not in S) & ("N" not in S))
EW = (("E" in S) & ("W" in S)) | (("E" not in S) & ("W" not in S))

print("Yes") if NS & EW else print("No")

Buggy submission (verdict: Runtime Error):
s = input()

ans1 = (("S" in s) and ("N" in s)) or (("S" not in s) & ("N" not in s))
ans2 = (("E" in s) and ("W" in s)) or (("E" not in s) & ("W" not in s)

print("Yes" if ans1 and ans2 else "No")
Problem p02630 (python)

Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))  # (N,)
Q = int(input())
B, C = zip(*[list(map(int, input().split())) for _ in range(Q)])  # (Q,), (Q,)

cur_sum = 0
value_count_map = collections.defaultdict(int)
for a in A:
    cur_sum += a
    value_count_map[a] += 1

for b, c in zip(B, C):
    b_cnt = value_count_map.get(b, 0)
    value_count_map[b] = 0
    value_count_map[c] += b_cnt
    cur_sum += (b_cnt * (c - b))
    print(cur_sum)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
A = list(map(int, input().split()))  # (N,)
Q = int(input())
B, C = zip(*[list(map(int, input().split())) for _ in range(Q)])  # (Q,), (Q,)

value_count_map = collections.defaultdict(int)
value_sum_map = collections.defaultdict(int)
for a in A:
    value_count_map[a] += 1
    value_sum_map[a] += a

for b, c in zip(B, C):
    b_cnt = value_count_map[b]
    value_count_map[c] += b_cnt
    value_sum_map[c] += c * b_cnt
    if b in value_count_map:
        del value_count_map[b]
        del value_sum_map[b]
    print(sum(v for v in value_sum_map.values()))
Problem p02947 (python)

Fixed submission:
import collections

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += v * (v - 1) // 2

print(ret)

Buggy submission (verdict: Runtime Error):
import collections
import math

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += int(math.factorial(v) / math.factorial(2) / math.factorial(v - 2))

print(ret)

Buggy submission (verdict: Runtime Error):
import collections
import math

n = int(input())
sl = collections.Counter([str(sorted(input())) for _ in range(n)])

ret = 0
for _, v in sl.most_common():
    if 2 <= v:
        ret += math.factorial(v) / math.factorial(2) / math.factorial(v - 2)

print(int(ret))
Problem p02694 (python)

Fixed submission:
# coding: utf-8

def main():
    x = int(input())
    
    money = 100
    i = 0
    while money < x:
        money = money * 101 // 100
        i += 1
    
    print(i)
    
main()

Buggy submission (verdict: Runtime Error):
def main():
    x = int(input())
    
    money = 100
    i = 0
    while money < x:
      	i += 1
        money = money * 101 // 100
    
    print(i)
    
main()
Problem p02981 (python)

Fixed submission:
# coding: utf-8
n,a,b = map(int, input().split())
if n*a < b:
    print(n*a)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = a*2
#a = a.reshape((a.shape[0],1))
#print(n,a)

N = np.zeros((n,n), dtype=int)
for i in range(n):
    N[i,i] = 1
    if i+1 == n:
        N[i,0] = 1
    else:
        N[i,i+1] = 1
#print(N)

ans = np.linalg.solve(N,a)
#ans = ans.reshape((ans.shape[0],))
ans = ans.astype(np.int)
print(*ans)
Problem p02995 (python)

Fixed submission:
# coding: utf-8
from sys import stdin
import sys, fractions
import numpy as np

def lcm(x,y):
    return((x*y) // fractions.gcd(x,y))


a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
#print(a, b, c, d)
#bまでで3で割り切れる数
three_all = b // c
#a-1までで3で割り切れる数
three_less = (a-1) // c
three_range = three_all - three_less
    
two_all = b // d
two_less = (a-1) // d
two_range = two_all - two_less
    
z = lcm(c,d)
six_all = b // z
six_less = (a-1) // z
six_range = six_all - six_less
    
num = three_range + two_range - six_range
    
ans = b-a+1-num
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

def lcm(x,y):
    return((x*y) // math.gcd(x,y))


a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
#print(a, b, c, d)
#bまでで3で割り切れる数
three_all = b // c
#a-1までで3で割り切れる数
three_less = (a-1) // c
three_range = three_all - three_less
    
two_all = b // d
two_less = (a-1) // d
two_range = two_all - two_less
    
z = lcm(c,d)
six_all = b // z
six_less = (a-1) // z
six_range = six_all - six_less
    
num = three_range + two_range - six_range
    
ans = b-a+1-num
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

def lcm(x,y):
    return((x*y) // math.gcd(x,y))

def main():
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    #print(a, b, c, d)
    #bまでで3で割り切れる数
    three_all = b // c
    #a-1までで3で割り切れる数
    three_less = (a-1) // c
    three_range = three_all - three_less
    
    two_all = b // d
    two_less = (a-1) // d
    two_range = two_all - two_less
    
    z = lcm(c,d)
    six_all = b // z
    six_less = (a-1) // z
    six_range = six_all - six_less
    
    num = three_range + two_range - six_range
    
    ans = b-a+1-num
    print(ans)
    
    return(ans)

if __name__ == '__main__':
    _ = main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

def lcm(x,y):
    return(x*y) // math.gcd(x,y)

def main():
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    #print(a, b, c, d)
    #bまでで3で割り切れる数
    three_all = b // c
    #a-1までで3で割り切れる数
    three_less = (a-1) // c
    three_range = three_all - three_less
    
    two_all = b // d
    two_less = (a-1) // d
    two_range = two_all - two_less
    
    z = lcm(c,d)
    six_all = b // z
    six_less = (a-1) // z
    six_range = six_all - six_less
    
    num = three_range + two_range - six_range
    
    ans = b-a+1-num
    print(ans)

if __name__ == '__main__':
    main()