AT_abc436_e [ABC436E] Minimum Swap

Description

You are given an integer sequence $ P=(P _ 1,P _ 2,\ldots,P _ N) $ that is a permutation of $ (1,2,\ldots,N) $ . Here, it is guaranteed that $ P $ is not equal to $ (1,2,\ldots,N) $ . You want to perform the following operation zero or more times to make $ P $ match the sequence $ (1,2,\ldots,N) $ : - Choose a pair of integers $ (i,j) $ satisfying $ 1\le i\lt j\le N $ . Swap the values of $ P _ i $ and $ P _ j $ . Let $ K $ be the minimum number of operations required to make $ P $ match the sequence $ (1,2,\ldots,N) $ . Find the number of operations that can be **the first operation** in a sequence of operations that makes $ P $ match the sequence $ (1,2,\ldots,N) $ in $ K $ operations. Two operations are distinguished if and only if the chosen pairs of integers $ (i,j) $ are different.

Input Format

The input is given from Standard Input in the following format: > $ N $ $ P _ 1 $ $ P _ 2 $ $ \ldots $ $ P _ N $

Output Format

Print the answer.

Explanation/Hint

### Sample Explanation 1 For example, the goal can be achieved in three operations as follows: - Choose $ (i,j)=(1,2) $ . $ P $ becomes $ (1,3,4,2,5) $ . - Choose $ (i,j)=(2,4) $ . $ P $ becomes $ (1,2,4,3,5) $ . - Choose $ (i,j)=(3,4) $ . $ P $ becomes $ (1,2,3,4,5) $ . The goal cannot be achieved in two or fewer operations, so $ K=3 $ . As explained above, choosing $ (1,2) $ for the first operation allows the goal to be achieved in three operations. Additionally, if one of $ (1,3),(1,4),(2,3),(2,4),(3,4) $ is chosen for the first operation, then by performing the next two operations appropriately, $ P $ can be made equal to $ (1,2,3,4,5) $ . Therefore, print `6`. ### Constraints - $ 2\le N\le3\times10 ^ 5 $ - $ 1\le P _ i\le N\ (1\le i\le N) $ - $ P _ i\ne P _ j\ (1\le i\lt j\le N) $ - There exists $ 1\le i\le N $ such that $ i\ne P _ i $ . - All input values are integers.