Find the second smallest value in a BST

Given an empty binary search tree with no nodes, you are asked to perform 2 kinds of queries:
  1. insert x - insert the value x in the BST
  1. smallest - print the second smallest element in the BST
Given q queries, you are asked to write a program to perform these queries.

Input

The first line of the input contains a single number q (1 ≤ q ≤ 1000).
The next q lines contain queries. For all the insert queries, the value of x does not exceed in absolute value. For all the smallest queries, it’s guaranteed that the BST has at least 2 elements.

Output

For each smallest query, the program should print the second smallest element in the binary search tree.

Examples

Input
Output
7 insert 2 insert 1 smallest insert 10 smallest insert -1 smallest
2 2 1
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue