| SashaT9 Contest 1 |
|---|
| Finished |
You are given a permutation $$$a$$$ of length $$$n$$$. You can perform the following operation:
Your task is to sort the permutation with minimal total cost.
The first contains a single integer $$$n$$$ ($$$1\le n\le 2\cdot 10^5$$$) — the length of the permutation $$$a$$$.
The second line contains $$$n$$$ integers $$$a_1, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — elements of permutation $$$a$$$.
Output the minimal total cost.
6 3 1 2 4 6 5
17
4 1 4 3 2
9
In the first sample, you can perform the following operations:
| Name |
|---|


