N = int(input())
A = list(map(int, input().split()))
print(sum([i == A[A[i] - 1] - 1 for i in range(N)]) // 2)
51710bbb3367b4990b3bdaf6fc827bbd14255810
<mask token>

<mask token>
print(sum([(i == A[A[i] - 1] - 1) for i in range(N)]) // 2)

N = int(input())
A = list(map(int, input().split()))
print(sum([(i == A[A[i] - 1] - 1) for i in range(N)]) // 2)

N = int(input())
A = list(map(int, input().split()))
print(sum([i == A[A[i] - 1] - 1 for i in range(N)]) // 2)