Shelves#452

Shelves

1 second
122.174 megabytes
Medium

On the shelf along the perimeter of the library reading room, there are volumes of a classic's works, numbered from to . The volumes are currently in random order. The librarian wants to arrange the volumes so that for each from to n-1, the volume is directly next to the volume i+1.

The librarian may swap any two volumes in one move. Find the minimum number of such swaps required to arrange the volumes in the desired order.

Input

The first line contains an integer (1 \leq n \leq 3000). Each of the next lines contains an integer, the volume number at that position. Each volume number from to appears exactly once.

Output

Print one integer: the minimum number of swaps the librarian must make.

Examples

Example 1

Loading
Loading