Stone Arranging 2
시간 제한2초메모리 제한1024 MB
돌을 하나씩 오른쪽에 놓을 때마다 같은 색의 가장 가까운 이전 돌 이후 구간을 그 색으로 칠하고, 마지막 색을 출력한다.
문제
JOI-kun has go stones. The stones are numbered from to . The color of each stone is an integer between and , inclusive. In the beginning, the color of Stone () is .
From now, JOI-kun will perform operations. He will put the stones on the table in a line. The operation () will be performed as follows:
- JOI-kun will put Stone on the immediate right of Stone . However, when , JOI-kun will put Stone on the table.
- If there is a stone among Stones , , , whose current color is the same as Stone , let be the maximum index of such stones, and JOI-kun will paint all of Stones , , , with the color .
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.
출력
Write lines to the standard output. The -th line () should contain the color of Stone after the operations are performed.
제한
- .
- ().
- Given values are all integers.