P1368 Craft

Background

New template problem: [P13270 [Template] Minimal Representation](https://www.luogu.com.cn/problem/P13270).

Description

Xiaomin and Xiaoyan are good friends. They are playing a magical game called Minecraft. They are going to make a long strip craftwork composed of blocks. However, the blocks are currently in disorder, and due to the machine’s limitation, they can only move the leftmost block of the craftwork to the right end. They want to know, using only this single operation, how pretty the craftwork can become. To compare the beauty of two craftworks, compare them from the beginning. If at position $i$ the blocks differ, the one with the smaller defect score is prettier; if they are the same, continue to compare the block at position $i+1$. If all positions are the same, then the two craftworks are equally pretty.

Input Format

The first line contains an integer $n$, the number of blocks. The second line contains $n$ integers, which are the defect scores of the blocks from left to right. Each score is less than $30$.

Output Format

Output one line with $n$ integers, which are the defect scores from left to right of the prettiest craftwork.

Explanation/Hint

- For $20\%$ of the testdata, $n \le 1000$. - For $40\%$ of the testdata, $n \le 10^4$. - For $100\%$ of the testdata, $n \le 3\times 10^5$. Translated by ChatGPT 5