Stone Arranging 2

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

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 (1iN1 ≤ i ≤ N) is A_iA\_i.

From now, JOI-kun will perform NN operations. He will put the stones on the table in a line. The operation ii (1iN1 ≤ 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 A_iA\_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

A_1A\_1

A_2A\_2

\vdots

A_NA\_N

출력

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

제한

  • 1N200,0001 ≤ N ≤ 200\\,000.
  • 1A_i1091 ≤ A\_i ≤ 10^9 (1iN1 ≤ i ≤ N).
  • Given values are all integers.