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

Fixed submission:
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K+1)/N
    for k in range(1, K):
        r = math.ceil(math.log(K / k,2))
        pro += 0.5**r / N
    print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log(K / k,2))
        pro += 0.5**r / N
    print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K+1)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>K:
    pro+=(N-K)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
    print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
        print(pro)

else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
        print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N==1 and K==1:
    print(1)
elif N>=K:
    pro+=(N-K)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
print(pro)

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())
pro=0
if N>=K:
    pro+=(N-K)/N
    for k in range(1, K):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
else:
    for k in range(1, N+1):
        r = math.ceil(math.log2(K / k))
        pro += 0.5**r / N
print(pro)
Problem p03196 (python)

Fixed submission:
import math
from collections import Counter
N, P = map(int, input().split())
if P == 1:
    print(1)
elif N == 1:
    print(P)
else:
    Eratosthenes = [p for p in range(2, math.ceil(P ** 0.5))]
    number = Eratosthenes[0]
    sosuu = []
    while number < P ** 0.25:
        sosuu.append(number)
        n_Eratosthenes = []
        for n in Eratosthenes:
            if n % number == 0:
                pass
            else:
                n_Eratosthenes.append(n)
        if len(n_Eratosthenes) == 0:
            break
        number = n_Eratosthenes[0]
        Eratosthenes = n_Eratosthenes
    numbers=sosuu+Eratosthenes
    suuji=0
    answers=[]
    while P>1 and suuji<len(numbers):
        number=numbers[suuji]
        if P%number==0:
            answers.append(number)
            P=P//number
        else:
            suuji+=1
    kotae=Counter(answers)
    answer=1
    for key,value in kotae.items():
        kazu=value//N
        if kazu==0:
            continue
        else:
            answer*=(key**kazu)
    print(answer)

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter
N, P = map(int, input().split())
if P == 1:
    print(1)
elif N == 1:
    print(P)
else:
    Eratosthenes = [p for p in range(2, math.ceil(P ** 0.5))]
    number = Eratosthenes[0]
    sosuu = []
    while number < P ** 0.25:
        sosuu.append(number)
        n_Eratosthenes = []
        for n in Eratosthenes:
            if n % number == 0:
                pass
            else:
                n_Eratosthenes.append(n)
        if len(n_Eratosthenes) == 0:
            break
        number = n_Eratosthenes[0]
        Eratosthenes = n_Eratosthenes
    numbers=sosuu+Eratosthenes
    suuji=0
    answers=[]
    while P>1:
        number=numbers[suuji]
        if P%number==0:
            answers.append(number)
            P=P//number
        else:
            suuji+=1
    kotae=Counter(answers)
    answer=1
    for key,value in kotae.items():
        if value>=N:
            answer*=key
    print(answer)
Problem p03351 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
if abs(c-a)<=d:
    print('Yes')
elif abs(a-b)<=d and abs(b-c)<=d:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=input()
K=int(input())
answers=[]
S=[a for a in s]
N=len(S)
for a in range(N):
    number = 0
    while a + number <= N and number<=K:
        z = S[a:a + number]
        answers.append(z)
        number += 1
kotae = []
for a in answers:
    if a in kotae:
        pass
    else:
        kotae.append(a)
kotae = sorted(kotae)
answer=kotae[K]
moji=''
for a in answer:
    moji+=a
print(moji)
Problem p03380 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
sort_A=sorted(A)
max_A=sort_A[-1]
answer=[]
half_A=max_A//2
number=pow(10,9)
answer=0
for n in range(N-1):
    if number>=abs(sort_A[n]-half_A):
        answer=n
        number=abs(sort_A[n]-half_A)
print(max_A,sort_A[answer])

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(*A)
else:
    A=sorted(A)
    ans1=A[-1]
    del A[-1]
    saidai=ans1/2
    num=pow(10,9)
    for n in range(N-2):
        if abs(saidai-A[n])<=num:
            num=abs(saidai-A[n])
        else:
            ans2=n-1
    print(ans1,A[ans2])
