Minimum Number Of Swaps Required To Sort An Array

hard
Given an array of n distinct elements, find the minimum number of swaps required to sort the array.

Input Format

First line contains an integer N . Second line has 2 space separated integers ai and bi.

Output Format

Print in one line the minimum number of swaps required to sort the given array.

Constraints

1 <= n <= 1000000
1 <= arr[i] <= 1000000000

Example

Input
5
10 19 6 3 5
Output
2
Previous
Satisfiability Of Equality Equation
Next
Remove Max Number Of Edges To Keep Graph Fully Traversable

Related Questions