package main

import (
	"fmt"
	"math"
	"sort"

	"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)))
}
func GetIndex(i int) int {
	return i % CAP
}

type MySet struct {
	dataList []map[int]struct{}
	count    []int
	total    int
}

func NewSet() MySet {
	n := (MAX / CAP) + 1
	dataList := make([]map[int]struct{}, n)
	for i := range dataList {
		dataList[i] = make(map[int]struct{})
	}
	counts := make([]int, n)
	return MySet{dataList, counts, 0}
}

func (this *MySet) Exists(i int) bool {
	_, ok := this.dataList[GetLank(i)][GetIndex(i)]
	return ok
}

func (this *MySet) Count() int {
	return this.total
}
func (this *MySet) Add(i int) int {
	lank := GetLank(i)
	if this.Exists(i) {
		return this.Count()
	}
	this.dataList[GetLank(i)][GetIndex(i)] = struct{}{}
	this.count[lank]++
	this.total++
	return this.Count()
}

func (this *MySet) Remove(i int) {
	if this.Exists(i) {
		delete(this.dataList[GetLank(i)], GetIndex(i))
		this.count[GetLank(i)]--
		this.total--
	}
}

func (this *MySet) Find(i int) int {
	if this.Exists(i) {
		return 1
	} else {
		return 0
	}
}

func (this *MySet) Dump(left, right int) []int {
	found := 0 // found in current lank
	count := 0 // num total
	result := make([]int, 8)
	// result := make([]int, this.count)
	for i := left; i <= right; i++ {
		// boundary
		if i % CAP == 0 {
			found = 0
		}
		// not exists in current lank
		lank := GetLank(i)
		if this.count[lank] == 0 {
			i = (lank + 1) * CAP - 1
			found = 0
			continue
		}
		if this.Exists(i) {
			found++
			if len(result) <= count {
				result = append(result, i)
			} else {
				result[count] = i
			}
			// done in current lank
			if found == this.count[lank] {
				i = (lank + 1) * CAP - 1
			}
			count++
		}
	}
	_ = 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: 167176