Problem p03474 (python)

Fixed submission:
A,B=map(int,input().split())
S=input()
number=0
list=['0','1','2','3','4','5','6','7','8','9']
for a in range(A):
    if S[a] in list:
        number+=1
if S[A]=='-':
    number+=1
for a in range(B):
    if S[A+a+1] in list:
        number+=1
if number==A+B+1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
number=0
list=['0','1','2','3','4'.'5','6','7','8','9']
for a in range(A):
    if S[a] in list:
        number+=1
if S[A]=='-':
    number+=1
for a in range(B):
    if S[A+a+1] in list:
        number+=1
if number==A+B+1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
number=0
list=[0,1,2,3,4,5,6,7,8,9]
for a in range(A):
    if int(S[a]) in list:
        number+=1
if S[A]=='-':
    number+=1
for a in range(B):
    if int(S[A+a+1]) in list:
        number+=1
if number==A+B+1:
    print('Yes')
else:
    print('No')
Problem p03565 (python)

Fixed submission:
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1


        if number == TN:
            e += c
            suuji += number
            numbers.append(e)
    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        a=numbers[-1]
        A = int(a)
        moji = ''
        for b in range(TN):
            B = int(b)
            listSS[A + B] = listT[B]
        for z in listSS:
            moji += z

        answer = moji.replace('?', 'a')
        print(answer)

Buggy submission (verdict: Runtime Error):
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1
            if number == TN:
                e += c
                suuji += number
                numbers.append(e)

    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        for a in range(TN):
            for b in numbers:
                listSS[b+ a] = listT[a]
                moji = ''
                mojiretu=[]
                for a in listSS:
                    moji += a
                answer = moji.replace('?', 'a')
                mojiretu.append(answer)
                kotae=sorted(mojiretu)
        print(kotae[0])
Problem p03569 (python)

Fixed submission:
from collections import deque
S=input()
deque_S=deque(S)
flag=0
ans=0
while True:
    if len(deque_S)<=1:
        break
    if deque_S[0] == deque_S[-1]:
        deque_S.pop()
        deque_S.popleft()
    else:
        if deque_S[0] == 'x':
            ans+=1
            deque_S.popleft()
        elif deque_S[-1] == 'x':
            ans+=1
            deque_S.pop()
        else:
            flag=1
            break
if flag==1:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
S=input()
deque_S=deque(S)
flag=0
ans=0
while True:
    if deque_S[0] == deque_S[-1]:
        deque_S.pop()
        deque_S.popleft()
    else:
        if deque_S[0] == 'x':
            ans+=1
            deque_S.pop()
        elif deque_S[-1] == 'x':
            ans+=1
            deque_S.popleft()
        else:
            flag=1
            break
    if len(deque_S)<=1:
        break
if flag==1:
    print(-1)
else:
    print(ans)
Problem p03611 (python)

Fixed submission:
N=int(input())
A=[0]*(10**5+1)
b=input().split()
numbers=[int(a) for a in b]
for a in numbers:
    A[a]+=1
list=[]
for z in range(10**5-1):
    y=A[z]+A[z+1]+A[z+2]
    list.append(y)
print(max(list))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[0]*10**5
b=input().split()
numbers=[int(a) for a in b]
for a in numbers:
    A[a-1]+=1
list=[]
for z in range(10**5-1):
    y=A[z]+A[z+1]+A[z+2]
    list.append(y)
print(max(list))
Problem p03633 (python)

Fixed submission:
import fractions
N=int(input())
list=[]
for a in range(N):
    T=int(input())
    list.append(T)
ans=list[0]
for z in range(1,N):
    ans=ans*list[z]//fractions.gcd(ans,list[z])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N=int(input())
