Mirko is a genius. But the purpose of his inventions is not always obvious. His
latest invention, the Shuffle-o-matic 3175, is one of those. The Shuffle-o-matic
is used in a very special way. First Mirko places
After experimenting with the machine Mirko decided to rest a bit on the floor.
There he noticed a piece of output tape. The piece is neatly cut just before the
He now wonders how many rows on that piece of paper have the property that all numbers in the row, that are still on the paper, are in the exact same spot they were before all the shuffling began.
Input Specification
The first line of input contains integers
The second line contains the shuffle sequence. The sequence is given as a
permutation of numbers
Output Specification
In the first and only line of input print the number of rows that have the property Mirko is looking for.
Scoring
Test cases worth
Sample Input 1
4 1 5 0 1
1 3 4 2
Sample Output 1
2
Explanation for Sample Output 1
Shuffle-o-matic outputs:
Mirko finds:
The first and fourth rows are interesting to Mirko.
Sample Input 2
7 3 8 1 2
2 3 1 6 4 7 5
Sample Output 2
0
Explanation for Sample Output 2
Shuffle-o-matic outputs:
Sample Input 3
6 2 11 3 0
6 3 5 4 2 1
Sample Output 3
1
Explanation for Sample Output 3
Shuffle-o-matic outputs:
Comments