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

Fixed submission:
N=int(input())
##c=list(map(int, input().split()))

a = [list(map(int, input().split())) for _ in range(N)]

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))**0.5

print(k/N)

Buggy submission (verdict: Runtime Error):
N=int(input())
##c=list(map(int, input().split()))
a=[]
b=[]
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))**0.5

print(k/N)

Buggy submission (verdict: Runtime Error):
N=int(input())
##c=list(map(int, input().split()))
a={}
b={}
for i in range(N):
    a[i]=int(input())
    b[i]=int(input())

k=float(0)
for i in range(N-1):
    for j in range(i+1,N-i-1):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Buggy submission (verdict: Runtime Error):
N=int(input())
##c=list(map(int, input().split()))
a={}
b={}
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Buggy submission (verdict: Runtime Error):
N=int(input())
##c=list(map(int, input().split()))
a=[]
b=[]
for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+((a[i]-a[j])**2+(b[i]-b[j])**2)**0.5

k=float(k*2/N)
print(k)

Buggy submission (verdict: Runtime Error):
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))


a=[]
b=[]


for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(((a[i]-a[j])**2+(b[i]+b[j])**2)**0.5)

k=float(k*2/N)
print(k)

Buggy submission (verdict: Runtime Error):
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))

a=[]
b=[]


for i in range(N):
    a.append(int(input()))
    b.append(int(input()))
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(((a[i]-a[j])**2+(b[i]+b[j])**2)**0.5)

k=float(k*2/N)
print(k)

Buggy submission (verdict: Runtime Error):
import math
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))


a=[]
b=[]

for i in range(N):
    a.append(input())
    b.append(input())
k=float(0)
for i in range(N-1):
    for j in range(i,N):
        k=k+float(math.sqrt(abs(a[i]-a[j])+abs(b[i]+b[j])))

k=float(k*2/N)
print(k)
Problem p02898 (python)

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

z=0
for i in v:
    if i>=K:
         z=z+1

print(z)

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

z=0
for i in range(v):
    if i>=K:
         z=z+1

print(z)
Problem p02899 (python)

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

N=int(input())
c=list(map(int, input().split()))
v=[0]*N
for i in range(N):
    v[c[i]-1]=i

for i in v:
    print(i+1)
    print(" ")

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

v=[0]*N
for i in range(N):
    c=int(input())
    v[c-1]=i

for i in v:
    print(i+1)
    print(" ")

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

v=[0]*N
for i in range(N):
    c=input()
    v[c]=i

for i in v:
    print(i+" ")
Problem p02922 (python)

Fixed submission:
(a,b)=map(int,input().split())
k=int(1)
z=0
while(k<b):
    z+=1
    k+=a-1

print(z)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
k=int(1)
z=0
while(k<b):
    z+=1
    k+=a-1

print(z)
Problem p02995 (python)

Fixed submission:
import math
import fractions
(a,b,c,d)=map(int,input().split())
g=c*d//fractions.gcd(c,d)
k=0
k+=b//c+b//d-b//g-int(a-1)//c-(a-1)//d+(a-1)//g

print(b-a+1-k)

Buggy submission (verdict: Runtime Error):
import math
import fractions
(a,b,c,d)=map(int,input().split())
g=int(c*d/math.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)

print(b-a+1-k)

Buggy submission (verdict: Runtime Error):
import math
(a,b,c,d)=map(int,input().split())
g=int(c*d/math.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)
print(b-a+1-k)

Buggy submission (verdict: Runtime Error):
import math
(a,b,c,d)=map(int,input().split())
g=int(c*d/math.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)

print(b-a+1-k)
Problem p03037 (python)

Fixed submission:
#n=int(input())
#s,t=input().split()
n,m = map(int, input().split())
#l=list(map(int, input().split()))
l=[0]*100005
r=[1000005]*100005
z=1000010
for i in range(m):
   l[i],r[i]=map(int,input().split()) 
