CSES - Aalto Competitive Programming 2024 - wk8 - Mon - Optimal sort
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are given an array aa of length nn. You should sort the array in increasing order by performing the following operation: picking two of its elements and swap them. Find an optimal way to sort the array.

Input

The first line contains a single integer nn. The next line contains nn integers a1,a2,,ana_1,\,a_2,\dots,\,a_n.

Output

Print the minimum number of operations required to sort the array.

Constraints

  • 1n1051 \leq n \leq 10^5
  • 1ai1091 \leq a_i \leq 10^9
  • aiaja_i \neq a_j if iji \neq j

Example 1

Input:

5
1 11 9 19 4

Output:

2

Example 2

Input:

10
18 13 20 12 4 5 19 15 14 11

Output:

7