Moves You Need to Make

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are given a permutation.

A move is one of the following:

  1. Swap two adjacent elements.
  2. 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 nn (1n31051 \leq n \leq 3 \cdot 10^5), the length of the permutation.

The second line contains nn integers a_ia\_i (1a_in1 \leq a\_i \leq n), the permutation itself.

출력

Output a single integer --- the minimum number of moves you need to make to sort the given permutation.