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

Fixed submission:
import sys

input = sys.stdin.readline

s = input()[:-1]
t = input()[:-1]

N = len(s) + 1
M = len(t) + 1


# dp[i][j] := s[i] t[j]までのLCS
dp = [[0]*M for _ in range(N)]


for i in range(1, N):
    for j in range(1, M):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

"""
復元
もしdp[i][j] == dp[i][j-1]ならt[j-1]は使われていないことがわかる
もしdp[i][j] == dp[i-1][j]ならs[i-1]は使われていないことがわかる
それ以外の場合、s[i-1], t[j-1]が使われていることがわかる
"""

ans = ""
i = len(s)
j = len(t)

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans  # t[j-1] + ansでも同じ
        i -= 1
        j -= 1
print(ans)

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

input = sys.stdin.readline

S = input()
T = input()

def lcs(S, T):
    s = [ch for ch in S]
    t = [ch for ch in T]

    # s[:i]とt[:j]のLCS
    dp = np.empty((len(s)+1, len(t)+1), dtype="U300")

    for i in range(1, len(s)+1):
        for j in range(1, len(t)+1):
            if s[i-1] == t[j-1]:
                dp[i, j] = dp[i-1, j-1] + s[i-1]
            else:
                case1 = dp[i, j-1]
                case2 = dp[i-1, j]
                if len(case1) > len(case2):
                    dp[i, j] = case1
                else:
                    dp[i, j] = case2
    return dp[-1, -1]

print(lcs(S, T))

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

input = sys.stdin.readline

S = input()
T = input()

def lcs(S, T):
    s = [ch for ch in S]
    t = [ch for ch in T]

    # s[:i]とt[:j]のLCS
    dp = np.empty((len(s)+1, len(t)+1), dtype="U3000")

    for i in range(1, len(s)+1):
        for j in range(1, len(t)+1):
            if s[i-1] == t[j-1]:
                dp[i, j] = dp[i-1, j-1] + s[i-1]
            else:
                case1 = dp[i, j-1]
                case2 = dp[i-1, j]
                if len(case1) > len(case2):
                    dp[i, j] = case1
                else:
                    dp[i, j] = case2
    return dp[-1, -1]

print(lcs(S, T))
Problem p03494 (python)

Fixed submission:
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))

print(ans)

Buggy submission (verdict: Runtime Error):
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))

print(ans)

Buggy submission (verdict: Runtime Error):
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))

print ans

Buggy submission (verdict: Runtime Error):
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))

print ans

Buggy submission (verdict: Runtime Error):
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans

n = int(raw_input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))

print ans

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
 
multi = reduce(mul, nums)
n = 0
while multi % 2 == 0:
  nums = [i/2 for i in nums]
  multi = reduce(mul, nums)
  n += 1

print(n)

Buggy submission (verdict: Runtime Error):

N = int(input())
nums = list(map(int, input().split()))
 
multi = reduce(mul, nums)
n = 0
while multi % 2 == 0:
  nums = [i/2 for i in nums]
  multi = reduce(mul, nums)
  n += 1

print(n)

Buggy submission (verdict: Runtime Error):

N = int(input())
nums = list(map(int, input().split()))
 
multi = reduce(mul, nums)
n = 0
while multi % 2 == 0:
  nums = [i/2 for i in nums]
  multi = reduce(mul, nums)
  n += 1
 
print(n)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
  
multi = reduce(mul, nums)
n = 0
while multi % 2 == 0:
  nums = [i/2 for i in nums]
  multi = reduce(mul, nums)
  n += 1
 
print(n)

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import mul

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

multi = reduce(mul, nums)
n = 0
while multi % 2 == 0:
  nums /= 2
  multi = reduce(mul, nums)
  n += 1

print(n)
Problem p03610 (python)

Fixed submission:
string = input()
i = 1
ans = ""
for s in string:
  if i % 2 != 0:
    ans += s
  i += 1
 
print(ans)

Buggy submission (verdict: Runtime Error):
string = input()
i = 1
ans = "
for s in string:
  if i % 2 != 0:
    ans += s

print(ans)
Problem p03814 (python)

Fixed submission:
string = input()
string_list = [s for s in string]
 
