#d11406. 双端队列
双端队列
Deque
Problem Description
You are given a sequence of length and an empty deque.
You must insert the numbers of the sequence into the deque one by one, in order. For each number you may choose to push it to the front or to the back of the deque.
Minimize the number of inversions in the final sequence obtained from the deque.
Input Format
The first line contains an integer , the length of the sequence ().
The second line contains integers , the given sequence ().
Output Format
Output one integer on a single line: the minimum possible number of inversions.
Sample Input
4
3 7 5 5
Sample Output
2