Problem:
 Score : 200 points    Problem Statement 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.      Constraints  2≤N≤10^5  1≤a_i≤N  a_i≠i         Input The input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print the number of the friendly pairs.        Sample Input 1 4
2 1 4 3      Sample Output 1 2  There are two friendly pairs: (1，2) and (3，4) .       Sample Input 2 3
2 3 1      Sample Output 2 0  There are no friendly pairs.       Sample Input 3 5
5 5 5 5 1      Sample Output 3 1  There is one friendly pair: (1，5) .

Solution (Python):
n = int(input())
alist = list(map(int, input().split()))
ans = 0
for i, a in enumerate(alist):
  if alist[a - 1] == i + 1:
    ans += 1
print(ans // 2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  if a[a[i]-1] == i+1:
    ans += 1
print(ans//2)

Solution (Python):
n=int(input());a=list(map(int,input().split()));ans=0
for i in range(n):
  if i+1==a[a[i]-1]:ans+=1
print(ans//2)

Solution (Python):
N = int(input())
A = [int(i)-1 for i in input().split()]

ans = 0
for i in range(N):
  if A[A[i]]==i: 
    ans += 1
print(ans//2)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
cnt = 0

for i, a_i in enumerate(a, 1):
    if a_i > i and a[a_i-1] == i:
        cnt += 1

print(cnt)

Solution (Python):
N=int(input())
A=list(map(int,input().split(' ')))
like={(i+1):A[i] for i in range(N)}
print(int(len([1 for i in range(N) if (i+1)==like[like[i+1]]])/2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
  a[i] -= 1

for i in range(n):
  if a[a[i]] == i:
    ans += 1
      
print(ans//2)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
M = []
for i in range(N):
  if i+1 > L[i]:
    M.append((L[i],i+1))
  else:
    M.append((i+1,L[i]))
M = list(set(M))
print(len(L)-len(M))

Solution (Python):
size = int(input())
rabbits = list(map(int, input().split()))
count = 0
for i in range(size):
    if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
        count += 1
print(count)

Solution (Python):
n = int(input())
l = [0] + list(map(int, input().split()))
cnt = 0
for i in range(1, n+1):
  if l[l[i]] == i:
    cnt += 1
print(cnt//2)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

dic = {}
for i in range(N):
    dic[i] = A[i] - 1
   
res = 0
for i in range(N):
    if dic[A[i] - 1] == i:
        res += 1
        
        
print(res//2)

Solution (Python):
n,*a=map(int,open(0).read().split());print(sum(a[~-a[i]]==-~i for i in range(n))>>1)

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

Solution (Python):
n=int(input());s=input().split();print(n-len(set(tuple(sorted([i+1,int(s[i])]))for i in range(n))))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
c=n
for i in range(n):
  if i+1!=l[l[i]-1]:
    c-=1
print(c//2)

Solution (Python):
N = int(input())
As = [A-1 for A in map(int, input().split())]

ans = 0
for i, A in enumerate(As):
    if As[A] == i:
        ans += 1
print(ans // 2)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(n):
    if A[A[i]-1]==i+1:
        ans+=1
print(ans//2)

Solution (Python):
N = int(input())
n = list(map(int,input().split()))
ans  = 0
for i in range(N):
    if n[n[i]-1] == i+1:
        ans += 1 
print(ans // 2)

Solution (Python):
n = int(input())
a = [int(m) for m in input().split()]
pair = []
for i in range(n):
  pair.append([i + 1, a[i]])

for i in range(n):
  pair[i].sort()
tuplepair = []
for i in range(n):
  tuplepair.append((pair[i][0], pair[i][1]))
print(n - len(set(tuplepair)))

Solution (Python):
N = int(input())
A = [0] + list(map(int, input().split()))
res = 0
for i in range(1, N):
    if i == A[A[i]]:
        res += 1
        A[A[i]] = 0
print(res)

Solution (Python):
n = int(input())
a = list(int(i) for i in input().split())
ans = 0
for i in range(n):
  if i == a[(a[i])-1]-1:
    ans += 1

print(ans//2)

Solution (Python):
n = int(input())
nums = list(map(int,input().split(' ')))
count = 0
for i in range(n):
    if i + 1 == nums[nums[i] - 1]:
        count += 1
print(count // 2)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
        a[i]=0
print(c)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
        a[i]=n+2
print(c)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))


ans=0

for i in range(n):
    if i+1==a[a[i]-1]:
        ans=ans+1

print(ans//2)

Solution (Python):
N=int(input())
a=[int(i)-1 for i in input().split()]
ans2=0
for i in range(N):
    if a[a[i]]==i:
        ans2+=1
ans=ans2//2
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

cnt=0
for j in range(N):
    if j+1==A[A[j]-1]:
        cnt+=1
        
print(cnt//2)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=0
for i in range(N):
    if i+1==a[a[i]-1]:
        b+=1
print(b//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i+1 == a[a[i]-1]:
        ans += 1
print(ans//2)

Solution (Python):
N = int(input())
A = [int(_) - 1 for _ in input().split()]
ans = 0
for i in range(N):
    if i < A[i] and A[A[i]] == i:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if i+1==a[a[i]-1]:
        c+=1
print(c//2)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

cnt = 0
for i in range(N):
  if A[A[i]-1] == i+1:
    cnt += 1
    
print(cnt // 2)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N) :
    if i == L[L[i]-1]-1 :
        ans += 1
ans //= 2
print(ans)

Solution (Python):
n = int(input())
a = [0] + list(map(int,input().split()))
c = 0
for i in range(1,n+1):
  if a[a[i]] == i:
    c += 1
print(c//2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

ans = 0
for i in range(N):
    j = A[i] - 1
    if i < j and A[j] - 1 == i:
        ans += 1
print(ans)

Solution (Python):
input();*a,=map(int,input().split());print(sum(a[a[i]-1]==i+1for i in range(len(a)))>>1)

Solution (Python):
input();a=list(map(int,input().split()));print(sum([a[i]>a[a[i]-1]==i+1for i in range(len(a))]))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
res = 0
for i in range(n):
    if a[i]>i+1 and a[a[i]-1]==i+1:
        res += 1
print(res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[a[i]-1]==i+1:c+=1
print(int(c/2))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
count=0
for i in range(n):
    if a[a[i]-1]==i+1:count+=1
print(count//2)

Solution (Python):
n = int(input())
list_a = list((map(int, input().split())))
for i in range(0,n):
    list_a[i] -= 1
ans = 0
for i in range(0,n):
    if list_a[list_a[i]] == i:
        ans += 1
print(ans//2)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)):
    if A[A[i]-1]-1 == i:
        ans += 1
print(ans // 2)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
cnt =  0 
for i in range(N):
    if a[a[i]-1]-1==i: cnt += 1
print(cnt//2)

Solution (Python):
N=int(input())
a=[int(i)-1 for i in input().split()]
ans=0
for i in range(N):
  if a[a[i]]==i:
    ans+=1
print(ans//2)

Solution (Python):

from sys import stdin

s_in = lambda: stdin.readline()[:-1] 
d_in = lambda: int(stdin.readline()) 
ds_in = lambda: list(map(int, stdin.readline().split())) 


N = d_in()
a_list = ds_in()

ans = 0
for i, a in enumerate(a_list):
	if i == a_list[a-1] - 1:
		ans += 1

print(ans // 2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
checklist = []
for i in range(N):
    cl = [i, a[i] - 1]
    cl.sort()
    checklist.append(cl)
cnt = 0
checklist.sort()
for i in range(1, N):
    if checklist[i] == checklist[i - 1]:
        cnt += 1
print(cnt)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  if a[a[i] - 1] == i + 1:
    ans += 1
print(ans // 2)

Solution (Python):
n=int(input())
d=set()
v=0
for i,j in enumerate(map(int,input().split()),start=1):
  t=tuple(sorted([i,j]))
  if t in d:
    v+=1
  else:
    d.add(t)
print(v)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()

ans = 0
for i in range(N):
	if i == aa[aa[i]-1]-1:
		ans += 1

print(ans//2)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

res = 0

for i in range(n):
    if a[a[i]-1]-1 == i:res +=1

print(int(res/2))

Solution (Python):
n = int(input())
an = input().split()
a = []
ans = 0
for i in range(0, n):
    temp = int(an[i])-1
    a.append(temp)
for i in range(0, n):
    if(i == a[a[i]]):
        ans += 1
print(ans//2)

Solution (Python):
n=int(input());a=list(map(int,input().split()));print(sum([0,1][a[a[i]-1]-1==i]for i in range(n))//2)

Solution (Python):
N = int(input())
A = list(map(lambda x: int(x)-1, input().split()))

ans = 0
for i in range(N):
    if A[A[i]] == i:
        ans += 1
print(ans // 2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    i_loves = a[i] - 1
    if a[i_loves] == i + 1:
        cnt += 1
print(cnt // 2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

count = 0

for i in range(len(a)):
    if a[a[i] - 1] == i + 1:
        count += 1

print(int(count/2))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(N):
	if a[a[i] - 1] == i + 1:
		c += 1

print(int(c / 2))

Solution (Python):
N = int(input())
jk =0
le = list(map(int,input().split()))

le = [0] + le
for i in range(N):
    if le[le[i]] == i:
        jk += 1

print(jk // 2)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

result = 0
for i, v in enumerate(a, 1):
    if a[v - 1] == i:
        a[i - 1] = -1
        result += 1
print(result)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
res = 0

for i in range(n):
  sel = a[i] -1
  if a[sel] == i+1:
    res += 1
else:
  print(int(res/2))

Solution (Python):



if __name__ == '__main__':
    n = int(input())
    a = list(map(lambda x: int(x) - 1, input().split()))
    count = 0

    
    
    for i in range(len(a)):
        if i == a[a[i]]:
            count += 1

    print(count // 2)

Solution (Python):



if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for i in range(len(a)):
        if i == a[a[i] - 1] - 1:
            count += 1

    print(count // 2)

Solution (Python):
n=int(input());*a,=map(int,input().split());print(sum(a[~-a[i]]==-~i for i in range(n))>>1)

Solution (Python):
n=int(input());a=list(map(int,input().split()));print(sum([0,1][a[a[i]-1]-1==i]for i in range(n))//2)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
  if l[l[i]-1] == i+1:
    ans += 1

print(ans // 2)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    pair = 0
    for i in range(n):
        if a[a[i]-1] == i + 1 and a[a[i]-1] <= a[i]:
            pair += 1
            
    print(pair)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0

for k in range(N):
    if A[A[k]-1] == k+1:
        ans += 1

print(ans//2)

Solution (Python):
def getinputdata():
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()
            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:
        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

cnt=0
for i in range(1,n+1):
     
     val=int(arr_data[1][i-1])
     
     if i==int(arr_data[1][val-1]):
         
         cnt+=1
         
print(cnt//2)

Solution (Python):
n=int(input());*a,=map(int,input().split())
print(sum([a[~-a[i]]==-~i for i in range(n)])>>1)

Solution (Python):
s=0;n=int(input());*a,=map(int,input().split())
for i in range(~-n):s+=(-~i<a[i])*(a[~-a[i]]==-~i)
print(s)

Solution (Python):
N = int(input())
A = [int(i)-1 for i in input().split()]

ans = 0
for i,a in enumerate(A):
  if i == A[a] and i < a:
    ans += 1
print(ans)

Solution (Python):
n = int(input())
nums = list(map(int,input().split()))
count = 0
for i in range(n):
  if i < nums[i] and (i+1) == nums[nums[i]-1]:
    count += 1
print(count)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
  if a[a[i]-1]==i+1: ans+=1
print(ans//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    if a[i] == 0:
        continue
    if a[a[i]-1]-1 == i:
        ans += 1
        a[a[i]-1], a[i] = 0, 0
        
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range(n):
    if a[a[i]-1] == i+1:
        ans += 1
print(ans//2)

Solution (Python):
N = int(input())

A = list(map(int,input().split()))[:N]

ans = 0
for i in range(N):
    if A[A[i]-1] == i+1: ans+= 1
        
print(ans//2)

Solution (Python):
N=int(input())
a=[int(i)-1 for i in input().split()]
K=0
for i in range(N):
  if a[a[i]]==i:
    K+=1
print(K//2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n):
  if a[a[i] - 1] - 1 == i:
    c += 1
print(c // 2)

Solution (Python):
import sys


n=int(input())
a=list(map(int,input().split()))
co=0
for i in range(len(a)):
    if(i+1==a[a[i]-1]):co+=1
print(co//2)

Solution (Python):
def main():
    N = int(input())
    A = map(int, input().split())

    d = {}
    ans = 0
    for i, a in enumerate(A, 1):
        x, y = min(i, a), max(i, a)
        d[(x, y)] = d.get((x, y), 0) + 1
        if d[(x, y)] == 2:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
cou = 0
ans = 1
lis = list(map(int,input().split()))
for i in range(n):
    a = lis[i]
    if lis[a-1] == i + 1:
        ans += 1
print(ans//2)

Solution (Python):

N = int(input())
a = list(map(int, input().split()))

print(sum([a[a[i] - 1] - 1 == i for i in range(N)]) // 2)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    searched = []
    for i, like in enumerate(A):
        if i + 1 == A[like-1]:
            ans += 1
    print(ans//2)

solve()

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
flag=0
for i in range(N):
    if a[a[i]-1]==i+1:
        flag +=1
    else:
        pass
print(int(flag/2))

Solution (Python):





def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    A = tuple(a-1 for a in A) 

    ans = 0
    for i in range(N):
        b = A[i]
        if A[b] == i:
            ans += 1

    ans //= 2
    print(ans)

if __name__ == "__main__": main()

Solution (Python):
N = int(input())
like_list = [int(i) for i in input().split()]

num = 0
for i in range(N):
    if like_list[like_list[i] - 1] == i + 1:
        num += 1

print(int(num/2))

Solution (Python):

"""
Created on Sat Sep 23 19:10:57 2017

@author: taichiNakamura
"""



N = int(input())

a = input().split()

a = list(map(int, a))

favorite = 0
for i,ai in enumerate(a):
    if a[ai-1] == (i+1):
        favorite += 1

print(favorite//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(N):
    if a[a[i]-1] == i+1:
        ans += 1

print(int(ans/2))

Solution (Python):
N = int(input())
src = list(map(int, input().split()))
ans = 0
for i in range(N):
    j = src[i] - 1
    if src[j] - 1 == i:
        ans += 1
print(ans // 2)

Solution (Python):
N = int(input())
usa = list(map(int, input().split()))
flag = [0 for x in range(N)]
count = 0
for i, ai in enumerate(usa):
    if(flag[i]):
        continue
    if(usa[ai-1]-1 == i):
        count+=1
        flag[ai - 1] = 1

print (count)

Solution (Python):
N = int(input())
A = list(map(lambda x:int(x)-1, input().split()))


cnt = 0
for i,a in enumerate(A):
  if A[a] == i:
    cnt += 1

print(cnt//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
 
count = 0
 
for i, target in enumerate(a):
	if a[target - 1] == i + 1:
		count += 1
 
print(count // 2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(N):
    if a[a[i]-1]-1 == i:
        ans += 1
        
print(ans//2)

Solution (Python):
N = int(input())

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


ans = 0
for i in range(N):
    if a[a[i]-1]-1 == i:
        ans += 1
print(ans//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(N):
    if a[a[i]-1]-1 == i:
        count += 1
print(int(count/2))

Solution (Python):

N = int(input())
a = list(map(int, input().split()))
b = [ (tmp+1,a[tmp]) for tmp in range(len(a)) if a[a[tmp]-1] == tmp+1 ]
print(len(list(set([ tuple(sorted(tmp)) for tmp in b ]))))

Solution (Python):
n=int(input())
a=[0]+list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
    if a[a[i]] == i:
        ans += 1
        a[a[i]] = 0
print(ans)

Solution (Python):
number = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(number):
    j = a[i]-1
    if a[j] == i + 1:
        count += 1
print(int(count/2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[a[i]-1] -1 == i:
        cnt +=1
print(cnt // 2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[a[i] - 1] == i + 1:
        cnt += 1
print(cnt // 2)

Solution (Python):
n = input()
rab = map(int, raw_input().split())

ans = 0
for i in range(n):
	if(rab[rab[i]-1] == i+1):
		ans += 1
		rab[i] = -1
print ans

Solution (Python):
s = int(input())
a=[int(i) for i in input().split()]
f=0
for i in range(s):
 if i==a[a[i]-1]-1:
     f+=1
print(int(f/2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(0, n):
	if a[a[i]-1]-1 == i:
		count += 1

print(int(count/2))

Solution (Python):
N = int(raw_input())
digits_str = raw_input()
likes = map(int, digits_str.split(' '))
tags = [0]*N
for i in range(N):
    if likes[likes[i]-1] == i+1:
        tags[i] = 1
print sum(tags) / 2

Solution (Python):
n = input()
a = map(int,raw_input().split())
print sum(i == a[a[i]-1]-1 for i in range(n)) / 2

Solution (Python):
import sys
input = lambda: sys.stdin.readline()

def main():
    n = int(input())
    L = [int(x)-1 for x in input().split()]

    cnt = 0
    for i in range(n):
        if L[L[i]] == i:
            cnt += 1

    print(cnt//2)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = map(int, input().split())
 
d = {i+1: j for (i,j) in enumerate(a)}
 
sum = 0
for x in range(n):
    if( x+1 == d[d[x+1]]):
        sum += 1
 
print(sum//2)

Solution (Python):




"""









"""
import sys

def input_single_line():
    """Receive Inputs."""
    return input()

def input_two_line():
    """Receive Two Lined Inputs.
    Like this.

    N
    1 2 3 4 5
    """
    sys.stdin.readline()
    target = sys.stdin.readline()
    target = target.rstrip("\n")
    target = target.split(" ")

    return target


def search_lovers(target_list: list) -> None:
    """Search Simple.
    >>> target_list = [2, 3, 1]
    >>> search_lovers(target_list)
    0
    >>> target_list = [2, 1, 4, 3]
    >>> search_lovers(target_list)
    2
    >>> target_list = [5, 5, 5, 5, 1]
    >>> search_lovers(target_list)
    1
    """
    target_list = [int(i) - 1 for i in target_list]
    lovers = []
    ans = 0
    for i, n in enumerate(target_list):
        if target_list[n] == i:
            ans = ans + 1

    print(int(ans/2))


if __name__ == "__main__":
    import doctest
    doctest.testmod()

    target = input_two_line()

    search_lovers(target)

Solution (Python):
from sys import stdin
s = set()
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 0
for i in xrange(1,n+1):
 x = a[i-1]
 y = i
 if (y,x) in s:
  s.remove((y,x))
  ans+=1
 else:
  s.add((x,y))
print ans

Solution (Python):
n = int(input())
arr = list(map(lambda x: int(x)-1,input().split()))
ans=0
for i in range(len(arr)):
    if i==arr[arr[i]]:
        ans+=1
print(ans//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

b = {}
ans = 0
for i, v in enumerate(a):
    if v > i+1:
        b[i+1] = v
    elif v < i+1:
        if v in b and b[v] == i+1:
            ans += 1
print(ans)

Solution (Python):
N = input()
rabits = map(int,raw_input().split())
_rabits = [r - 1 for r in rabits]
count = 0
for i in range(N):
    j = _rabits[i]
    if _rabits[j] == i and i < j:
        count+=1
        
print count

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    num_len = len(a)
    ans = 0
    for i in range(num_len):
        if a[a[i]-1] == i+1:
            ans += 1
    print(int(ans / 2))

Solution (Python):
n = int(raw_input())
a = map(int, raw_input().split(' '))
a = map(lambda i: i - 1, a)

res = 0
for i, v in enumerate(a):
    if a[v] == i:
        res += 1

print res / 2

Solution (Python):
N = input()
l = raw_input()
a = map(int, l.split(" "))
count = 0
for i in range(N):
	
	if a[a[i]-1] -1 == i:
		count = count + 1
print(count/2)

Solution (Python):
n = int(input())
a = input().split(' ')
t = 0
for o in range(n):
    i = o + 1
    b = int(a[o]) - i
    if i == int(a[o + b]):
      t += 1
print(int(t / 2))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    p=a[i]
    if a[p-1]==i+1:
        ans += 1

print(ans//2)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

count = 0
for idx,val in enumerate(A):
    if A[val-1] == idx+1:
        count += 1

print(count//2)

Solution (Python):
from collections import defaultdict

mat = defaultdict(lambda: defaultdict(int))
mat[0][1] = 0

ans = 0
_ = input()

for i, a in enumerate(map(lambda x: int(x), input().split())):
    mat[a-1][i] += 1
    mat[i][a-1] += 1

for i, vec in mat.items():
    for j, val in vec.items():
        ans += val // 2

print(ans // 2)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n = int(input())
    a = list(map(int, input().split()))
    c = 0
    for _ in range(n):
        if a[a[_]-1] == _ + 1:
            c += 1
    return c // 2

print(f())

Solution (Python):
n=int(raw_input())
N=map(int,raw_input().split())
count=0
for i in range(n):
	if i==N[N[i]-1]-1:
		count+=1
print count/2

Solution (Python):
n = int(input())
L = [int(x)-1 for x in input().split()]


cnt = 0
for i in range(n):
    if L[L[i]] == i:
        cnt += 1
print(cnt//2)

Solution (Python):
n = int(raw_input())
s = raw_input()
aa = s.split(" ")
aa = [int(x)-1 for x in aa]

ctr = 0

for i in range(n):
	if i == aa[aa[i]]:
		ctr = ctr + 1

ctr = ctr / 2

print(str(ctr))

Solution (Python):
n = int(input())
l = [int(x)-1 for x in input().split()]

cnt = 0
for i in range(n):
    if l[l[i]] == i: cnt += 1

print(cnt // 2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
i = 0
j = 1
b = list(range(2))
c = []
while i < n:
    b[0] = a[i]
    b[1] = j
    b.sort()
    c.append(''.join(str(b)))
    i += 1
    j += 1
l = len(set(c))
print(str(n - l))

Solution (Python):
n = int(input())
a = list(map(int, input(). split()))
cnt = 0

for i in range(n):
    try:
        if a[a[i] - 1] - 1 == i:
            cnt += 1
    except:
        pass

print(cnt // 2)

Solution (Python):
s1 = input()
s2 = input()
s2 = s2.split(" ")
f = 0
for a,b in enumerate(s2):
    if str(s2[int(b)-1]) == str(a+1):
        f = f+1
print (int(f/2))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

pairs = []

for i in range(len(A)):
    if A[A[i] - 1] == i + 1:
        pairs.append(1)

print(len(pairs) // 2)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))









n_pair = 0

for i in range(len(A)):
    if A[i] is not None:
        if A[A[i] - 1] == i + 1:
            n_pair += 1
            A[A[i] - 1] = None

print(n_pair)

Solution (Python):
n = input()
a = map(int, raw_input().split())
count = 0
for i, v in enumerate(a):
    if a[a[i] - 1] == i + 1:
        if a[i] == 0:
            continue
        count = count + 1
        a[i] = 0
        
print count

Solution (Python):
n = input()
a = input()
a = a.split(sep=' ')

result = 0
for i in range(1,int(n)+1):
    if int(a[int(a[i-1])-1]) == i:
        result = result+1
result = int(result/2)
print(result)

Solution (Python):
N = int(input())
aa = input()
b = []
b = aa.split(" ")
output = 0
a = []
flag = []
for i in range(len(b)):
    a.append(int(b[i]))
    flag.append(False)

for i in range(len(a)):
    if (i + 1 == a[a[i] - 1]):
        output = output + 1
        

print(output//2)

Solution (Python):
N = input();
a = raw_input().split();
a.insert(0, 0);

count = 0;
for i in range(1, N+1):
    if (i == int(a[int(a[i])])):
        count += 1;
print count / 2

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    if a[a[i] - 1] == i + 1:
        total += 1
print(total // 2)

Solution (Python):
def main():
    n = int(input())
    dic = {}
    l = raw_input().split()
    for i in range(n):
        if i+1 > int(l[i]) :
            if(dic.get("{}{}".format(i+1,l[i]))):
                dic["{}{}".format(i+1,l[i])] += 1
            else:
                dic["{}{}".format(i+1,l[i])] = 1
        else:
            if(dic.get("{}{}".format(l[i],i+1))):
                dic["{}{}".format(l[i]),i+1] += 1
            else:
                dic["{}{}".format(l[i],i+1)] = 1
    c = 0
    for k,v in dic.items():
        if v >= 2:
            c += 1
    print(c)
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

pair = 0
for index, item in enumerate(a):
    if a[item - 1] == index + 1:
        pair += 1
print(int(pair / 2))

Solution (Python):
a=input()
b=map(int,raw_input().split())
tmp=0
cnt=0
for i in range(0,a):
    tmp=b[i]-1
    if tmp<b[tmp]:
        if b[tmp]==i+1:
            cnt+=1

print cnt

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]

friends = 0
for i in range(0,len(a)):
    if a[i] == -1 or a[i] == -2:
        continue
    if a[a[i] - 1] == (i+1) :
        friends += 1
        a[ (a[i] - 1) ] = -1
        a[i] = -1
print(int(friends))

Solution (Python):

def main():
  
  N = int(raw_input())
  s = raw_input()
  a = map(int, s.split())
  count = 0 
  for i in range(0, N): 
    if a[a[i]-1]-1 == i:
      count = count + 1 

  
  print count/2

main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

pairs = 0
for i in range(N):
    x = a[i]
    if a[x - 1] - 1 == i:
        pairs += 1
print(pairs // 2)

Solution (Python):
n=int(input())
a=list(map(lambda x: int(x) - 1, input().split()))
ans = 0
for i in range(n):
    if a[a[i]] == i:
        ans += 1
print(ans//2)

Solution (Python):

n = int(input())
likes = list(enumerate(input().split(' '), start=1))
rev = list(likes)
rev.reverse()
pairs = 0
for n, like in rev:
	if int(like) < n and likes[int(like) - 1][1] == str(n):
			pairs += 1
print(str(pairs))

Solution (Python):
N = int(raw_input())
likes = map(int, raw_input().split())
pairs = 0
counter = 0
rabbit = 1
while counter < N:
    if likes[(likes[counter] - 1)] == rabbit:
        pairs += 1
        rabbit += 1
        counter += 1
    else:
        rabbit += 1
        counter += 1
pairs = pairs / 2
print pairs

Solution (Python):
N=int()
N = input()
l = map(int, raw_input().split())
count=int()

var = int()
indexerror = int()
for var in range(0, N):
    try:
        k = int()
        k=l[var]
        k-=1
        if k >= (var+1):
            if l[k] == var+1:
                count+=1
    except IndexError:
        indexerror+=1

print count

Solution (Python):
n = int(raw_input())
rab = list(raw_input().split(" "))
count = 0
for i in range(n):
    if int(rab[i]) != i+1 and int(rab[int(rab[i])-1]) == i+1:
        count += 1
print count/2

Solution (Python):
in2= input()
in2b = raw_input()
in2b = in2b.split()

c =0
for i in in2b:
    in2b[c]=int(i)
    c+=1
    


j = 0
pair =0 
while j < in2:
    i = in2b[j]
    if (j+1<i):
        if in2b[i-1] == j+1:
            pair+=1
    j+=1
        
print pair

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
count=0
for i in range(N):
    if a[a[i]-1]==i+1:
        count+=1
print(count//2)

Solution (Python):
N = input()
love = map(int, raw_input().split())
count = 0
for i in range(N):
    if love[love[i]-1] == i+1:
        count = count + 1
print count / 2

Solution (Python):
n = int(input())
a = list(map(int, input().split(" ")))
cnt=0
for i in range(n):
    if a[a[i]-1]-1==i:
        cnt += 1
print(int(cnt/2))

Solution (Python):
n = int(raw_input())
st = raw_input()
ilist = st.split()
ilist = [int(a) for a in ilist]
for i in range(0, n):
    ilist[i]-=1
k = 0
for i in range(0, n):
    if (i == ilist[ilist[i]]): k+=1
print k/2

Solution (Python):
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)

Solution (Python):

N = int(input())
a = list(map(int,input().split()))
ans=0
for i, v in enumerate(a):
    if v != None:
        if a[v-1] == i+1:
            ans+=1
            a[v-1] = None
print(ans)

Solution (Python):
N = int(input())
a = list(map(lambda x:x-1, list(map(int, input().split()))))

pairs = 0

for i in range(N):
    if a[a[i]] == i:
        pairs += 1

print(pairs//2)

Solution (Python):
N = int(raw_input())
x_vec = map(int, raw_input().split())
ret = 0
for i in range(len(x_vec)):
    if x_vec[x_vec[i] - 1] == i + 1:
        ret += 1 
print ret / 2

Solution (Python):
n = input()
A = map(int, raw_input().split())

print sum(i+1 == A[v-1] and v == A[i] for i, v in enumerate(A)) / 2

Solution (Python):



n = int(input())
a = [0] + list(map(int, input().split()))

ans = 0
for i in range(1, n+1):
	if i < a[i]:
		if a[a[i]] == i:
			ans += 1

print(ans)

Solution (Python):

num = int(input())
str = input()
Li = list(map(int,str.split(' ')))
CoupleNum = 0
for pointer in range(len(Li)):
	ai = Li[pointer]
	if (ai > pointer+1):
		if (Li[ai-1]==pointer+1):
			CoupleNum += 1
print(CoupleNum)