def find(s, slist):
  index = []
  for i, st in enumerate(slist):
    if st == s:
      index.append(i)
  return index
 
index_of_a = find("A", string_list)
index_of_z = find("Z", string_list)
 
print(index_of_z[-1] - index_of_a[0]+1)

Buggy submission (verdict: Runtime Error):
string = input()
string_list = [s for s in string]

def find(s, slist):
  index = []
  for i, st in enumerate(slist):
    if st == s:
      index.append(i)

index_of_a = find("A", string_list)
index_of_z = find("Z", string_list)

print(index_of_z[-1] - index_of_a[0]+1)
Problem p03860 (python)

Fixed submission:
A, B, C = input().split()
print("A{}C".format(B[0]))

Buggy submission (verdict: Runtime Error):
A. B, C = input().split()
B = [b for b in B]
print("A{}C".format(B[0]))

Buggy submission (verdict: Runtime Error):
A. B, C = input().split()
print("A{}C".format(B[0]))
Problem p04030 (python)

Fixed submission:
IN = input()
OUT = []

for order in IN:
    if order == "B" and len(OUT) != 0:
        OUT.pop()
    elif order == "0" or order == "1":
        OUT.append(order)

print("".join(OUT))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = 0
for i in range(1, N+1):
  S += i
print(S)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = 0
for i in range(1, N+1):
  S += 1
print(S)
Problem p02657 (python)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
A,B=int(input().split())
print(A*B)
Problem p02713 (python)

Fixed submission:
import numpy as np
K=int(input())
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.sum())

Buggy submission (verdict: Runtime Error):
k=int(input())
    ans=0
    for x in range(1,k+1):
        for y in range(1,k+1):
            for z in range(1,k+1):
               if math.gcd(x,y)==1:
                   ans+=1
               
               elif math.gcd(math.gcd(x,y),z)==1: 
                   ans+=1
               else: 
                       ans+=math.gcd(math.gcd(x,y),z)
    print(ans)
Problem p02717 (python)

Fixed submission:
x,y,z=map(str,input().split())
print(z+" "+x+" "+y)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
count=0
for i in range(int(n)):
    if a[i]<sum(a)//(4*int(m)):
        count=count
    else:
        count+=1
if count>=int(m):
    print("Yes")
else:
    print("No")
Problem p02801 (python)

Fixed submission:
C=input()
li=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
count=li.index(C)
count=count+1
print(li[count])

Buggy submission (verdict: Runtime Error):
C=int(input())
li=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
print(li[C+1])
Problem p03060 (python)

Fixed submission:
n=int(input())
v=[int(x) for x in input().split()]
c=[int(y) for y in input().split()]

new=[v[i]-c[i] for i in range(n) if v[i]-c[i]>0]

print(sum(new))

Buggy submission (verdict: Runtime Error):
n=int(input())
v=[int(x) for x in input().split()]
c=[int(y) for y in input().split()]

new=[v[i]-c[i] for i in range(n)]
new.sort()
print(new[-2]+new[-1])
Problem p03109 (python)

Fixed submission:
def solve():
  y,m,d = map(int, input().split("/"))
  if y < 2019: 
    return "Heisei"
  elif y > 2019: 
    return "TBD"
    
  if m < 4: 
    return "Heisei"
  elif m > 4: 
    return "TBD"
    
  if d > 30: 
    return "TBD"
  return "Heisei"

print(solve())

Buggy submission (verdict: Runtime Error):
import bisect
import itertools
 
a, b, q = map(int, input().split())
ss, tt = [], []
for _ in range(a):
  ss.append(int(input()))
for _ in range(b):
  tt.append(int(input()))
  
