import numpy as np

n = int(eval(input()))

A = np.array(list(map(int, input().split())))

A -= 1



ans = 0

seen = [0] * n

for i, ai in enumerate(A):

    if seen[i]:

        continue

    seen[i] = 1

    if A[ai] == i:

        ans += 1

        seen[ai] = 1



print(ans)

N = int(eval(input()))

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



ans = 0

for i, a in enumerate(A):

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

        ans += 1

ans //= 2

print(ans)

import numpy as np

n = int(eval(input()))
A = np.array(list(map(int, input().split())))
A -= 1
ans = 0
seen = [0] * n
for i, ai in enumerate(A):
    if seen[i]:
        continue
    seen[i] = 1
    if A[ai] == i:
        ans += 1
        seen[ai] = 1
print(ans)

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

-import numpy as np - -n = int(eval(input())) -A = np.array(list(map(int, input().split()))) -A -= 1 +N = int(eval(input())) +A = list(map(int, input().split())) -seen = [0] * n -for i, ai in enumerate(A): -    if seen[i]: -        continue -    seen[i] = 1 -    if A[ai] == i: +for i, a in enumerate(A): +    if A[a - 1] == i + 1: -        seen[ai] = 1 +ans //= 2