Convinced that happy cows generate more milk, Farmer John has installed a giant disco ball in his barn and plans to teach his cows to dance!
Looking up popular cow dances, Farmer John decides to teach his cows the "Bovine Shuffle". The Bovine Shuffle consists of his N cows (1≤N≤100,000) lining up in a row in some order, then performing successive "shuffles", each of which potentially re-orders the cows. To make it easier for his cows to locate themselves, Farmer John marks the locations for his line of cows with positions 1…N, so the first cow in the lineup will be in position 1, the next in position 2, and so on, up to position N.
A shuffle is described with N numbers, a1…aN, where a cow in position ii moves to position ai during the shuffle (and so, each ai is in the range 1…N). Every cow moves to its new location during the shuffle. Unfortunately, all the ai's are not necessarily distinct, so multiple cows might try to move to the same position during a shuffle, after which they will move together for all remaining shuffles.
Farmer John notices that some positions in his lineup contain cows in them no matter how many shuffles take place. Please help him count the number of such positions.
农场主约翰坚信快乐的奶牛能产生更多的牛奶,于是他安装了一个巨大的奶牛。 迪斯科舞会在他的谷仓里,并计划教他的奶牛跳舞!
查找流行的牛舞,农夫约翰决定教他的牛“牛” “洗牌”。牛洗牌包括他的N牛(1≤n≤100000)。 按一定顺序排成一行,然后依次执行“洗牌”。 其中有可能重新订购奶牛。为了让他的奶牛更容易 找到自己,农夫约翰用 位置1到N,所以第一头奶牛将排在第1位, 下一个位置在第2位,以此类推,直到N的位置。
洗牌是用N个整数a1…aN来描述的,在这里,牛处于位置。 i在洗牌期间移动到ai(因此,每个ai在 范围1到N)。在洗牌的时候,每头牛都会搬到新的地方。 不幸的是,所有的ai不一定是不同的,所以多头牛。 可能会在洗牌时尝试移动到相同的位置,然后他们会。 所有剩下的洗牌都要一起行动。
农民约翰注意到在他的阵容中有些位置上有奶牛 不管发生了多少次洗牌。请帮他数一下 就位。
The first line of input contains N, the number of cows. The next line contains the N integers a1…aN.
第一行输入 N,表示奶牛的数量。
下一行 包含N个整数a1…aN。
4
3 2 1 3
3