for _ in range(q):
  x = int(input())
  md = pow(10, 15)
  xs, xt = bisect.bisect_left(ss, x), bisect.bisect_left(tt, x)
  ls, rs, lt, rt = ss[max(0, xs-1)], ss[min(a-1, xs)], tt[max(0, xt-1)], tt[min(b-1, xt)]
  for s, t in itertools.product([ls, rs], [lt, rt]):
    if s > t:
      if t > x:
        md = s - x if s - x < md else md
      elif s > x:
        if md > 2 * (s-x) + x-t:
          md = 2 * (s-x) + x-t
        if md > 2 * (x-t) + s-x:
          md = 2 * (x-t) + s-x
      else:
        md = x - t if x - t < md else md
    else:  # t > s
      if s > x:
        md = t - x if t - x < md else md
      elif t > x:
        if md > 2 * (x-s) + t-x:
          md = 2 * (x-s) + t-x
        if md > 2 * (t-x) + x-s:
          md = 2 * (t-x) + x-s
      else:
        md = x - s if x - s < md else md
  print(md)
Problem p03783 (python)

Fixed submission:
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
 
INF = 10**18
 
from heapq import heappush, heappop
 
l0, r0 = P[0]
 
L = [-l0+1]
R = [l0-1]
s = t = 0
 
res = 0
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    s += (r1 - l1); t += (r0 - l0)
    if -s-L[0] <= l1-1 <= t+R[0]:
        heappush(L, -l1+1-s)
        heappush(R, l1-1-t)
    elif l1-1 < -s-L[0]:
        heappush(L, -l1+1-s)
        heappush(L, -l1+1-s)
        p = -heappop(L)-s
        heappush(R, p-t)
        res += (p - (l1-1))
    elif t+R[0] < l1-1:
        heappush(R, l1-1-t)
        heappush(R, l1-1-t)
        p = heappop(R) + t
        heappush(L, -p-s)
        res += (l1-1 - p)
print(res)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
N = 400
if n > N: exit()

l = [0]*n
r = [0]*n
for i in range(n): 
    l[i], r[i] = list(map(int, input().split()))
dp = [[1000 for i in range(N)] for j in range(n)]

for i in range(N): #最初の段は埋めておく。
    dp[0][i] = abs(l[ni]-i)
    if i < l[ni]: 
         d = l[ni] - i
    elif r[ni] < i: 
         d = i - r[ni]
    else: 
         d = 0
    dp[0][i] = d
    
for ni in range(1,n): # 何段目で?
    for xj in range(N): # どこに接地させる?
        # このブロックをxjに持っていくコスト
        if xj < l[ni]: 
            d = l[ni] - xj
        elif r[ni] < xj:
            d = xj - r[ni]
        else: 
            d = 0 
        # 前のブロックで、xjに設置している中で最もコストの低いものに、今回のコストを加える
        min_cost = 1000
        for xk in range(N):
            d2 =  0
            if xk < xj:
                if xj <= xk+r[ni-1]:
                    min_cost = min(min_cost, dp[ni-1][xj] + d2 )
            elif xj < xk:
                if xk <= xj+r[ni]:
                    min_cost = min(min_cost, dp[ni-1][xj] + d2 ) 
            else:
                min_cost = min(min_cost, dp[ni-1][xj] + d2)
        dp[ni][xj] = min_cost+d
print(min(dp[n-1]))

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

if n>400: exit()

l = [0]*n
r = [0]*n

for i in range(n):
    l[i], r[i] = list(map(int, input().split()))

N = 400+1
dp = [[0 for i in range(N)] for j in range(n)]

# 一番上のブロックを動かした時のコスト
for i in range(N):
    if r[0] < i: d = i-r[0]
    elif i < l[0]: d = l[0]-i
    else: d = 0
    dp[0][i] = d

# 順番にコストを計算していく
for ni in range(1,n+1):
    for i in range(N):
        if r[ni] < i: d = i-r[ni]
        elif i < l[ni]: d = l[ni]-i
        else: d = 0
        dp[ni][i] = d + dp[ni-1][i]
print(min(dp[n-1]))
Problem p02663 (python)

Fixed submission:
H1, M1, H2, M2, K = map(int, input().split())

h1 = H1 * 60
m1 = M1
h2 = H2 * 60
m2 = M2

ans = (h2 + m2) - (h1 + m1) - K if (h2 + m2) > (h1 + m1) else (h2 + m2) - (h1 + m1) - K + 24 * 60

print(ans)

Buggy submission (verdict: Runtime Error):
H1, M1, H2, M2, K = map(int, input().split())

if h1 > h2:
    h2 += 24

