atcoder#ABC240D. [ABC240D] Strange Balls

[ABC240D] Strange Balls

Score : 400400 points

Problem Statement

Takahashi has NN balls. Each ball has an integer not less than 22 written on it. He will insert them in a cylinder one by one. The integer written on the ii-th ball is aia_i.

The balls are made of special material. When kk balls with kk (k2)(k \geq 2) written on them line up in a row, all these kk balls will disappear.

For each ii (1iN)(1 \leq i \leq N), find the number of balls after inserting the ii-th ball.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 2ai2×105(1iN)2 \leq a_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 \ldots aNa_N

Output

Print NN lines. The ii-th line (1iN)(1 \leq i \leq N) should contain the number of balls after inserting the ii-th ball.

5
3 2 3 2 2
1
2
3
4
3

The content of the cylinder changes as follows.

  • After inserting the 11-st ball, the cylinder contains the ball with 33.
  • After inserting the 22-nd ball, the cylinder contains 3,23, 2 from bottom to top.
  • After inserting the 33-rd ball, the cylinder contains 3,2,33, 2, 3 from bottom to top.
  • After inserting the 44-th ball, the cylinder contains 3,2,3,23, 2, 3, 2 from bottom to top.
  • After inserting the 55-th ball, the cylinder momentarily has 3,2,3,2,23, 2, 3, 2, 2 from bottom to top. The two consecutive balls with 22 disappear, and the cylinder eventually contains 3,2,33, 2, 3 from bottom to top.

10
2 3 2 3 3 3 2 3 3 2
1
2
3
4
5
3
2
3
1
0