package main

import (
	"fmt"
	"sort"
	"math"
	"bufio"
	"bytes"
	"io"
	"os"

	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

const MAX int = 1000000001
const CAP int = 512

func GetLank(i int) int {
	return int(math.Floor(float64(i) / float64(CAP)))
}

type MultiSet struct {
	list   map[int]int //[val] => count
	counts []int
	total int
}

func NewSet() MultiSet {
	list := make(map[int]int)
	numLank := (MAX / CAP) + 1
	counts := make([]int, numLank)
	return MultiSet{list, counts, 0}
}

func (this *MultiSet) Exists(i int) bool {
	_, ok := this.list[i]
	return ok
}

func (this *MultiSet) Add(i int) int {
	this.list[i]++
	this.counts[GetLank(i)]++
	this.total++
	return this.total
}

func (this *MultiSet) Remove(i int) {
	if this.Exists(i) {
		num := this.list[i]
		this.list[i] = 0
		this.counts[GetLank(i)] -= num
		this.total -= num
	}
}

func (this *MultiSet) Find(i int) int {
	if this.Exists(i) {
		return this.list[i]
	} else {
		return 0
	}
}

func (this *MultiSet) Dump(left, right int) []int {
	count := 0
	found := 0
	result := make([]int, 8)
	for i := left; i <= right; i++ {
		// boundary
		if i % CAP == 0 {
			found = 0
		}
		// not exists in current lank
		lank := GetLank(i)
		if this.counts[lank] == 0 {
			i = (lank + 1) * CAP - 1
			found = 0
			continue
		}
		if this.Exists(i) {
			for j := 0; j < this.list[i]; j++ {
				if len(result) <= count {
					result = append(result, i)
				} else {
					result[count] = i
				}
				found++
				count++
			}
			// done in current lank
			if found == this.counts[lank] {
				i = (lank + 1) * CAP - 1
			}
		}
	}
	// _ = sort.Slice
	result = result[:count]
	sort.Slice(result, func(lhs, rhs int) bool {
		return result[lhs] < result[rhs]
	})
	return result
}

func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	set := NewSet()

	lines, _ := ReadLongLines(n)

	for i := range lines {
		args := strings.Split(lines[i], " ")
		command, _ := strconv.Atoi(args[0])
		x, _ := strconv.Atoi(args[1])

		switch command {
		case 0: //insert
			l := set.Add(x)
			con.Printf("%d\n", l)
		case 1: //find
			con.Printf("%d\n", set.Find(x))
		case 2: // delete
			set.Remove(x)
		case 3: // dump
			l, _ := strconv.Atoi(args[1])
			r, _ := strconv.Atoi(args[2])
			result := set.Dump(l, r)
			for i := range result {
				con.Printf("%d\n", result[i])
			}
		}

	}
}



Measured memory_bytes: 41944