AT_arc225_d [ARC225D] Gap Swap (easy)

Description

**This problem has a similar setting to Problem E, but the cost of the operation is different.** There is a permutation $ P $ of $ (1,2,\ldots,N) $ . You can perform the following operation on $ P $ . - Choose integers $ i $ and $ j $ satisfying $ 1 \le i < j \le N $ . Here, $ P_k=k $ must hold for every integer $ k $ satisfying $ i < k < j $ . Then, swap $ P_i $ and $ P_j $ . This operation incurs a **cost of $ \boldsymbol{j-i} $** . Note that if $ i+1=j $ , there is no integer $ k $ satisfying $ i

Input Format

The input is given from Standard Input in the following format: > $ N $ $ P_1 $ $ P_2 $ $ \ldots $ $ P_N $

Output Format

Output the answer.

Explanation/Hint

### Sample Explanation 1 For example, by performing two operations as follows, $ P $ can be sorted into ascending order with a total cost of $ 6 $ . - First operation: choose $ i=4, j=5 $ , and swap $ P_4, P_5 $ . This costs $ 1 $ . - Second operation: choose $ i=1, j=6 $ , and swap $ P_1, P_6 $ . This costs $ 5 $ . $ P $ cannot be sorted into ascending order with a cost less than $ 6 $ , so the answer is $ 6 $ . ### Sample Explanation 2 The required total cost can be $ 0 $ . ### Constraints - $ 2 \le N \le 5\times 10^5 $ - $ 1 \le P_i \le N $ - $ P $ is a permutation of $ (1,2,\ldots,N) $ . - All input values are integers.