beecrowd | 1200

BST Operations I

By Neilor Tonin, URI  Brazil

Timelimit: 1

Marcela needs your help to write a computer program about binary search tree. The program must have the following commands:

By using this program, at any time must be possible to insert a new element, print the Pre-order, In-order or Post-order traversal or search any element inside the tree.


The input contains N lines and each line contains an operation using letters (A-Z, a-z) over a binary search tree, that initially will be empty. The first line of input contains an insertion (I). The next lines can have any command described above, like the given example. The end of input is determined by EOF.

Obs: Consider that will not be repeated elements in the tree.


Each line of the input excepting the lines with the "I" command must produce one output line. The output must be acording to the given example, remembering that "existe" means exist and "nao existe" means don't exist in portuguese. There is no blank space after the last line char, otherwise you`ll get Presentation Error.

Sample Input Sample Output

I c
I f
I a
I h
P z
P h
I g

a c f h
c a f h
a h f c
z nao existe
h existe
a c f g h