Filling the bag

Ali Baba is hidden in the cave of the treasure, watching how the forty thieves leave jewels and take away jewels all the time. When the thieves depart, Ali Baba will fill his bag with the most valuable jewels, but he will have to make it quickly, so that the thieves cannot catch him. Therefore, at every moment he wants to know which are the jewels that he will have to take if he has the chance. Help him!

Input

Input begins with the number of jewels that fit in the bag (a number between 1 and 10510^5). Follow the actions of the thieves: If they leave a jewel, there is the word “leave” followed by the value of the jewel. If they take a jewel, there is the word “take” followed by the value of the jewel. The values are natural numbers, all different.

Output

For every action of the thieves, print the maximum value of the jewels that Ali Baba could take if the thieves left at that moment.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:16:19.010Z

© Jutge.org, 2006–2026.
https://jutge.org