BST Problem


Problem Statement

You are given nn queries, each of the following form, either:

  • SEARCH x\text{SEARCH }x where xx is some integer, or
  • INSERT x\text{INSERT }x where xx is some integer Imagine you start with an empty collection of numbers. When you see INSERT x\text{INSERT }x you should add xx to your collection of numbers. Every time you see SEARCH x\text{SEARCH } x you should determine the first thing less than or equal to xx in your collection of numbers.

Input Format

Your first line will contain nn. Your next nn lines will contain one query each.

Output Format

For each SEARCH x\text{SEARCH } x query you should output the first thing less than or equal to xx in your current collection of numbers. If there is nothing less than or equal to xx, output −1-1.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5
  • −109≤ai≤109-10^9 \leq a_i \leq 10^9

Sample Cases

Input 1
7
INSERT 10
SEARCH 9
INSERT 3
INSERT 4
INSERT 8
SEARCH 3
SEARCH 7
Output 1
-1
3
4

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.