PivotOJ

Stone Arranging 2

시간 제한: 2000ms메모리 제한: 1024MB출처: JOI 2022-2023 본선BOJ 27536

문제

JOI-kun has NN go stones. The stones are numbered from 11 to NN. The color of each stone is an integer between 11 and 10910^9, inclusive. In the beginning, the color of Stone ii (1 ≤ i ≤ N) is AiA_i.

From now, JOI-kun will perform NN operations. He will put the stones on the table in a line. The operation ii (1 ≤ i ≤ N) will be performed as follows:

  1. JOI-kun will put Stone ii on the immediate right of Stone i1i - 1. However, when i=1i = 1, JOI-kun will put Stone 11 on the table.
  2. If there is a stone among Stones 11, 22, \dots, i1i - 1 whose current color is the same as Stone ii, let jj be the maximum index of such stones, and JOI-kun will paint all of Stones j+1j + 1, j+2j + 2, \dots, i1i - 1 with the color AiA_i.

In order to confirm whether the operations are correctly performed, JOI-kun wants to know in advance the colors of the stones after all the operations are performed.

Given information of the go stones, write a program which determines the colors of the stones after the N operations are performed.

입력

Read the following data from the standard input.

NN

A1A_1

A2A_2

\vdots

ANA_N

출력

Write NN lines to the standard output. The ii-th line (1 ≤ i ≤ N) should contain the color of Stone ii after the NN operations are performed.

예제

예제 1

입력
6
1
2
1
2
3
2
출력
1
1
1
2
2
2

예제 2

입력
10
1
1
2
2
1
2
2
1
1
2
출력
1
1
1
1
1
1
1
1
1
2
코드를 제출하려면 로그인하세요.