Feng Shui
시간 제한1초메모리 제한2048 MB
순열이 주어질 때, 한 지점을 기준으로 앞은 감소하고 뒤는 증가하도록 만드는 최소 인접 교환 횟수를 구한다.
문제
You own flower pots (numbered from to ) displayed in order from west to east. Each flower pot has a different height; flower pot is the th shortest flower pot by height. In other words, the array is a permutation of .
After learning about Feng Shui (a practice of arranging pieces in living spaces to create balance), your house is healthier if you arrange the flower pots as follows. There should exist an integer such that , for all , and for all . You are allowed to swap adjacent flower pots zero or more times.
As the flower pots are fragile, you want to minimize the number of swaps. Determine the minimum number of swaps such that the flower pots follow the Feng Shui rule.
입력
The first line consists of an integer ().
The second line consists of integers (). The array is a permutation of .
출력
Output a single integer representing the minimum number of swaps such that the flower pots follow the Feng Shui rule.