Under construction

Still being built. Things may change

Way Home

Interview

Time limit2sMemory limit1024 MB

Summary
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 xx:

  • x>0x > 0: The sign with number xx becomes active.
  • x<0x < 0: If a sign with number −x-x appeared earlier on the road, its effect is canceled.
  • x=0x = 0: The currently active sign is canceled. If there is no active sign, nothing happens.

A number x≠0x \neq 0 appears on the road at most once. For example, if Chudakov passes the four signs 1,2,−2,01, 2, -2, 0 in this order, the active sign after −2-2 is 11.

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 nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), the number of signs on the road.

Each of the next nn lines contains one integer aia_i (−105≤ai≤105-10^5 \le a_i \le 10^5), the number written on the ii-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 00.

Examples1

  1. Example 1

    Input
    7
    1
    -1
    4
    2
    3
    -2
    0
    
    Expected output
    1
    0
    4
    2
    3
    3
    4