mi=max(l)
ma=min(r)



if mi>ma:
    print(0)
else:
    print(ma-mi+1)

Buggy submission (verdict: Runtime Error):
#n=int(input())
#s,t=input().split()
n,m = map(int, input().split())
#l=list(map(int, input().split()))
l=[0]*100005
r=[1000005]*100005
z=1000010
for i in range(m):
   l[i],r[i]=map(int,input().split()) 
mi=max(l)
ma=min(r)



if mi>ma:
    print(0)
else
    print(ma-mi+1)
Problem p03633 (python)

Fixed submission:
def gcd (a, b):
	while a:
		a, b = b % a, a
	return b

def lcm (a, b):
	return a // gcd(a, b) * b

n = int(input())
g = 1
for _ in range(n):
	t = int(input())
	g = lcm(t, g)
print(g)

Buggy submission (verdict: Runtime Error):
import math

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

n = int(input())
g = 1
for _ in range(n):
	t = int(input())
	g = lcm(t, g)
print(g)
Problem p02783 (python)

Fixed submission:
h,a = map(int, input().split())
print(((h+a-1)//a))

Buggy submission (verdict: Runtime Error):
h,a = map(int, input.split())
print(((h+a-1)//a))
Problem p03390 (python)

Fixed submission:
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    left=0
    right=a*b
    for i in range(100):
        mid=(left+right)//2
        if mid*mid<a*b:
            left=mid
        else:
            right=mid
    ret=left*2
    if ret==0:
        print(ret)
        continue
    if (a*b-1)//left==left:
        ret-=1
    if min(a,b)<=left:
        ret-=1
    print(ret)

Buggy submission (verdict: Runtime Error):
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    left=0
    right=a*b
    for i in range(100):
        mid=(left+right)//2
        if mid*mid<a*b:
            left=mid
        else:
            right=mid
    ret=left*2
    if (a*b-1)//left==left:
        ret-=1
    if min(a,b)<=left:
        ret-=1
    print(ret)

Buggy submission (verdict: Runtime Error):
q=int(input())
while q>0:
    q-=1
    a,b=map(int,input().split())
    s=int((a*b-1)**0.5)
    ret=2*s
    if (a*b-1)//s==s:
        ret-=1
    if min(a,b)<=s:
        ret-=1
    print(ret)
Problem p03394 (python)

Fixed submission:
n=int(input())
ret=[2,3,4] if n>=6 else [2,5,63] if n==3 else [2,5,20,63] if n==4 else [2,5,20,30,63]
if n>=6:
    def getnext(a):
        if a%6==0:
            return a+2
        elif a%6==2:
            return a+1
        elif a%6==3:
            return a+1
        elif a%6==4:
            return a+2
    while len(ret)<n:
        ret.append(getnext(ret[-1]))
    if sum(ret)%6==5:
        ret[-1]=getnext(ret[-1])
    elif sum(ret)%6!=0:
        ret.remove((sum(ret)%6)+6)
        ret.append(getnext(ret[-1]))
        while sum(ret)%6!=0:
            ret[-1]=getnext(ret[-1])
print(" ".join(map(str,ret)))

Buggy submission (verdict: Runtime Error):
n=int(input())
ret=[2,3,4] if n>=6 else [2,3,25] if n==3 else [2,3,5,30] if n==4 else [2,3,5,30,60]
if n>=6:
    def getnext(a):
        if a%6==0:
            return a+2
        elif a%6==2:
            return a+1
        elif a%6==3:
            return a+1
        elif a%6==4:
            return a+2
    while len(ret)<n:
        ret.append(getnext(ret[-1]))
    if sum(ret)%6==5:
        ret[-1]=getnext(ret[-1])
    elif sum(ret)%6!=0:
        ret.remove((sum(ret)%6)+6)
        ret.append(getnext(ret[-1]))
        while sum(ret)%6!=0:
            ret[-1]=getnext(ret[-1])
    print(" ".join(map(str,ret)))
else:
    print(" ".join(ret))
Problem p04001 (python)

Fixed submission:
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10+int(s[idx]), idx+1)
    return ret1+ret2
# 最初の文字の左側には+は入れる必要が無いので1から
print(solve(0,int(s[0]),1))

Buggy submission (verdict: Runtime Error):
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10int(s[idx]), idx+1)
    return ret1+ret2
print(solve(0,int(s[0]),1))
Problem p02797 (python)

Fixed submission:
from sys import stdin

N, K, S = [int(x) for x in stdin.readline().rstrip().split()]
    
ans = [S] * K
if S == 10 ** 9:
    ans.extend([1] * (N - K))
else:
    ans.extend([S + 1] * (N - K))

print(*ans)

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

N, K, S = [int(x) for x in stdin.readline().rstrip().split()]

ans = [S] * K
n = (N - K) // (S - 1)
ans.extend([S + 1] * (N - K))

print(*ans)
Problem p02804 (python)

Fixed submission:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()
c = 1
ans = 0
inf = 10 ** 9 + 7
fact_list = [1] * (N + 1)
fact_inv = [1] * (N + 1)
f = 1

for i in range(1, N + 1):
    f *= i
    f %= inf
    fact_list[i] = f

for i in range(1, N + 1):
    fact_inv[i] = pow(fact_list[i], inf - 2, inf)

for i in range(N - K + 1):
    tmp_min = A[i]
    tmp_max = A[N - i - 1]
    d = (tmp_max - tmp_min) % inf
    n = fact_list[N - i - 1] * fact_inv[K - 1] * fact_inv[N - i -K] % inf
    ans += d * n
    ans %= inf

print(int(ans))

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

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()
c = 1
ans = 0
inf = 10 ** 9 + 7
fact_list = [0] * (N + 1)
fact_list[0] = 1
f = 1

for i in range(1, N + 1):
    f *= i
    fact_list[i] = f

for i in range(N - K + 1):
    tmp_min = A[i]
    tmp_max = A[N - i - 1]
    d = (tmp_max - tmp_min) % inf
    n = (fact_list[N - i - 1] / fact_list[K - 1] / fact_list[N - i -K]) % inf
    ans += d * n
    ans %= inf

print(int(ans))

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

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()
c = 1
ans = 0
inf = 10 ** 9 + 7
fact_list = [0] * (N + 1)
fact_list[0] = 1
f = 1

for i in range(1, N + 1):
    f *= i
    fact_list[i] = f

for i in range(N - K + 1):
    tmp_min = A[i]
    tmp_max = A[N - i - 1]
    d = (tmp_max - tmp_min) % inf
    n = (fact_list[N - i - 1] / fact_list[K - 1] / fact_list[N - i -K]) % inf
    ans += (tmp_max - tmp_min) * n
    ans %= inf

print(int(ans))

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

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()
c = 1
ans = 0
inf = 10 ** 9 + 7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


for i in range(N - K + 1):
    tmp_min = A[i]
    tmp_max = A[N - i - 1]
    n = (factorial(N - i - 1) / factorial(K - 1) / factorial(N - i -K)) % inf
    ans += (tmp_max - tmp_min) * n
    ans %= inf

print(int(ans))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()
c = 1
ans = 0
inf = 10 ** 9 + 7

for i in range(N - K + 1):
    tmp_min = A[i]
    tmp_max = A[N - i - 1]
    n = (math.factorial(N - i - 1) / math.factorial(K - 1) / math.factorial(N - i -K)) % inf
    ans += (tmp_max - tmp_min) * n
    ans %= inf

print(int(ans))
Problem p02814 (python)

Fixed submission:
from sys import stdin
import fractions

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // fractions.gcd(g % A[i], A[i])
    if g > M:
        print(0)
        exit()

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // math.gcd(g % A[i], A[i])

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // math.gcd(g, A[i])

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)
Problem p02882 (python)

Fixed submission:
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if x == (a ** 2) * b:
    print(0)
    exit()
if 2 * x >= (a ** 2) * b:
    v = (a ** 2) * b - x
    c = (2 * v) / (a ** 2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if 2 * x >= (a ** 2) * b:
    v = (a ** 2) * b - x
    c = (2 * v) / (a ** 2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)
Problem p02900 (python)

Fixed submission:
from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)
C = []
y = 1
while y ** 2 <= gcd:
    if gcd % y == 0:
        if y >= 2:
            C.append(y)
        if y ** 2 != gcd:
            C.append(gcd // y)
    y += 1

ans = 1
g = 1
C.sort()
for c in C:
    while gcd % c == 0:
        gcd //= c
        if g != c:
            ans += 1
        g = c

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = math.gcd(A, B)

x = 2
ans = 1
g = 1

while gcd > 1:
    if gcd % x == 0:
        gcd //= x
        if g != x:
            ans += 1
        g = x
    else:
        x += 1

print(ans)
Problem p02904 (python)

Fixed submission:
from sys import stdin
from collections import deque

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]

ans = N - K + 1

D = deque([x for x in P[:K]])
oc = 0
ordered_twice = False

for i in range(len(D) - 1):
    if D[i] <= D[i + 1]:
        oc += 1

Q = deque([])
Q_min = []
Q_max = []

for i in range(N):
    while len(Q) > 0 and P[Q[len(Q) - 1]] >= P[i]:
        Q.pop()
    Q.append(i)
    if Q[len(Q) - 1] >= K - 1:
        Q_min.append(P[Q[0]])
        if Q[0] == i + 1 - K:
            Q.popleft()

PP = [-x for x in P]
Q = deque([])

for i in range(N):
    while len(Q) > 0 and PP[Q[len(Q) - 1]] >= PP[i]:
        Q.pop()
    Q.append(i)
    if Q[len(Q) - 1] >= K - 1:
        Q_max.append(-PP[Q[0]])
        if Q[0] == i + 1 - K:
            Q.popleft()

for i in range(N - K + 1):
    if i > 0:
        D.popleft()
        D.append(P[i + K - 1])
        if P[i - 1] <= D[0]:
            oc -= 1
        if D[K - 2] <= D[K - 1]:
            oc += 1

        if (Q_min[i - 1] == P[i - 1] and Q_max[i] == D[-1]) or (oc == K - 1 and ordered_twice):
            ans -= 1

    if oc == K - 1:
        ordered_twice = True

print(ans)

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

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
Q_max = [-x for x in P[:K]]
Q_min = [x for x in P[:K]]
heapq.heapify(Q_min)
heapq.heapify(Q_max)
D = deque([x for x in P[:K]])
oc = 0
ordered_twice = False

for i in range(len(D) - 1):
    if D[i] <= D[i + 1]:
        oc += 1

for i in range(N - K + 1):
    if i == 0:
        ans += 1
        if oc == K - 1:
            ordered_twice = True
    else:
        D.popleft()
        D.append(P[i + K - 1])
        if P[i - 1] <= D[0]:
            oc -= 1
        if D[K - 2] <= D[K - 1]:
            oc += 1
        if oc == K - 1:
            if not ordered_twice:
                ordered_twice = True
                if P[i - 1] > Q_min[0] or D[K - 1] < -Q_max[0]:
                    ans += 1
        else:
            if P[i - 1] > Q_min[0] or D[K - 1] < -Q_max[0]:
                ans += 1
        if P[i - 1] == Q_min[0]:
            heapq.heappop(Q_min)
        if P[i - 1] == -Q_max[0]:
            heapq.heappop(Q_max)
        if D[K - 1] >= -Q_max[0]:
            heapq.heappush(Q_max, -D[K - 1])
        if D[K - 1] <= Q_min[0]:
            heapq.heappush(Q_min, D[K - 1])

print(ans)
Problem p02913 (python)

Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        res = max(res, min(j - i, dp[i][j]))

print(res)

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

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1, dp[i][j]
        res = max(res, min(j - i, dp[i][j]))

print(res)
Problem p02953 (python)

Fixed submission:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]
drop = 0

