Way Home
InterviewTime limit2sMemory limit1024 MB
Given a stream of signs where positive x activates x, -x cancels x, and 0 cancels the active sign, print the active sign after each step.
- Level
Medium4 of 10
- Topics
- Stack, Implementation
- Solved
- No attempts yet
Signs
On his way home from work, Gennady Evgenyevich Chudakov noticed several road signs placed along the road. Each sign is a plate with a number written on it. At any moment, the active sign is the most recent sign that has not been canceled among all signs seen so far. For a sign with number :
- : The sign with number becomes active.
- : If a sign with number appeared earlier on the road, its effect is canceled.
- : The currently active sign is canceled. If there is no active sign, nothing happens.
A number appears on the road at most once. For example, if Chudakov passes the four signs in this order, the active sign after is .
Chudakov wants to know the active sign after each new sign he passes, but he has no time to solve this because he is busy with other things. Help him.
Input
The first line contains one integer (), the number of signs on the road.
Each of the next lines contains one integer (), the number written on the -th sign that Chudakov passes.
Output
For each sign, print on a new line the number on the active sign after applying that sign's instruction. If there is no active sign, print .