Cranes

No attempts yetTime limit1sMemory limit128 MB

Problem

The BeczkoBit factory produces barrels for pickling bytes. The production line is fully automated, and the bottleneck is the warehouse. In the warehouse the finished barrels must be lined up in order of size, from the smallest to the largest. All barrels have distinct sizes.

The sorting is carried out by a team of cranes. Each crane can swap the positions of any two barrels. The cranes work in parallel, and a single swap by one crane takes 11 unit of time. During any one unit of time each barrel may be moved by at most one crane, so two swaps performed in the same unit of time may not touch the same barrel.

Find the minimum time (number of time units) needed to arrange the barrels in ascending order of size.

Input

The first line contains an integer nn (1n1000001 \le n \le 100\,000), the number of barrels. The second line contains nn distinct integers from {1,2,,n}\{1, 2, \ldots, n\}, giving the sizes of the barrels in the order they stand in the warehouse. The barrel in the first position is described by the first number, and the barrel in the last position by the last number.

Output

Print a single integer on one line: the minimum number of time units needed to sort the barrels into ascending order of size.