Computer Hacking
Time limit2sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
Miles and Peter from a parallel universe stole a computer with secret data from the Alchemax laboratory. Now Miles is studying its contents. He opened the directory named <<SuperSecretData>> in the terminal. He noticed that files sometimes appear and disappear in this directory on their own. All file names consist of lowercase Latin letters.
At certain moments he wants to know the minimum number of key presses needed to type the name of a file that is in the directory at that moment. Initially the terminal contains an empty string. Miles can press keys for lowercase Latin letters, which appends that letter to the end of the string. He can also press the tab key. It appends letters to the end of the string while the next letter can be determined uniquely. That is, if the terminal contains string and there is a letter such that the set of files whose names start with equals the set of files whose names start with , then is appended to the end of . The string here means followed by .
For example, if the directory contains the files passwords and paroli, and the terminal is empty, pressing tab makes the terminal show pa. Pressing tab again does not change the string. If Miles then presses s, the terminal shows pas. If he presses tab after that, the terminal shows passwords.
Help Miles answer his questions.
Input
The first line contains one integer (), the number of queries. Each of the next lines is a query that starts with a character giving its type.
If the character is +, a file is added to the directory. Its name follows on the same line ().
If the character is -, a file is removed from the directory. The integer follows on the same line, the number of the file (). Files are numbered from in the order they appear.
If the character is ?, Miles asks the minimum number of buttons he must press to type the name of a file. The integer follows on the same line, the number of the file he asks about (). Files are numbered from in the order they appear.
The total length of all does not exceed . No two files in the directory have the same name at the same time. Each file is removed at most once. When a query of the third type is made, the file has already been added and has not yet been removed. The file numbers in queries of the second and third types do not exceed the number of files added by that moment.
Output
For each query of the third type, print the answer on a separate line.