list=[]
for a in range(N):
    T=int(input())
    list.append(T)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm(*list))

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
list=[]
for a in range(N):
    T=int(input())
    list.append(T)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm(*list))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N=int(input())
list=[]
for a in range(N):
    T=int(input())
    if T in list:
        continue
    else:
        list.append(T)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm(*list))
Problem p03659 (python)

Fixed submission:
N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = 0
    del A[0]
    del A[-1]
    for a in range(N - 1):
        number += A[a]
        if number >= average:
            break
    a1 = abs(sum(A[:a]) + first - last - sum(A[a:]))
    a2 = abs(sum(A[:a + 1]) + first - last - sum(A[a + 1:]))
    print(min(a1, a2))
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
if b-a==c-b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a,bc=map(int,input().split())
if b-a==c-a:
    print('YES')
else:
    print('NO')
Problem p03797 (python)

Fixed submission:
N,M=map(int,input().split())
count=0
if N>=1 and M>=2:
    a=M//2
    if N>=a:
        M=M-2*a
        answer=a
    else:
        M=M-2*N
        answer=N
else:
    answer=0
if M>=4:
    kotae=M//4
else:
    kotae=0
print(answer+kotae)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
count=0
if N>=1 and M>=2:
    a=M//2
    if N>=a:
        M=M-2*a
        answer=a
    else:
        M=M-2*N
        answer=N
if M>=4:
    kotae=M//4
print(answer+kotae)
Problem p03828 (python)

Fixed submission:
N=int(input())
b=1
for a in range(1,N+1):
    b*=a
numbers=[2]
for c in range(3,N+1):
    count=0
    for d in numbers:
        if not c%d==0:
            count+=1
        else:
            pass
    if count==len(numbers):
        numbers.append(c)
    else:
        pass
answers=[]
while b>1:
    for e in numbers:
        kazu=0
        while b%e==0:
            b=b//e
            kazu+=1
        answers.append(kazu)
kotae=1
for f in answers:
    kotae*=(f+1)
print(kotae%(10**9+7))

Buggy submission (verdict: Runtime Error):
N=int(input())
b=1
for a in range(1,N+1):
    b*=a
numbers=[2]
for c in range(3,N+1):
    count=0
    for d in numbers:
        if not c%d==0:
            count+=1
        else:
            pass
    if count==len(numbers):
        numbers.append(c)
    else:
        pass
answers=[]
while b>1:
    for e in numbers:
        kazu=0
        while b%e==0:
            b=b/e
            kazu+=1
        answers.append(kazu)
kotae=1
for f in answers:
    kotae*=(f+1)
print(kotae%(10**9+7))

Buggy submission (verdict: Runtime Error):
N=int(input())
b=1
for a in range(1,N+1):
    b*=a
numbers=[2]
for c in range(3,N+1):
    count=0
    for d in numbers:
        if not c%d==0:
            count+=1
        else:
            pass
    if count==len(numbers):
        numbers.append(c)
    else:
        pass
answers=[]
while b>1:
    for e in numbers:
        kazu=0
        while b%e==0:
            b=b/e
            kazu+=1
        answers.append(kazu)
kotae=1
for f in answers:
    kotae*=(f+1)
print(kotae)

Buggy submission (verdict: Runtime Error):
N=int(input())
b=1
for a in range(1,N+1):
    b*=a
numbers=[2]
for c in range(3,N+1):
    count=0
    for d in numbers:
        if not c%d==0:
            count+=1
        else:
            pass
    if count==len(numbers):
        numbers.append(c)
    else:
        pass
answers=[]
while b>1:
    for e in numbers:
        kazu=0
        while b%e==0:
            b=b/e
            kazu+=1
        answers.append(kazu)
kotae=1
for f in answers:
    kotae*=(f+1)
print(kotae)
Problem p03838 (python)

Fixed submission:
x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x==0:
    if y < 0:
        print(1+abs(y))
    else:
        print(abs(y))
