n=int(eval(input()));a=list(map(int,input().split()));print((sum([0,1][a[a[i]-1]-1==i]for i in range(n))//2))
n,*a=list(map(int,open(0).read().split()));print((sum(a[a[i]-1]==i+1for i in range(n))>>1))
n = int(eval(input()))
a = list(map(int, input().split()))
print((sum([0, 1][a[a[i] - 1] - 1 == i] for i in range(n)) // 2))

n, *a = list(map(int, open(0).read().split()))
print((sum(a[a[i] - 1] == i + 1 for i in range(n)) >> 1))

-n = int(eval(input())) -a = list(map(int, input().split())) -print((sum([0, 1][a[a[i] - 1] - 1 == i] for i in range(n)) // 2)) +n, *a = list(map(int, open(0).read().split())) +print((sum(a[a[i] - 1] == i + 1 for i in range(n)) >> 1))