eolymp
bolt
Try our new interface for solving problems
Problems

Second Maximum

Second Maximum

Implement the binary search tree for integers. The program reads a sequence of integers and builds a tree from them. Elements are inserted to the tree according to the search results of their place. If the item already exists in the tree, do not add it. The balance operations on the tree are not performed. Print the second biggest element in a built tree. It is guaranteed that it always exist. \InputFile The program receives a sequence of integers. The sequence ends with the number \textbf{0}, which means the end of input, do not add it to the tree. It is guaranteed that the input sequence contains no more than \textbf{10^5} numbers, each of them does not exceed \textbf{2·10^9} in absolute value. \OutputFile Print the second biggest element in a built tree. Example corresponds to the following tree: \includegraphics{https://static.e-olymp.com/content/79/7974f5e895071585d28e9cb1a4500776072c6850.jpg}
Time limit 1 second
Memory limit 64 MiB
Input example #1
7 3 2 1 9 5 4 6 8 0
Output example #1
8