eolymp
bolt
Try our new interface for solving problems
Problems

Similar numbers

Similar numbers

In developing the system of data analysis needed to solve the following particular problem. There is a set of integers (initially empty) and a sequence of queries of three types: \begin{itemize} \item \textbf{ADD x} --- add an element x in the set (if an element already exists, then the set does not change) \item \textbf{DEL x} --- delete element x from the set (if no such element, then the set does not change) \item \textbf{FIND} --- find and display the distance between the two closest elements in the set. This ensures that the set has at least two elements. \end{itemize} Required to fulfill a given sequence of requests. \InputFile The first line contains one integer \textbf{N} (\textbf{1} <= \textbf{N} <= \textbf{100 000}) --- total number of requests. In each of the next \textbf{N} lines of a written request pursuant to the above format. All numeric values in the query are in the range from \textbf{1} to \textbf{1 000 000 000}. \OutputFile Bring one number in the row for each query type \textbf{FIND} --- the distance between the two closest elements in the set at the time of the query.
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
7
ADD 1
ADD 5
ADD 4
ADD 6
FIND
DEL 5
FIND
Output example #1
1
2
Author Igor Andrianov