if N == 1:
    print('Yes')
    exit()

if N == 2:
    if H[0] - H[1] > 1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()

for i in range(N - 2, -1, -1):
    if H[i] - H[i + 1] > 1:
        print('No')
        exit()
    if H[i] - H[i + 1] == 1:
        H[i] -= 1
print('Yes')

Buggy submission (verdict: Runtime Error):
N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0

if N == 1:
    print('Yes')
    exit()

if N == 2:
    if H[0] - H[1] > 1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()

for i in range(1, N):
    if H[i - 1] - H[i] > 1:
        print('No')
        exit()
    elif H[i - 1] - H[i] == 1:
        if cnt > 0:
            print('No')
            exit()
        H[i] -= 1
        cnt += 1

print('Yes')
Problem p02995 (python)

Fixed submission:
from sys import stdin
import fractions

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]


def div(n, x, y):
    lcs = int(x * y / fractions.gcd(x, y))
    return n - int(n // x) - int(n // y) + int(n // lcs)


print(div(B, C, D) - div(A - 1, C, D))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]


def div(n, x, y):
    lcs = int(x * y / math.gcd(x, y))
    return n - int(n // x) - int(n // y) + int(n // lcs)


print(div(B, C, D) - div(A - 1, C, D))
Problem p03074 (python)

Fixed submission:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
if len(S) == 1:
    run.append(1)
else:
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            cnt += 1
        else:
            run.append(cnt)
            cnt = 1
        if i == len(S) - 1:
            run.append(cnt)
if S[0] == '0':
    run = [0] + run
if S[N - 1] == '0':
    run = run + [0]
if len(run) < 2 * K + 1:
    print(sum(run))
    exit()
ans = sum(run[0: 2 * K + 1])
sb = ans
for j in range(2, len(run) - 2 * K):
    if j % 2 == 1:
        continue
    else:
        sb = sb - run[j - 1] - run[j - 2] + run[j + 2 * K] + run[j + 2 * K - 1]
        if sb > ans:
            ans = sb
print(ans)

Buggy submission (verdict: Runtime Error):
rom sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
cnt = 1
run = []
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        cnt += 1
    else:
        run.append(cnt)
        cnt = 1
    if i == len(S) - 1:
        run.append(cnt)
X = [sum(run[j: j + 2 * K + 1]) for j in range(max(len(run) - 2 * K, 1))]
if len(X) == 0:
    print(1)
else:
    print(max(X))
Problem p03111 (python)

Fixed submission:
from sys import stdin

# ABC
# N = int(stdin.readline().rstrip())


def dfs(x):
    ret = 0
    if int(x) > N:
        return ret
    if '7' in x and '5' in x and '3' in x:
        ret += 1
    for k in '753':
        ret += dfs(x + k)
    return ret


# print(dfs('0'))

# ABC119 C - Synthetic Kadomatsu
N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(stdin.readline().rstrip()) for _ in range(N)]


def solve(m, a, b, c):
    if m == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 7
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    return min(solve(m + 1, a, b, c), solve(m + 1, a + l[m], b, c) + 10,
               solve(m + 1, a, b + l[m], c) + 10, solve(m + 1, a, b, c + l[m]) + 10)


print(solve(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(stdin.readline().rstrip()) for _ in range(N)]


def solve(m, a, b, c):
    if m == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 7
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    return min(solve(m + 1, a, b, c), solve(m + 1, a + l[m], b, c) + 10,
               solve(m + 1, a, b + l[m], c) + 10, solve(m + 1, a, b, c + l[m]) + 10)


print(solve(0, 0, 0, 0))