Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem.

The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.

For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them.

NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$.

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 2; i <= n+1; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

import "fmt"

func main() {
	var T, n int
	fmt.Scan(&T)
	for T > 0 {
		T--
		fmt.Scan(&n)
		if n == 1 {
			fmt.Println(1)
			continue
		}
		var i int
		for i = 2; i < n+1; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println(i)
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    for i := 0; i < n; i++ {
        fmt.Fprint(output, i + 2, " ")
    }
    fmt.Fprintln(output)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 2
		}

		for _, ch := range arr {
			fmt.Fprintf(out, "%d ", ch)
		}
		fmt.Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		for j := 0; j < n; j++ {
			fmt.Fprint(w, j+2, " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var num int
		fmt.Scanf("%d\n", &num)
		for j := 0; j < num; j++ {
			fmt.Printf("%d ", 2+j)
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func gcd(x, y int) int {
	if y > x {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(n int) string {
	var s []string
	for i := 0; i < n; i++ {
		s = append(s, fmt.Sprint(i+2))
	}
	return strings.Join(s, " ")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

// Online IDE - Code Editor, Compiler, Interpreter

package main

import "fmt"

func main() {
   t := 1
   fmt.Scanln(&t)
   for x := 0; x < t; x++ {
      n := 1
      fmt.Scanln(&n)
      for i := 2; i <= (n + 1); i++ {
         fmt.Print(i)
         fmt.Print(" ")
      }
      fmt.Print("\n")
   }

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

/*
1
5
---
2 3 5 7 11
 */

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	primes := make([]int, 1_000)
	j := 0

	for i := 2; i < 8000 && j < len(primes); i++ {
		if isPrime(i) {
			primes[j] = i
			j++
		}
	}

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		for i := 0; i < n; i++ {
			fmt.Fprintf(&bld, "%d ", primes[i])
		}
		fmt.Fprintln(&bld)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1608A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1608A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1608A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1608A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1608A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1608A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1608A
Date: 11/12/21
User: epradere
URL: https://codeforces.com/contest/1608/problem/0
Problem: CF1608A
**/
func (in *CF1608A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n == 1 {
			fmt.Println(1)
		} else {
			for i := 2; i < n+2; i++ {
				fmt.Printf("%d ", i)
			}
			fmt.Println()
		}
	}
}

func NewCF1608A(r *bufio.Reader) *CF1608A {
	return &CF1608A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1608A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"fmt"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		_, _ = fmt.Scanln(&n)
		if n == 1 {
			fmt.Println(1)
		} else {
			fmt.Print("2")
			for j, k := 0, 3; j < n-1; j, k = j+1, k+1 {
				fmt.Printf(" %d", k)
			}
			fmt.Println()
		}
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 1; i <= n; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"

)

const MOD int64 = 1000000007

var n int

var r *bufio.Reader

func main() {

	r = bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(r, &n)

		solve()

		fmt.Println()
	}
}

func solve()  {
	for i := 1; i < n; i++ {
		fmt.Print(i)
		fmt.Print(" ")
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    for i := 0; i < n; i++ {
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}


Немногие знают, что сотрудники ВКонтакте могут менять цвет подсветки в куполе знаменитого Дома Зингера, где расположена штаб-квартира ВКонтакте. Для этого нужно всего лишь отправить сообщение с цветом в специальный чат «Зингер | color», а бот его распознает и сменит подсветку. При этом на время городских мероприятий смена цвета блокируется.Формально, бот обрабатывает три типа сообщений:   lock: заблокировать изменение цвета. Если оно и так заблокировано на данный момент, сообщение игнорируется.  unlock: разблокировать изменение цвета. Если оно и так разблокировано на данный момент, сообщение игнорируется.  red / orange / yellow / green / blue / indigo / violet: изменить цвет купола на заданный, если изменение цвета на данный момент не заблокировано. Вам дана история сообщений, полученных ботом, в хронологическом порядке. Считайте, что перед получением первого сообщения купол подсвечивается голубым (blue), а изменение цвета не заблокировано.В качестве эксперимента было решено поддержать в боте эффективную обработку редактирования сообщений. Вам дана последовательность пар вида $$$(i, msg)$$$, означающих, что $$$i$$$-е в хронологическом порядке сообщение было отредактировано и теперь имеет вид $$$msg$$$. Обратите внимание, что редактироваться может любое сообщение, и при редактировании сообщения бот должен обработать всю историю сообщений заново (в частности, перед обработкой первого сообщения цвет купола голубой, а изменение цвета не заблокировано).Определите, какой цвет будет у купола Дома Зингера до первой операции редактирования, а также после каждой операции редактирования.

В первой строке задано одно целое число $$$n$$$ ($$$1 \le n \le 10^5$$$) — число сообщений, полученных ботом. В следующих $$$n$$$ строках заданы сообщения, полученные ботом, в хронологическом порядке, по одному сообщению в строке. Каждое сообщение — строка из следующего набора: lock, unlock, red, orange, yellow, green, blue, indigo, violet. Сообщения пронумерованы от $$$1$$$ до $$$n$$$. В следующей строке задано одно целое число $$$t$$$ ($$$1 \le t \le 10^5$$$) — число операций редактирования сообщений. В следующих $$$t$$$ строках заданы операции редактирования в хронологическом порядке, по одной в строке. Каждая операция — пара из номера сообщения $$$i$$$ ($$$1 \le i \le n$$$) и его нового содержимого $$$msg$$$, также принадлежащего набору lock, unlock, red, orange, yellow, green, blue, indigo, violet.

Выведите $$$t+1$$$ строку: цвет купола до первой операции редактирования, а также после каждой операции редактирования в хронологическом порядке.

7
red
violet
unlock
red
orange
lock
indigo
6
5 green
6 lock
6 yellow
4 lock
1 lock
5 unlock

1
red
8
1 lock
1 unlock
1 blue
1 unlock
1 unlock
1 lock
1 yellow
1 lock

orange
green
green
indigo
violet
blue
indigo

red
blue
blue
blue
blue
blue
blue
yellow
blue

package main

import (

	"fmt"
	"math/rand"

	"time"

	"bufio"
	"os"
)

type edit struct {
	msg string
	op int
}

type interval struct {
	l, r int
}

const LOCAL = false

func main() {

	if LOCAL {
		rand.Seed(time.Now().UnixNano())

		choices := []string{"lock", "unlock", "red", "orange", "yellow", "green", "blue", "indigo", "violet"}

		var n, t int
		n = 1000
		t = 1000

		for p := 0; p < 100; p++ {

			ops := make([]string, n + 1)
			for i := 1; i <= n; i++ {
				id := rand.Intn(9)
				ops[i] = choices[id]
			}

			edits := make([]edit, t)
			for j := 0; j < t; j++ {
				n := 1 + rand.Intn(1000)
				id := rand.Intn(9)

				edits[j] = edit{ choices[id], n}
			}

			o1 := make([]string, n + 1)
			o2 := make([]string, n + 1)

			for i := 1; i <= n; i++ {
				o1[i] = ops[i]
				o2[i] = ops[i]
			}

			fmt.Println("OPS and Edits--")
			fmt.Println(ops)
			fmt.Println(edits)

			a1 := solve(o1, edits, n,  t)
			//a2 := solve_stupid(o2, edits, n,  t)
			fmt.Println(len(a1))

			/*for i := 0; i < len(a1); i++ {
				if a1[i] != a2[i] {
					fmt.Println("ERROR")
					fmt.Println(a1)
					fmt.Println(a2)
					fmt.Println(ops)
					fmt.Println(edits)
					break
				}
			}*/
		}

	} else {

		w := bufio.NewWriter(os.Stdout)
		r := bufio.NewReader(os.Stdin)
		var n, t int
		fmt.Fscan(r, &n)

		ops := make([]string, n + 1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(r, &ops[i])
		}

		fmt.Fscan(r, &t)

		edits := make([]edit, t)
		for j := 0; j < t; j++ {
			fmt.Fscan(r, &edits[j].op, &edits[j].msg)
		}

		o1 := make([]string, n + 1)
		o2 := make([]string, n + 1)

		for i := 1; i <= n; i++ {
			o1[i] = ops[i]
			o2[i] = ops[i]
		}

		a1 := solve(o1, edits, n,  t)

		for i := 0; i < len(a1); i++ {
			fmt.Fprintln(w, a1[i])
		}
		w.Flush()
	}

}

func solve_stupid(ops []string, edits []edit , n int, t int) []string {

	color := "blue"
	locked := false
	var resp []string

	for i := 1; i <= n; i++ {
		o := ops[i]

		if o == "lock" {
			locked = true

		} else if o == "unlock" {
			locked = false

		} else {
			if locked {
				continue
			}

			color = o
		}
	}
	resp = append(resp, color)

	for i := 0 ; i < t; i++ {

		e := edits[i]
		ops[e.op] = e.msg

		color := "blue"
		locked := false

		for i := 1; i <= n; i++ {
			o := ops[i]

			if o == "lock" {
				locked = true

			} else if o == "unlock" {
				locked = false

			} else {
				if locked {
					continue
				}

				color = o
			}
		}

		resp = append(resp, color)
	}

	return resp

}

func solve(ops []string, edits []edit , n int, t int) []string {
	var resp []string

	locks := newIntIntTreeMap(func(a int, b int) bool {
		return a < b
	})
	unlocks := newIntIntTreeMap(func(a int, b int) bool {
		return a < b
	})

	colors := newIntInterfaceTreeMap(func(a int, b int) bool {
		return a < b
	})

	color := "blue"
	locked := false
	start := -1

	for i := 1; i <= n; i++ {
		o := ops[i]

		if o == "lock" {
			locked = true
			locks.Set(i, 0)

			if start != -1 {
				colors.Set(start, &interval{start, i - 1})
				start = -1
			}

		} else if o == "unlock" {
			locked = false
			unlocks.Set(i, 0)

			if start != -1 {
				colors.Set(start, &interval{start, i - 1})
				start = -1
			}

		} else {
			if locked {
				continue
			}

			if start == -1 {
				start = i
			}

			color = o
		}
	}
	if start != -1 {
		colors.Set(start, &interval{start, n})
	}

	resp = append(resp, color)

	for i := 0; i < t; i++ {
		e := edits[i]

		msg := e.msg
		op := e.op

		if msg == "lock" {
			if ops[op] == "lock" {

			} else if ops[op] == "unlock" {
				itl := locks.UpperBound(op)
				itu := unlocks.UpperBound(op)

				var m int

				if itl.Valid() {
					if itu.Valid() {
						m = min(itl.Key(), itu.Key())

					} else {
						m = itl.Key()
					}

				} else {
					if itu.Valid() {
						m = itu.Key()

					} else {
						m = n
					}
				}

				if m >= op + 1 {
					colors.Del(op + 1)
				}

				locks.Set(op, 0)
				unlocks.Del(op)

			} else {
				it := colors.LowerBound(op)

				if it.Valid() {
					if it.Key() == op {
						colors.Del(op)
					}
				}
				it.Prev()
				if it.node != nil {
					ival := it.Value().(*interval)

					if ival.l < op && ival.r >= op {
						colors.Del(ival.l)
						colors.Set(ival.l, &interval{ival.l, op - 1})
					}
				}

				locks.Set(op, 0)
			}

			ops[op] = msg

		} else if msg == "unlock" {

			if ops[op] == "unlock" {

			} else if ops[op] == "lock" {
				itl := locks.UpperBound(op)
				itu := unlocks.LowerBound(op)

				if !itl.Valid() {
					var r int
					if !itu.Valid() {
						r = n
					} else {
						r = itu.Key() - 1
					}

					if op + 1 <= r {
						colors.Set(op + 1, &interval{op + 1, r})
					}

				} else {
					var r int
					if !itu.Valid() {
						r = itl.Key() - 1
					} else {
						r = min(itl.Key() - 1, itu.Key() - 1)
					}

					if r >= op + 1 {
						colors.Set(op + 1, &interval{op + 1, r})
					}
				}

				locks.Del(op)
				unlocks.Set(op, 0)

			} else {
				it := colors.LowerBound(op)

				if it.Valid() {
					if it.Key() == op {
						colors.Del(op)

						if op + 1 <= it.Value().(*interval).r {
							colors.Set(op + 1, &interval{op + 1, it.Value().(*interval).r})
						}
					}
				}
				it.Prev()

				if it.node != nil {
					ival := it.Value().(*interval)

					if ival.l < op && ival.r >= op {
						colors.Del(ival.l)

						if op == ival.r {
							colors.Set(ival.l, &interval{ival.l, op -  1})
						} else {
							colors.Set(ival.l, &interval{ival.l, op -  1})
							colors.Set(op +  1, &interval{op +  1, ival.r})
						}
					}
				}

				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itu.Prev()
				itl.Prev()

				doScan := false

				if itl.node != nil {
					indexLock := itl.Key()

					if itu.node != nil {
						indexUnlock := itu.Key()

						if indexLock > indexUnlock {
							doScan = true
						}

					} else {
						doScan = true
					}

				}

				if doScan {
					itl := locks.UpperBound(op)
					itu := unlocks.UpperBound(op)

					var index int

					if itu.Valid() {
						if itl.Valid() {
							index = min(itu.Key(), itl.Key()) - 1

						} else {
							index = itu.Key() - 1
						}

					} else {
						if itl.Valid() {
							index = itl.Key() - 1

						} else {
							index = n
						}
					}

					if op + 1 <= index {
						colors.Set(op + 1, &interval{op + 1, index})
					}

				}

				unlocks.Set(op, 0)
			}

			ops[op] = msg

		} else {

			if ops[op] == "lock" {
				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itl.Prev()
				itu.Prev()

				start := -1
				end := - 1

				if itl.node != nil {
					if itu.node != nil {

						if itu.Key() > itl.Key() {
							start = itu.Key() + 1
						}
					}

				} else {
					if itu.node != nil {
						start = itu.Key() + 1

					} else {
						start = 1
					}
				}

				itl = locks.UpperBound(op)
				itu = unlocks.UpperBound(op)

				if itl.Valid() {
					if itu.Valid() {
						m := min(itl.Key(), itu.Key())
						end = m - 1

					} else {
						end = itl.Key() - 1
					}
				} else {
					if itu.Valid() {
						end = itu.Key() - 1
					} else {
						end = n
					}
				}

				if start != -1 {
					colors.Del(start)
					colors.Set(start, &interval{start, end})
				}

				locks.Del(op)
				ops[op] = msg

			} else if ops[op] == "unlock" {
				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itl.Prev()
				itu.Prev()

				start := -1
				end := -1

				if itl.node != nil {
					if itu.node != nil {

						if itu.Key() > itl.Key() {
							start = itu.Key() + 1
						}
					}

				} else {
					if itu.node != nil {
						start = itu.Key() + 1

					} else {
						start = 1
					}
				}

				itl = locks.UpperBound(op)
				itu = unlocks.UpperBound(op)

				if itl.Valid() {
					if itu.Valid() {
						m := min(itu.Key(), itl.Key())
						end = m - 1

					} else {
						end = itl.Key() - 1
					}

				} else {
					if itu.Valid() {
						end = itu.Key() - 1

					} else {
						end = n
					}
				}

				if colors.Contains(op + 1) {
					colors.Del(op + 1)
				}

				if start != -1 {
					colors.Set(start, &interval{start, end})
				}

				unlocks.Del(op)
				ops[op] = msg

			} else {
				ops[op] = msg
			}

		}

		it := colors.LowerBound(n)

		var rightMost *interval
		if it.Valid() {
			resp = append(resp, ops[n])

		} else {
			it.Prev()
			if it.node == nil {
				resp = append(resp, "blue")
			} else {
				rightMost = it.Value().(*interval)
				if rightMost.r == 0 {
					resp = append(resp, "blue")
				} else {
					resp = append(resp, ops[rightMost.r])
				}
			}
		}
	}

	return resp
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type intIntTreeMap struct {
	endNode   *nodeIntIntTreeMap
	beginNode *nodeIntIntTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntIntTreeMap struct {
	right   *nodeIntIntTreeMap
	left    *nodeIntIntTreeMap
	parent  *nodeIntIntTreeMap
	isBlack bool
	key     int
	value   int
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntIntTreeMap(less func(a int, b int) bool) *intIntTreeMap {
	endNode := &nodeIntIntTreeMap{isBlack: true}
	return &intIntTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intIntTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Set(key int, value int) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntIntTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intIntTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntIntTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intIntTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Get(id int) (int, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intIntTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intIntTreeMap) Range(from, to int) (forwardIteratorIntIntTreeMap, forwardIteratorIntIntTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) LowerBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) UpperBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intIntTreeMap) Iterator() forwardIteratorIntIntTreeMap {
	return forwardIteratorIntIntTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intIntTreeMap) Reverse() reverseIteratorIntIntTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntIntTreeMap(node)
	}
	return reverseIteratorIntIntTreeMap{tree: t, node: node}
}

func (t *intIntTreeMap) findNode(id int) *nodeIntIntTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.right != nil {
		return mostLeftIntIntTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.left != nil {
		return mostRightIntIntTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intIntTreeMap) insertFixup(x *nodeIntIntTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntIntTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntIntTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntIntTreeMap(root *nodeIntIntTreeMap, z *nodeIntIntTreeMap) {
	var y *nodeIntIntTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntIntTreeMap(z)
	}
	var x *nodeIntIntTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntIntTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntIntTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntIntTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntIntTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntIntTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntIntTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Prev() {
	i.node = predecessorIntIntTreeMap(i.node)
	if i.node == nil {
		//panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntIntTreeMap) Value() int { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntIntTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntIntTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntIntTreeMap) Value() int { return i.node.value }

type intInterfaceTreeMap struct {
	endNode   *nodeIntInterfaceTreeMap
	beginNode *nodeIntInterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntInterfaceTreeMap struct {
	right   *nodeIntInterfaceTreeMap
	left    *nodeIntInterfaceTreeMap
	parent  *nodeIntInterfaceTreeMap
	isBlack bool
	key     int
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntInterfaceTreeMap(less func(a int, b int) bool) *intInterfaceTreeMap {
	endNode := &nodeIntInterfaceTreeMap{isBlack: true}
	return &intInterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Set(key int, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntInterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntInterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Get(id int) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intInterfaceTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Range(from, to int) (forwardIteratorIntInterfaceTreeMap, forwardIteratorIntInterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) LowerBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) UpperBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intInterfaceTreeMap) Iterator() forwardIteratorIntInterfaceTreeMap {
	return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intInterfaceTreeMap) Reverse() reverseIteratorIntInterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntInterfaceTreeMap(node)
	}
	return reverseIteratorIntInterfaceTreeMap{tree: t, node: node}
}

func (t *intInterfaceTreeMap) findNode(id int) *nodeIntInterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.right != nil {
		return mostLeftIntInterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.left != nil {
		return mostRightIntInterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intInterfaceTreeMap) insertFixup(x *nodeIntInterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntInterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntInterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntInterfaceTreeMap(root *nodeIntInterfaceTreeMap, z *nodeIntInterfaceTreeMap) {
	var y *nodeIntInterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntInterfaceTreeMap(z)
	}
	var x *nodeIntInterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntInterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntInterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntInterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntInterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntInterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntInterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Prev() {
	i.node = predecessorIntInterfaceTreeMap(i.node)
	if i.node == nil {

	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntInterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntInterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }

package main

import (
	"bufio"
	"os"
	"fmt"
)

type edit struct {
	msg string
	op int
}

type interval struct {
	l, r int
}

func main() {

	r := bufio.NewReader(os.Stdin)
	var n, t int
	fmt.Fscan(r, &n)

	color := "blue"
	locked := false

	ops := make([]string, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(r, &ops[i])
	}

	fmt.Fscan(r, &t)

	edits := make([]edit, t)
	for j := 0; j < t; j++ {
		fmt.Fscan(r, &edits[j].op, &edits[j].msg)
	}

	locks := newIntIntTreeMap(func(a int, b int) bool {
		return a < b
	})
	unlocks := newIntIntTreeMap(func(a int, b int) bool {
		return a < b
	})

	colors := newIntInterfaceTreeMap(func(a int, b int) bool {
		return a < b
	})

	start := -1

	for i := 1; i <= n; i++ {
		o := ops[i]

		if o == "lock" {
			locked = true
			locks.Set(i, 0)

			if start != -1 {
				colors.Set(start, &interval{start, i - 1})
				start = -1
			}

		} else if o == "unlock" {
			locked = false
			unlocks.Set(i, 0)

			if start != -1 {
				colors.Set(start, &interval{start, i - 1})
				start = -1
			}

		} else {
			if locked {
				continue
			}

			if start == -1 {
				start = i
			}

			color = o
		}
	}
	fmt.Println(color)

	for i := 0; i < t; i++ {
		e := edits[i]

		msg := e.msg
		op := e.op

		if msg == "lock" {
			if ops[op] == "lock" {

			} else if ops[op] == "unlock" {
				it := colors.LowerBound(op)

				if it.Valid() {
					intKey := it.Key()
					itl := locks.LowerBound(op)

					if !itl.Valid() {
						colors.Del(intKey)

					} else {
						lockIndex := itl.Key()

						if lockIndex > intKey {
							itu := unlocks.LowerBound(op)

							if !itu.Valid() {
								colors.Del(intKey)
							} else {
								if itu.Key() > intKey {
									colors.Del(intKey)
								}
							}
						}
					}
				}

				locks.Set(op, 0)
				unlocks.Del(op)

			} else {
				it := colors.LowerBound(op)

				if it.Valid() {
					if it.Key() == op {
						colors.Del(op)
					}
				}
				it.Prev()
				if it.node != nil {
					ival := it.Value().(*interval)

					if ival.l < op && ival.r >= op {
						colors.Del(ival.l)
						colors.Set(ival.l, &interval{ival.l, op - 1})
					}
				}

				locks.Set(op, 0)
			}

			ops[op] = msg

		} else if msg == "unlock" {

			if ops[op] == "unlock" {

			} else if ops[op] == "lock" {
				itl := locks.UpperBound(op)
				itu := unlocks.LowerBound(op)

				if !itl.Valid() {
					var r int
					if !itu.Valid() {
						r = n
					} else {
						r = itu.Key() - 1
					}

					if op < n {
						colors.Set(op + 1, &interval{op + 1, r})
					}

				} else {
					var r int
					if !itu.Valid() {
						r = itl.Key() - 1
					} else {
						r = min(itl.Key() - 1, itu.Key() - 1)
					}

					if op < n {
						colors.Set(op + 1, &interval{op + 1, r})
					}
				}

				locks.Del(op)
				unlocks.Set(op, 0)

			} else {
				it := colors.LowerBound(op)

				if it.Valid() {
					if it.Key() == op {
						colors.Del(op)

						if op < n {
							colors.Set(op + 1, it.Value().(*interval).r)
						}
					}
				}
				it.Prev()

				if it.node != nil {
					ival := it.Value().(*interval)

					if ival.l < op && ival.r >= op {
						colors.Del(ival.l)

						if op == ival.r {
							colors.Set(ival.l, &interval{ival.l, op -  1})
						} else {
							colors.Set(ival.l, &interval{ival.l, op -  1})
							colors.Set(ival.l, &interval{op +  1, ival.r})
						}
					}
				}

				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itu.Prev()
				itl.Prev()

				doScan := false

				if itl.node != nil {
					indexLock := itl.Key()

					if itu.node != nil {
						indexUnlock := itu.Key()

						if indexLock > indexUnlock {
							doScan = true
						}

					} else {
						doScan = true
					}

				}

				if doScan {
					itl := locks.UpperBound(op)
					itu := unlocks.UpperBound(op)

					var index int

					if itu.Valid() {
						if itl.Valid() {
							index = min(itu.Key(), itl.Key())

						} else {
							index = itu.Key()
						}

					} else {
						if itl.Valid() {
							index = itl.Key()

						} else {
							index = n
						}
					}

					if op < n {
						colors.Set(op + 1, &interval{op + 1, index})
					}
				}

				unlocks.Set(op, 0)
			}

			ops[op] = msg

		} else {

			if ops[op] == "lock" {
				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itl.Prev()
				itu.Prev()

				start := -1
				end := - 1

				if itl.node != nil {
					if itu.node != nil {

						if itu.Key() > itl.Key() {
							start = itu.Key() + 1
						}
					}

				} else {
					if itu.node != nil {
						start = itu.Key() + 1

					} else {
						start = 0
					}
				}

				itl = locks.UpperBound(op)
				itu = unlocks.UpperBound(op)

				if itl.Valid() {
					if itu.Valid() {
						m := min(itl.Key(), itu.Key())
						end = m - 1

					} else {
						end = itl.Key() - 1
					}
				} else {
					if itu.Valid() {
						end = itu.Key() - 1
					} else {
						end = n
					}
				}

				if start != -1 {
					colors.Del(start)
					colors.Set(start, &interval{start, end})
				}

				locks.Del(op)
				ops[op] = msg

			} else if ops[op] == "unlock" {
				itl := locks.LowerBound(op)
				itu := unlocks.LowerBound(op)
				itl.Prev()
				itu.Prev()

				start := -1
				end := -1

				if itl.node != nil {
					if itu.node != nil {

						if itu.Key() > itl.Key() {
							start = itu.Key() + 1
						}
					}

				} else {
					if itu.node != nil {
						start = itu.Key() + 1

					} else {
						start = 0
					}
				}

				itl = locks.UpperBound(op)
				itu = unlocks.UpperBound(op)

				if itl.Valid() {
					if itu.Valid() {
						m := min(itu.Key(), itl.Key())
						end = m - 1

					} else {
						end = itu.Key() - 1
					}

				} else {
					if itu.Valid() {
						end = itu.Key() - 1

					} else {
						end = n
					}
				}

				if colors.Contains(op + 1) {
					colors.Del(op + 1)
				}

				if start != -1 {
					colors.Set(start, &interval{start, end})
				}

				unlocks.Del(op)
				ops[op] = msg

			} else {
				ops[op] = msg
			}

		}

		it := colors.LowerBound(n)

		var rightMost *interval
		if it.Valid() {
			fmt.Println(ops[n])

		} else {
			it.Prev()
			if it.node == nil {
				fmt.Println("blue")
			} else {
				rightMost = it.Value().(*interval)
				if rightMost.r == 0 {
					fmt.Println("blue")
				} else {
					fmt.Println(ops[rightMost.r])
				}
			}
		}
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type intIntTreeMap struct {
	endNode   *nodeIntIntTreeMap
	beginNode *nodeIntIntTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntIntTreeMap struct {
	right   *nodeIntIntTreeMap
	left    *nodeIntIntTreeMap
	parent  *nodeIntIntTreeMap
	isBlack bool
	key     int
	value   int
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntIntTreeMap(less func(a int, b int) bool) *intIntTreeMap {
	endNode := &nodeIntIntTreeMap{isBlack: true}
	return &intIntTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intIntTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Set(key int, value int) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntIntTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intIntTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntIntTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intIntTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intIntTreeMap) Get(id int) (int, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intIntTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intIntTreeMap) Range(from, to int) (forwardIteratorIntIntTreeMap, forwardIteratorIntIntTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) LowerBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intIntTreeMap) UpperBound(key int) forwardIteratorIntIntTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntIntTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntIntTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intIntTreeMap) Iterator() forwardIteratorIntIntTreeMap {
	return forwardIteratorIntIntTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intIntTreeMap) Reverse() reverseIteratorIntIntTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntIntTreeMap(node)
	}
	return reverseIteratorIntIntTreeMap{tree: t, node: node}
}

func (t *intIntTreeMap) findNode(id int) *nodeIntIntTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.right != nil {
		return mostLeftIntIntTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntIntTreeMap(x *nodeIntIntTreeMap) *nodeIntIntTreeMap {
	if x.left != nil {
		return mostRightIntIntTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntIntTreeMap(x *nodeIntIntTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intIntTreeMap) insertFixup(x *nodeIntIntTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntIntTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntIntTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntIntTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntIntTreeMap(root *nodeIntIntTreeMap, z *nodeIntIntTreeMap) {
	var y *nodeIntIntTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntIntTreeMap(z)
	}
	var x *nodeIntIntTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntIntTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntIntTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntIntTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntIntTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntIntTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntIntTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntIntTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntIntTreeMap) Prev() {
	i.node = predecessorIntIntTreeMap(i.node)
	if i.node == nil {
		//panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntIntTreeMap) Value() int { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntIntTreeMap struct {
	tree *intIntTreeMap
	node *nodeIntIntTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntIntTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntIntTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntIntTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntIntTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntIntTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntIntTreeMap) Value() int { return i.node.value }

type intInterfaceTreeMap struct {
	endNode   *nodeIntInterfaceTreeMap
	beginNode *nodeIntInterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntInterfaceTreeMap struct {
	right   *nodeIntInterfaceTreeMap
	left    *nodeIntInterfaceTreeMap
	parent  *nodeIntInterfaceTreeMap
	isBlack bool
	key     int
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntInterfaceTreeMap(less func(a int, b int) bool) *intInterfaceTreeMap {
	endNode := &nodeIntInterfaceTreeMap{isBlack: true}
	return &intInterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Set(key int, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntInterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntInterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Get(id int) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intInterfaceTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Range(from, to int) (forwardIteratorIntInterfaceTreeMap, forwardIteratorIntInterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) LowerBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) UpperBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intInterfaceTreeMap) Iterator() forwardIteratorIntInterfaceTreeMap {
	return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intInterfaceTreeMap) Reverse() reverseIteratorIntInterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntInterfaceTreeMap(node)
	}
	return reverseIteratorIntInterfaceTreeMap{tree: t, node: node}
}

func (t *intInterfaceTreeMap) findNode(id int) *nodeIntInterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.right != nil {
		return mostLeftIntInterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.left != nil {
		return mostRightIntInterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intInterfaceTreeMap) insertFixup(x *nodeIntInterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntInterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntInterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntInterfaceTreeMap(root *nodeIntInterfaceTreeMap, z *nodeIntInterfaceTreeMap) {
	var y *nodeIntInterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntInterfaceTreeMap(z)
	}
	var x *nodeIntInterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntInterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntInterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntInterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntInterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntInterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntInterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Prev() {
	i.node = predecessorIntInterfaceTreeMap(i.node)
	if i.node == nil {

	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntInterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntInterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }