Sorted Arrangement
Medium
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
There is a container that is open from both ends and is always sorted. To insert an element, its position is determined, then each of the elements to the left or to the right of that position is removed. The new element is inserted, then the removed elements are added back. Each removal or insertion is an operation. Determine the minimum number of operations after inserting a list of integers into an empty list.
Input
The first line contains number n (1 ≤ n ≤ 10^6
). The next line contains n integers in the range from 1 to 10^6
.
Output
Print the minimum number of operations to create the sorted list.
Examples
Input #1
Answer #1
Submissions 338
Acceptance rate 14%