h1 = H1 * 60
m1 = M1
h2 = H2 * 60
m2 = M2

print((h2 - m2) - (h1 + m1) - K)
Problem p02677 (python)

Fixed submission:
import math
            
A, B, H, M = map(int, input().split())

"""
h = (H / 12 + (M / 60 / 12)) * 2 * math.pi
m = M / 60 * 2 * math.pi

ax = A * math.cos(h)
ay = A * math.sin(h)

bx = B * math.cos(m)
by = B * math.sin(m)

#print(h, m, ax, ay, bx, by)

ans = ((ax-bx)**2 + (ay-by)**2 )**(1/2)

print(ans)
"""

ang = ((H / 12 + (M / 60 / 12)) - (M / 60)) * 360

#print(ang)

C = ang * math.pi / 180 if ang < 180 else (360 - ang) * math.pi / 180

#print(C / math.pi)

c2 = A**2 + B**2 - 2 * A * B * math.cos(C)

print((c2)**(1/2))

Buggy submission (verdict: Runtime Error):
A, B, H, M = map(int, input().split())


h = (H / 12 + (M / 60 / 12)) * 2 * math.pi
m = M / 60 * 2 * math.pi

ax = A * math.cos(h)
ay = A * math.sin(h)

bx = B * math.cos(m)
by = B * math.sin(m)

#print(h, m, ax, ay, bx, by)

ans = ((ax-bx)**2 + (ay-by)**2 )**(1/2)

print(ans)
Problem p02696 (python)

Fixed submission:
# -*- coding: utf-8 -*-
A,B,N = map(int, input().split())
 
def function(x):
  return (A*x)//B-A*(x//B)
 
if B-1<=N:
  print(function(B-1))
else:
  print(function(N))

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

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

s = B-1 if N > B-1 else N

x = np.arange(0, s+1)
X = A * (x % B) - (A * (x % B)) % B

print(int(np.max(X)))

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

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

#s = B if N > B else N
#print(s)

x = np.arange(0, N+1)
x1 = np.floor(A * x / B)
x2 = A * np.floor(x / B)
X =  x1 - x2

print(int(np.max(X)))

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

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

s = B if N > B else N
#print(s)

x = np.arange(0, int(s/2))
X = np.floor(A * x / B) - A * np.floor(x / B)

print(int(np.max(X)))

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

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

s = B if N > B else N
#print(s)

x = np.arange(0, s+1)
X = np.floor(A * x / B) - A * np.floor(x / B)

print(int(np.max(X)))

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

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

x = np.arange(0, N+1)
X = np.floor(A * x / B) - A * np.floor(x / B)

print(int(np.max(X)))

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

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

X = np.arange(1, N+1)
X = np.floor(A * X / B) - A * np.floor(X / B)

print(int(np.max(X)))
Problem p02700 (python)

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

while True:
    C -= B
    #print(C)
    if C <= 0:
        print("Yes")
        break
    A -= D
    #print(A)
    if A <= 0:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
while True:
    C -= B
    if C <= 0:
        print("Yes")
        break
    A -= D
    if D <= 0:
        print("No")
        break
Problem p02702 (python)

Fixed submission:
S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    #print("S_[i]:", S_[i])
    #print("int(S_[i])*x:", int(S_[i])*x)
    #print("total:", total)
    total += int(S_[i])*x
    #print("total:", total)
    total %= m
    #print("total:", total)
    ans += modlis[total]
    #print("x:", x)
    x = x * 10 % m
    #print("x:", x)

print(ans)

Buggy submission (verdict: Runtime Error):
import re
S = input()

s = []
for i in range(1000):
    s.append(str(i*2019))

count = []
for i in s:
    count += len(re.findall(S, i))

print(count)

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

count = 0
for j in range(4, len(S)+1):
    for i in range(len(S)-4):
        if S[i:i+4] % 2019 == 0:
            count += 1

print(count)
Problem p02706 (python)

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

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

sub = N - sum(A)

if sub >= 0:
    print(sub)
else:
    print(-1)

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

A = 0
for i in range(M):
    s = int(input())
    A += s

sub = N - A

if sub >= 0:
    print(sub)
