There are N rabbits, numbered 1 through N.  The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.  For a pair of rabbits i and j (i＜j), we call the pair (i，j) a _friendly pair_ if the following condition is met.    * Rabbit i likes rabbit j and rabbit j likes rabbit i.  Calculate the number of the friendly pairs.
N = int(input())
rs = list(map(int, input().split()))
numpair = 0
for i in range(N):
	if (i+1) == rs[rs[i] - 1]:
		numpair+=1
print(numpair/2)
N = int(input())
rs = list(map(int, input().split()))
numpair = 0
for i in range(N):
	if (i+1) == rs[rs[i] - 1]:
		numpair+=1
print(numpair//2)