Farmer John is convinced that happy cows give more milk, so he has hung a giant disco ball in his barn and wants to teach his cows to dance.
After looking up popular cow dances, Farmer John settles on the Bovine Shuffle. In the Bovine Shuffle his N cows (1≤N≤100000) line up in a row and then perform one shuffle after another, and each shuffle can reorder the line. So the cows can find their own spots, Farmer John numbers the places in the row from 1 to N. At the start each place holds exactly one cow.
One shuffle is described by N numbers a1,…,aN. When a shuffle happens, every cow standing at place i moves to place ai. Each ai is between 1 and N. All cows move to their new places at the same time. The values ai are not guaranteed to be distinct, so several cows can end up at the same place, and once cows share a place they move together for all remaining shuffles.
Farmer John notices that some places hold cows no matter how many shuffles take place. Count how many such places there are.