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 i (for i=1,2,…) cancels the most recent operation of level at most i−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 X is performed, X is active. If X is an undo operation of level i, take the most recent active operation of level at most i−1, call it X1, and make X1 undone. If X1 is itself an undo operation, the operation X2 that X1 had undone becomes active again. The rule keeps applying: whenever the state of an undo operation Xj changes, the state of the operation Xj+1 that Xj 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 s, 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 s, and Ui is an undo operation of level i.
| Operation | E1 | E2 | E5 | U1 | U1 | U3 | E4 | U2 | U1 | U1 | E1 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Editor state | 0 | 1 | 2 | 5 | 2 | 1 | 2 | 4 | 2 | 1 | 0 | 1 |
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.
The first line contains the number of operations n (1≤n≤500000) performed by Byteasar.
Each of the next n lines contains one integer ai (−n≤ai≤n, ai=0) describing an operation. If ai>0, the operation is an editing operation that changes the editor state to ai. If ai<0, the operation is an undo operation of level −ai. Every undo operation in the input has an active operation of smaller level to cancel.
Print n lines. Line i contains the editor state after the first i operations of the input.