Problem:
Multi-Set For a set $S$ of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in $S$ .  insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.  find($x$): Report the number of $x$ in $S$.  delete($x$): Delete all $x$ from $S$.  dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.  Input The input is given in the following format. $q$
$query_1$
$query_2$
:
$query_q$ Each query $query_i$ is given by 0 $x$ or 1 $x$ or 2 $x$ or 3 $L$ $R$ where the first digits 0 , 1 , 2 and 3 represent insert, find, delete and dump operations respectively. Output For each insert operation, print the number of elements in $S$. For each find operation, print the number of specified elements in $S$. For each dump operation, print the corresponding elements in ascending order. Print an element in a line. Constraints  $1 \leq q \leq 200,000$  $0 \leq x \leq 1,000,000,000$  The total number of elements printed by dump operations does not exceed $1,000,000$  The sum of numbers printed by find operations does not exceed $2,000,000$  Sample Input 1 10
0 1
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 4
3 1 4 Sample Output 1 1
2
3
4
2
0
1
4
1
1
3
4

Solution (Python):
import bisect

S=[]

q=int(input())

def find(x):
    index=bisect.bisect_left(S,x)
    if index==len(S):
        return -1
    if S[index]==x:
        return index
    else:
        return -1


for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        bisect.insort_left(S, query[1])
        print(len(S))
    elif query[0]==1:
        L,R=query[1],query[1]
        indL=bisect.bisect_left(S,L)
        indR=bisect.bisect_right(S,R)
        print(len(S[indL:indR]))
    elif query[0]==2:
        while find(query[1])>=0:
            S.pop(find(query[1]))
    else:
        L,R=query[1],query[2]
        indL=bisect.bisect_left(S,L)
        indR=bisect.bisect_right(S,R)
        for s in S[indL:indR]:
            print(s)

Solution (Python):
from bisect import insort, bisect_right, bisect_left


class MultiSet:
    def __init__(self) -> None:
        self.total = 0
        self.ms: dict = dict()
        self.lr: list = []

    def insert(self, x: int) -> None:
        self.total += 1
        if x in self.ms:
            self.ms[x] += 1
        else:
            self.ms[x] = 1
            insort(self.lr, x)
        print(self.total)

    def find(self, x: int) -> None:
        print(self.ms.get(x, 0))

    def delete(self, x: int) -> None:
        if x in self.ms:
            self.total -= self.ms[x]
            self.ms[x] = 0

    def dump(self, l: int, r: int) -> None:
        lb = bisect_left(self.lr, l)
        ub = bisect_right(self.lr, r)
        for i in range(lb, ub):
            k = self.lr[i]
            v = self.ms[k]
            print(f'{k}\n' * v, end='')


if __name__ == "__main__":
    ms = MultiSet()
    num_query = int(input())
    for _ in range(num_query):
        op, *v = map(lambda x: int(x), input().split())
        if 0 == op:
            ms.insert(v[0])
        elif 1 == op:
            ms.find(v[0])
        elif 2 == op:
            ms.delete(v[0])
        else:
            ms.dump(v[0], v[1])

Solution (Python):

"""
Set - Multi-Set
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_7_D&lang=jp

"""
from bisect import insort, bisect_right, bisect_left

class Multi_set:
    def __init__(self):
        self.total = 0
        self.ms = dict()
        self.lr = []

    def insert(self, x):
        self.total += 1
        if x in self.ms:
            self.ms[x] += 1
        else:
            self.ms[x] = 1
            insort(self.lr, x)
        print(self.total)

    def find(self, x):
        print(self.ms.get(x, 0))

    def delete(self, x):
        if x in self.ms:
            self.total -= self.ms[x]
            self.ms[x] = 0

    def dump(self, l, r):
        lb = bisect_left(self.lr, l)
        ub = bisect_right(self.lr, r)
        for i in range(lb, ub):
            k = self.lr[i]
            v = self.ms[k]
            print(f'{k}\n' * v, end='')


ms = Multi_set()
for _ in range(int(input())):
    op, x, y = (input() + ' 1').split()[:3]
    if op == '0':
        ms.insert(int(x))
    elif op == '1':
        ms.find(int(x))
    elif op == '2':
        ms.delete(int(x))
    else:
        ms.dump(int(x), int(y))

Solution (Python):
import bisect


q = int(input())

S = []


for _ in range(q):

    command, *list_num = input().split()
    x = int(list_num[0])

    index_left_x = bisect.bisect_left(S, x)
    index_right_x = bisect.bisect_right(S, x)

    if   command == "0":
        
        x = int(list_num[0])
        S.insert(index_left_x, x)
        print(len(S))
    elif command == "1":
        
        x = int(list_num[0])
        print(index_right_x - index_left_x)
    elif command == "2":
        
        x = int(list_num[0])
        S[index_left_x:index_right_x]= []
    elif command == "3":
        
        L = x
        R = int(list_num[1])

        index_left = bisect.bisect_left(S, L)
        index_right = bisect.bisect_right(S, R)
        
        for element in S[index_left:index_right]:
            print(element)
    else:
        raise

Solution (Python):

from bisect import *
import sys
n = int(input())
ss = []
color = {}
cnt = 0
for _ in range(n):
    a, b, *c = map(int,sys.stdin.readline().split())
    if a == 0:
        if b not in color:
            insort_left(ss,b)
            color[b] = 1
            cnt += 1
        else:
            color[b] += 1
            cnt += 1
        print(cnt)
    elif a == 1:
        print(color[b] if b in color else 0)
    elif a == 2:
        if b in color:
            cnt -= color[b]
            color[b] = 0
    else:
        L = bisect_left(ss,b)
        R = bisect(ss,c[0])
        for i in range(L,R):
            for _ in range(color[ss[i]]):
                print(ss[i])

Solution (Python):
import bisect

S=[]

def insert(S,count,x):
    y=bisect.bisect(S,x)
    S.insert(y,x)
    count+=1
    print(count)
    return S,count

def find(S,x):
    y0=bisect.bisect_left(S,x)
    y1=bisect.bisect_right(S,x)
    return y0,y1

def erase(S,count,x):
    y0,y1=find(S,x)
    if y1-y0>0:
        del S[y0:y1]
        count-=y1-y0
    return S,count

def dump(S,L,R):
    s=bisect.bisect_left(S,L)
    e=bisect.bisect_right(S,R)
    if e-s>0:
        print('\n'.join(map(str,S[s:e])))

q=int(input())
count=0
for i in range(q):
    query=list(map(int,input().split()))
    
    if query[0]==0:
        S,count=insert(S,count,query[1])
    elif query[0]==1:
        y0,y1=find(S,query[1])
        print(y1-y0)
    elif query[0]==2:
        S,count=erase(S,count,query[1])
    else:
        dump(S,query[1],query[2])

Solution (Python):
import sys
import bisect
nq = int(input())
lines = sys.stdin.readlines()
ans = [None] * nq
arr = []
for i in range(nq):
    q, *arg = lines[i].split()
    x = int(arg[0])
    l_idx = bisect.bisect_left(arr, x)
    r_idx = bisect.bisect_right(arr, x)
    if q == '0':    
        arr.insert(l_idx, x)
        ans[i] = str(len(arr))
    elif q == '1':   
        ans[i] = r_idx - l_idx
    elif q == '2':           
        arr[l_idx:r_idx] = []
    else:                   
        r_idx = bisect.bisect_right(arr, int(arg[1]))
        ans[i] = '\n'.join(map(str, arr[l_idx:r_idx])) if l_idx != r_idx else None
    

[print(x) for x in ans if x is not None]