#P1368. 工艺

工艺

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 ii 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+1i+1. If all positions are the same, then the two craftworks are equally pretty.

Input Format

The first line contains an integer nn, the number of blocks.

The second line contains nn integers, which are the defect scores of the blocks from left to right. Each score is less than 3030.

Output Format

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

10
10 9 8 7 6 5 4 3 2 1

1 10 9 8 7 6 5 4 3 2

Hint

  • For 20%20\% of the testdata, n1000n \le 1000.
  • For 40%40\% of the testdata, n104n \le 10^4.
  • For 100%100\% of the testdata, n3×105n \le 3\times 10^5.

Translated by ChatGPT 5