Sorting
Medium
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
N
cards are numbered from 1 to N
(1 ≤ N ≤ 32767
). These cards have been shuffled and placed in a single row on the table, from left to right. Your task is to determine the minimum number of swaps needed to arrange the cards in ascending order.
Input
The input consists of a single line. It starts with the integer N
, followed by N
distinct natural numbers, each not exceeding N
. These numbers represent the sequence of cards as they are currently laid out on the table.
Output
Output a single integer representing the minimum number of swaps required to sort the cards in ascending order.
Examples
Input #1
Answer #1
Submissions 352
Acceptance rate 21%