elif x > 0:
    if abs(y) < x:
        if y == 0:
            print(1+y+x)
        elif y>0:
            print(abs(abs(y)-abs(x))+2)
        else:
            print(y+x+1)
    else:
        if y > 0:
            print(y-x)
        else:
            print(abs(y)-x+1)
else:
    if abs(y) <abs(x):
        if y >0 :
            print(1+abs(abs(x)-abs(y)))
        elif y==0:
            print(abs(x))
        else:
            print(abs(-x+y))
    else:
        if y >0:
            print(1+y+x)
        else:
            print(2+x-y)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x==0:
    if y < 0:
        print(1-y)
    else:
        print(y)
elif x > 0:
    if abs(y) < x:
        print(1+y+x)
    else:
        if y > 0:
            print(y-x)
        else:
            print(y-x)+1
else:
    if abs(y) <x:
        print(y-x)
    else:
        if y >=0:
            print(y-x)
        else:
            print(2+x-y)
Problem p03844 (python)

Fixed submission:
A,op,B=input().split()
if op=='+':
    print(int(A)+int(B))
else:
    print(int(A)-int(B))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=input().split()
numbers=[int(a) for a in A]
numbers.sort()
kazu=N//2
b=0
n=N-1
list=[]
nlist=[]
if N==1:
    if A==0:
        print(1)
    else:
        print(0)
else:
    if N % 2 == 0:
        for c in range(kazu):
            list.append(n - c * 2)
        nlist = list + list
        nlist.sort()
        if numbers == nlist:
            print((2 ** kazu)%(10**9+7))
        else:
            print(0)
    else:
        for c in range(kazu):
            list.append(n - c * 2)
        nlist = list + list + [0]
        nlist.sort()
        if numbers == nlist:
            print((2 ** kazu)%(10**9+7))
        else:
            print(0)
Problem p03852 (python)

Fixed submission:
c=input()
if c=='a' or c=='i' or c=='u' or c=='e' or c=='o':
    print('vowel')
else:
    print('consonant')

Buggy submission (verdict: Runtime Error):
c=input()
if c==a or c==i or c==u or c==e c==o:
    print('vowel')
else:
    print('consonant')
Problem p04030 (python)

Fixed submission:
S=input()
words=[a for a in S]
answers=[]
for n in words:
    if n=='1':
        answers.append('1')
    elif n=='0':
        answers.append('0')
    else:
        if not answers:
            continue
        else:
            answers.pop()
mojiretu=''
for x in answers:
    mojiretu+=x
print(mojiretu)

Buggy submission (verdict: Runtime Error):
S=input()
words=[*S]
answers=[]
for n in words:
    if n=='1':
        answers.append('1')
    elif n=='0':
        answers.append('0')
    else:
        if not answers:
            continue
        else:
            answers.pop()
mojiretu=''
for x in answers:
    mojiretu+=x
print(int(mojiretu))

Buggy submission (verdict: Runtime Error):
S=input()
words=[*S]
answers=[]
for n in words:
    if n=='1':
        answers.append('1')
    elif n=='0':
        answers.append('0')
    else:
        if not answers:
            continue
        else:
            answers.pop()
mojiretu=''
for x in answers:
    mojiretu+=x
print(mojiretu)

Buggy submission (verdict: Runtime Error):
S=input()
words=[*S]
answers=[]
for n in words:
    if n=='1':
        answers.append('1')
    elif n=='0':
        answers.append('0')
    else:
        if not answers:
            continue
        else:
            answers.pop()
mojiretu=''
for x in answers:
    mojiretu+=x
print(mojiretu)
Problem p02609 (python)

Fixed submission:
CH = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1,2,1]
N = int(input())
X = input()
s = 0
a = 1
A = []
B = []
for x in X:
    if x == "1":
        s += 1
for i in range(N):
    A.append(a)
    a = a*2 %(s+1)
