#P1327. 数列排序

数列排序

Description

Given a sequence aa that satisfies aiaja_i \not =a_j (iji\not=j), you are asked to sort this sequence in ascending order. Each time, you may swap any pair of numbers. What is the minimum number of swaps required?

Input Format

The first line contains an integer nn, the number of elements.

The second line contains nn integers separated by spaces, representing the sequence aa.

Output Format

Output a single line containing one integer, the minimum number of swaps.

8
8 23 4 16 77 -5 53 100

5


Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n1051\le n\le10^5, 231<ai<2311-2^{31}\lt a_i\lt2^{31}-1.

Translated by ChatGPT 5