N=int(eval(input()))

*A,=list(map(int,input().split()))

i=0

ans=0

while i<N:

    if i+1==A[A[i]-1]:

        ans+=1

    i+=1

print((ans//2))
N,*A=list(map(int,open(0).read().split()))

print((sum(i+1==A[A[i]-1]for i in range(N))//2))
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
i = 0
ans = 0
while i < N:
    if i + 1 == A[A[i] - 1]:
        ans += 1
    i += 1
print((ans // 2))

N, *A = list(map(int, open(0).read().split()))
print((sum(i + 1 == A[A[i] - 1] for i in range(N)) // 2))

-N = int(eval(input())) -(*A,) = list(map(int, input().split())) -i = 0 -ans = 0 -while i < N: -    if i + 1 == A[A[i] - 1]: -        ans += 1 -    i += 1 -print((ans // 2)) +N, *A = list(map(int, open(0).read().split())) +print((sum(i + 1 == A[A[i] - 1] for i in range(N)) // 2))