Editor

No attempts yetTime limit3sMemory limit512 MB

Problem

Byteasar is building a text editor. It has two kinds of operations: an editing operation that changes the text, and an undo operation that cancels an earlier operation. The undo of this editor works on several levels.

An editing operation is an operation of level 0. An undo operation of level ii (for i=1,2,i = 1, 2, \dots) cancels the most recent operation of level at most i1i - 1 that is not already undone. So an undo of level 1 reaches only editing operations, and an undo of level 2 reaches editing operations and undo operations of level 1, but no undo operation of a higher level.

More formally, every operation already performed is either active or undone. Right after an operation XX is performed, XX is active. If XX is an undo operation of level ii, take the most recent active operation of level at most i1i - 1, call it X1X_1, and make X1X_1 undone. If X1X_1 is itself an undo operation, the operation X2X_2 that X1X_1 had undone becomes active again. The rule keeps applying: whenever the state of an undo operation XjX_j changes, the state of the operation Xj+1X_{j+1} that XjX_j had undone changes too. The chain of state changes ends when it reaches an editing operation.

The current contents of the editor are described by a single integer ss, called the editor state, which is 0 at the beginning. Each editing operation names the editor state it produces. The current editor state is the value of the most recent active editing operation, and it is 0 when no editing operation is active.

The table below shows a run of operations and the editor state after each one. Es is an editing operation that changes the state to ss, and Ui is an undo operation of level ii.

OperationE1E2E5U1U1U3E4U2U1U1E1
Editor state012521242101

Byteasar first performs three editing operations, so the state goes from 0 to 1, then to 2, then to 5. The two undo operations of level 1 cancel E5 and E2, which brings the state back to 1. The undo of level 3 cancels the last U1, so E2 becomes active again and the state is 2 once more. Then U2 cancels E4, the next U1 cancels the restored E2, the last U1 cancels E1, and the final operation is an editing operation that sets the state to 1.

Report the editor state after every operation.

Input

The first line contains the number of operations nn (1n5000001 \le n \le 500000) performed by Byteasar.

Each of the next nn lines contains one integer aia_i (nain-n \le a_i \le n, ai0a_i \ne 0) describing an operation. If ai>0a_i > 0, the operation is an editing operation that changes the editor state to aia_i. If ai<0a_i < 0, the operation is an undo operation of level ai-a_i. Every undo operation in the input has an active operation of smaller level to cancel.

Output

Print nn lines. Line ii contains the editor state after the first ii operations of the input.