a = 1
num = int(X,2)
num1 = num%(s+1)
if s > 1:
    num2 = num%(s-1)
    for i in range(N):
        B.append(a)
        a = a*2 %(s-1)
for i in range(N):
    if int(X[i])==1:
        p = s-1
        if p == 0:
            print(0)
            continue
        x = (num2-B[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])
    else:
        p = s+1
        x = (num1+A[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])

Buggy submission (verdict: Runtime Error):
CH = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1,2,1]
N = int(input())
X = input()
s = 0
a = 1
A = []
B = []
for x in X:
    if x == "1":
        s += 1
for i in range(N):
    A.append(a)
    a = a*2 %(s+1)
a = 1
for i in range(N):
    B.append(a)
    a = a*2 %(s-1)
num = int(X,2)
num1 = num%(s+1)
if s > 1:
    num2 = num%(s-1)
for i in range(N):
    if int(X[i])==1:
        p = s-1
        if p == 0:
            print(0)
            continue
        x = (num2-B[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])
    else:
        p = s+1
        x = (num1+A[N-1-i])%p
        if x > 20:
            y = x%sum(map(int,list(bin(x))[2:]))
            print(2+CH[y])
        else:
            print(1+CH[x])
Problem p02684 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
n = 1
B = [0]*N
state = 0
for i in range(2*N+1):
    if i == K:
        state = 1
        break
    B[n-1] = i+1
    n = A[n-1]
    if B[n-1] != 0:
        t = i+2
        break
if state:
    print(n)
else:
    c = t-B[n-1]
    s = (K+1-t)%c
    for i in range(s):
        n = A[n-1]
    print(n)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
n = 1
B = [0]*N
for i in range(K):
    B[n-1] = i+1
    n = A[n-1]
    if B[n-1] != 0:
        t = i+2
        break
c = t-B[n-1]
s = (K+1-B[n-1])%c
for i in range(s):
    n = A[n-1]
print(n)
Problem p02882 (python)

Fixed submission:
import math
a,b,X = map(float,input().split())
T = math.atan(a/b)
if X <= a**2*b/2.0:
    c = 2*X/(a*b**2)
    theta = 90.0 -math.atan(c)*180/math.pi
else:
    Y = a**2*b-X
    theta = math.atan(2*Y/a**3)*180/math.pi
print(theta)

Buggy submission (verdict: Runtime Error):
import math
from sympy import *
a,b,X = map(float,input().split())
T = math.atan(a/b)
if X <= a**2*b/2.0:
    c = 2*X/(a*b**2)
    t = Symbol('t', real=True)
    x = solve(t**3-c*t**2+t-c)[0]
    theta = 90.0 -math.atan(x)*180/math.pi
else:
    Y = a**2*b-X
    theta = math.atan(2*Y/a**3)*180/math.pi
print(theta)
Problem p02945 (python)

Fixed submission:
A,B = map(int,input().split())
C = max(A+B,A-B)
print(max(A*B,C))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
D = [[] for i in range(M)]
for i in range(N):
    A,B = map(int,input().split())
    if A <= M:
        D[A-1].append(B)
count = 0
Tax = []
for i in range(M):
    for j in D[i]:
        bisect.insort_left(Tax,j)
    if not Tax:
        continue
    count += Tax.pop()
print(count)
Problem p02995 (python)

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

if __name__ == "__main__":
    A,B,C,D = map(int,input().split())
    ac = A%C
    E = int(C*D/gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))

Buggy submission (verdict: Runtime Error):
import math
if __name__ == "__main__":
    A,B,C,D = map(int,input().split())
    ac = A%C
    E = int(C * D / math.gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))

Buggy submission (verdict: Runtime Error):
import math

if __name__ == "__main__":

    A,B,C,D = map(int,input().split())
    ac = A%C
    #bc = B%C
    E = int(C * D / math.gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))