Hide

Problem C
Röðunarrugl

Languages en is
While waiting for the pizza from Trominos those who have arrived to the KFFÍ party are going to watch something. There were few suggestions for what to watch so eventually Atli suggests Bogletics, which no one bothers to veto. Thus they begin to watch. At some point the main character encounters a bit of a problem. He has $n$ items and $n + 1$ places to store them. Since he can’t carry a whole lot and already has some things he can’t part with, he can only carry one item at once. Currently the items are arranged in some order in places $1$ through $n$, but not in the order he wishes them to be. The only thing he can do to fix this is move one item from its current location to an empty place. How many such moves must he make to get everything into its desired place?

Input

The first line of the input contains a single integer $n$ satisfying $1 \leq n \leq 10^5$, the number of items to rearrange. Next there is a line with $n$ integers $k_1, k_2, \dots , k_ n$ satisfying $1 \leq k_ i \leq n$. The value $k_ i$ is the place the main character wants the item that is currently at location $i$ to be in. None of the $k_ i$ will equal $n + 1$ as that place should be empty at the end. The values will be unique as well.

Output

A single line with an integer giving the minimum number of moves needed to get everything to the desired place.

Scoring

Group

Points

Constraints

1

20

$n \leq 5$

2

30

$n \leq 10^3$

3

50

No further constraints

Sample Input 1 Sample Output 1
4
1 3 2 4
3
Sample Input 2 Sample Output 2
8
7 4 6 8 1 3 5 2
11

Please log in to submit a solution to this problem

Log in