Moves You Need to Make
면접 대비시간 제한2초메모리 제한512 MB
순열이 주어질 때, 첫째와 마지막 원소를 최대 한 번 교환할 수 있다는 조건에서 정렬에 필요한 인접 교환의 최소 횟수를 구한다.
문제
You are given a permutation.
A move is one of the following:
- Swap two adjacent elements.
- Swap the first and the last elements. Can be used at most once.
What is the minimum number of moves you need to make to sort the given permutation?
입력
The first line contains a single integer (), the length of the permutation.
The second line contains integers (), the permutation itself.
출력
Output a single integer --- the minimum number of moves you need to make to sort the given permutation.