else:
    print(-1)
Problem p02814 (python)

Fixed submission:
import sys
N,M=map(int,input().split())
A=list(set(map(int,input().split())))
N=len(A)
A=[a//2 for a in A]
 
def f(x):
    cnt=0
    while x%2==0:
        x//=2
        cnt+=1
    return cnt
C=f(A[0])
for a in A:
    if f(a)!=C:
        print(0)
        sys.exit()
def lcm(x,y):
    xy=x*y
    while y!=0:
        x,y=y,x%y
    return xy//x
LCM=A[0]
for i in range(1,N):
    LCM=lcm(LCM,A[i])
if LCM>M:
    ans=0
else:
    M//=LCM
    ans=(M+1)//2
print(ans)

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

### 解説より、
while not any(x % 2 for x in A):
    A = [i // 2 for i in A]
 
if not all(x % 2 for x in A):
    print(0)
    exit()
### ###

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b // gcd(a, b)

ans = A[0]
for i in range(1, N):
    ans = lcm(ans, A[i])
    
print((M // ans + 1) // 2)
Problem p03074 (python)

Fixed submission:

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

a = []
f = S[0]
l = 0
for i in range(1, N+1):
    if f != S[i]:
        a.append(i-l)
        l = i
        f = S[i]
        

if S[0] == '0':
    a = [0] + a

SUM = sum(a[0:0+2*K+1])

MAX = max(0, SUM)
for i in range(2, len(a)):
    if i % 2 == 0:
        try:
            SUM = SUM - (a[i-2]+a[i-1]) + (a[i+2*K-1]+a[i+2*K])
        except:
            try:
                SUM = SUM - (a[i-2]+a[i-1]) + (a[i+2*K-1])
            except:
                break
        
        MAX = max(MAX, SUM)


print(MAX)

Buggy submission (verdict: Runtime Error):

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

a = []
f = S[0]
l = 0
for i in range(1, N+1):
    #print(S[i])
    if f != S[i]:
        #a.append([l, i-1, int(f)])
        #a.append([i-l, int(f)])
        a.append(i-l)
        l = i
        f = S[i]
        
#print(a)

if S[0] == '0':
    a = [0] + a

#print(a[0:0+2*K+1])
SUM = sum(a[0:0+2*K+1])

MAX = max(0, SUM)
for i in range(1, len(a)//2+len(a)%2):
    if i % 2 == 0:
        #print(a[i:i+2*K+1])
        #print(a[i-2], a[i-1])
        #print(a[i+2*K-1], a[i+2*K])
        #print(sum(a[i:i+2*K+1]))
        #MAX = max(MAX, sum(a[i:i+2*K+1]))
        SUM = SUM-(a[i-2]+a[i-1])+(a[i+2*K-1]+a[i+2*K])
        MAX = max(MAX, SUM)

print(MAX)
Problem p02924 (python)

Fixed submission:


def main():
    n = int(input())
    print( (n * (n- 1) ) // 2)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):


def main():
  n = int(input())
  print((n - 1) * n) // 2)



if __name__ == "__main__":
  main()
Problem p03997 (python)

Fixed submission:

	
def main():	
	x = int(input())
	y = int(input())
	h = int(input())
	print(((x + y) * h) // 2)
 
if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):

	
def main():
	linie = input()
	vector = [int(x) for x in linie.split()]	
	x = vector[0]
	y = vector[1]
	h = vector[2]
	print(((x + y) * h) // 2)
 
if __name__ == "__main__":
	main()
Problem p02973 (python)

Fixed submission:
import bisect
from collections import deque
N = int(input())
nums = deque()

for i in range(N):
    temp =  int(input())
    ind = bisect.bisect_left(nums, temp)
    if ind == 0:
        nums.appendleft(temp)
    else:
        nums[ind - 1] = temp
print(len(nums))

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = [int(input()) for _ in range(N)]
ans = 0
nums_sorted = nums[:]
nums_sorted = list(set(nums_sorted))
nums_sorted.sort(reverse=True)
di = {}





for i in range(N-1):
    if nums[i] > nums[i+1]:
        ans += 1

nums_l = len(nums)
nums_s = len(list(set(nums)) )
ans += nums_l - nums_s
if len(nums_s) == 1:
    ans += 1



print(ans)
Problem p02991 (python)

Fixed submission:
from sys import stdin
from collections import defaultdict
from collections import deque

N,M = list(map(int,stdin.readline().split()))
Cs = [tuple(map(int,stdin.readline().split())) for _ in range(M)]
S,T = list(map(int,stdin.readline().split()))

INF = 10 ** 15
# visit = [False] * ( (N + 1) * 3 )
dist  = [-1] * ( (N) * 3 + 1 )
graph_connection = defaultdict(lambda :[])
graph_cost = defaultdict(lambda :defaultdict(lambda :INF))
#
# def dfs(v,dist_before):
#
#     dist[v] = dist_before + 1
#     next_vertexs = graph_connection[v]
#     for next_v  in next_vertexs :
#         if dist[next_v] == -1:
#             dfs(next_v,dist[v])
#     return 0
#

for cost in  Cs:
    a,b= cost
    for i in range(0,3):
        from_v = a + (i) * N
        to_v = b + (i + 1) % 3 * N
        graph_connection[from_v].append(to_v )

        # from_v = b + (i) * N
        # to_v = a + (i + 1) % 3 * N
        # graph_connection[from_v].append(to_v )

# dist[S] = 0


que = deque()
#(from_v,to_v)
dist[S] = 0
que.append(S)
while len(que) != 0:
    from_v = que.popleft()
    nexts = graph_connection[from_v]
    for next_v in nexts:
        if dist[next_v] == -1:
            dist[next_v] = dist[from_v] + 1
            que.append(next_v)

if dist[T] < 0:
    print(dist[T] )
else:
    print(dist[T]//3)

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

N,M = list(map(int,stdin.readline().split()))
Cs = [tuple(map(int,stdin.readline().split())) for _ in range(M)]
S,T = list(map(int,stdin.readline().split()))

INF = 10 ** 15
# visit = [False] * ( (N + 1) * 3 )
dist  = [-1] * ( (N) * 3 + 1 )
graph_connection = defaultdict(lambda :[])
graph_cost = defaultdict(lambda :defaultdict(lambda :INF))
#
# def dfs(v,dist_before):
#
#     dist[v] = dist_before + 1
#     next_vertexs = graph_connection[v]
#     for next_v  in next_vertexs :
#         if dist[next_v] == -1:
#             dfs(next_v,dist[v])
#     return 0
#

for cost in  Cs:
    a,b= cost
    for i in range(0,3):
        from_v = a + (i) * N
        to_v = b + (i + 1) % 3 * N
        graph_connection[from_v].append(to_v )

        # from_v = b + (i) * N
        # to_v = a + (i + 1) % 3 * N
        # graph_connection[from_v].append(to_v )

# dist[S] = 0


que = deque()
#(from_v,to_v)
que.append((S,S))

while not que.empty():
    from_v, to_v = que.popleft()
    dist[to_v] = dist[from_v] + 1
    for next_v in graph_connection[to_v]:
        if dist[next_v] == -1:
            que.appendleft((to_v,next_v))
if dist[T] < 0:
    print(dist[T] )
else:
    print(dist[T]//3)
Problem p02995 (python)

Fixed submission:
import  fractions

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


def do():
    A,B,C,D =  list(map(int,input().split(" ")))
    CD = lcm(C,D)
    A1 = A- 1
    ans = (B//C + B//D - B//CD) - (A1//C + A1//D - A1//CD)
    ans = (B-A+1) - ans
    print(ans)

if __name__ == "__main__":
    do()

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def do():
    A,B,C,D =  list(map(int,input().split(" ")))
    CD = lcm(C,D)
    A1 = A- 1
    ans = (B//C + B//D - B//CD) - (A1//C + A1//D - A1//CD)
    ans = (B-A+1) - ans
    print(ans)

if __name__ == "__main__":
    do()

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D =  list(map(int,input().split(" ")))
CD = lcm(C,D)
A1 = A- 1
ans = (B//C + B//D - B//CD) - (A1//C + A1//D - A1//CD)



ans = (B-A+1) - ans
print(ans)