QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#14740. Sorting Robot Arm

统计

To sort items of varying heights from lowest to highest, engineers have invented a sorting robotic arm. It follows a simple sorting rule: in the first operation, it finds the position $P_1$ of the lowest item and reverses the items from the start to $P_1$; in the second operation, it finds the position $P_2$ of the second-lowest item and reverses the items from the second position to $P_2$... eventually, all items will be sorted.

The image above shows an example: before the first operation, the lowest item is at position 4, so the items from 1 to 4 are reversed; before the second operation, the second-lowest item is at position 6, so the items from 2 to 6 are reversed...

Your task is to write a program to determine the sequence of operations, i.e., the position $P_i$ of the lowest item before each operation, so that the robotic arm can work. Note that if there are items with the same height, you must ensure that their relative order after sorting remains the same as it was initially.

Input

The first line contains a positive integer $n$, representing the number of items to be sorted. The second line contains $n$ space-separated integers $a_i$, representing the height of each item.

Output

Output a single line containing $n$ space-separated integers $P_i$.

Examples

Input 1

6
3 4 5 1 6 2

Output 1

4 6 4 5 6 6

Input 2

4
3 3 2 1

Output 2

4 2 4 4

Constraints

For 30% of the data: * $1 \le n \le 1000$

For 100% of the data: $1 \le n \le 100000$ $1 \le a_i \le 2000000000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.