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):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

d = defaultdict(list)
cnt = 0
for i, a in enumerate(A):
    if i+1 in d[a]:
        cnt += 1
    d[i+1].append(a)


print(cnt)

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):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

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

resolve()

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

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

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

print(count // 2)

Solution (Python):
n = int(input())
a = [0]*(n+1)
a[1:] = map(int, input().split())
ans = set()
for i in a[1:]:
    if i==a[a[i]]:
        j, k = sorted([i, a[i]])
        ans |= {(j, k)}
print(len(ans))

Solution (Python):


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

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

print(ans//2)

Solution (Python):

import collections
import itertools as it
import math

 

n  = int(input())

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




ans_ = 0
for i, a_ in enumerate(a):
    if a[a_-1] == i + 1: 
        ans_ += 1
print(ans_ // 2)

Solution (Python):
def main():
    N=int(input())
    a=[int(_) for _ in input().split()]
    ans = 0
    for i,v in enumerate(a):
        if a[v-1] == i+1:
            ans += 1
    print(ans//2)

main()

Solution (Python):
n, *a_l= map(int, open(0).read().split())
cnt = 0
for i, a in enumerate(a_l):
    if a_l[a-1] == i+1:
        cnt += 1
print(cnt//2)

Solution (Python):
n, *a_l= map(int, open(0).read().split())
lovedBy = [[] for _ in range(n)]
for i, a in enumerate(a_l):
    lovedBy[a-1].append(i)
cnt = 0
for i, a in enumerate(a_l):
    if a-1 in lovedBy[i]:
        cnt += 1
print(cnt//2)

Solution (Python):
n = int(input())
a = tuple(map(lambda a:int(a)-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()))
c = 0
a = [0] + a
for i in range(n):
    if i == a[a[i]]:
        c += 1
else:
    print(c//2)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    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)
resolve()

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

cnt = 0
index_list = list(range(0,n,1))

for i in (index_list):
    if a_list[a_list[i]-1] == i+1:
        cnt += 1
print(cnt//2)

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
  if lis[lis[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):
    b=a[i]-1
    if(i==a[b]-1):
        ans+=1
print(ans//2)

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

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

print(res)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    a=list(map(lambda x:int(x)-1,readline().split()))

    flags=[False]*N
    res=0
    for i in range(N):
        j=a[i]
        if flags[j]==False and a[j]==i:
            flags[i]=True
            flags[j]=True
            res+=1

    print(res)
    
if __name__=="__main__":
    main()

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

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

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

n = int(input())
a = [int(x) for x in input().split()]
ans = set()
for i in range(n):
    j = a[i] - 1
    if (i not in ans) and (j not in ans) and a[j] == i + 1:
        ans.add(j)
print(len(ans))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
liked=[[] for i in range(n)]
for i in range(n):
    liked[lis[i]-1].append(i+1)

count=0
for i in range(n):
    if lis[i] in liked[i]:
        count+=1
print(count//2)

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

Solution (Python):
N=int(input())
*A,=map(int, input().split())
A=[-1]+A
ans=0
for i in range(1,N+1):
    j=A[i]
    if j>i and A[j]==i: ans+=1
print(ans)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










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

def readInts():
  return list(map(int,input().split()))

def main():
    n = int(input())
    A = readInts()
    Pa = [0 for _ in range(n)]
    for i in range(n):
        Pa[i] = A[i] - 1
    cnt = 0
    for i in range(n):
        if i == Pa[Pa[i]]:
            cnt += 1
    print(cnt//2)
if __name__ == '__main__':
  main()

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

cnt = 0
for i,value in enumerate(a):
    b = a[value-1]
    if b == i+1:
        cnt += 1
cnt //=2
print(cnt)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    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)    
resolve()

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

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

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

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()))
A.insert(0,0)
cnt = 0
for i in range(1,N+1):
    k = A[i]
    if A[k]==i:
        cnt += 1
print(cnt//2)

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

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

    print(ans)

if __name__ == '__main__':
    main()

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
    a[i] = ""
print(cnt)

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

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

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

for i in range(N):
    j = a[i]-1
    
    if a[j]-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 i==a[a[i]-1]-1:ans+=1
print(ans//2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
pair = {}
ans = 0
for i in range(N):
    pair[i + 1] = a[i]

for key, value in pair.items():
    if pair[value] == key:
        ans += 1

print(ans // 2)

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

Solution (Python):
N=int(input())
like=list(map(int,input().split()))
count=0

for i in range(N):
    like_1=like[i]
    
    
    if like[like_1-1]==i+1:
        
        
        count+=1
        
        
print(count//2)

Solution (Python):
n = int(input())
a_inputs = [int(i) for i in input().split()]

ans=0
for i in range(n):
    if a_inputs[a_inputs[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[A[i]-1]-1 == i:
    ans += 1
print(ans//2)

Solution (Python):

N = int(input())

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

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

print(res//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 and i < a[i]-1:
        ans += 1
print(ans)

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

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

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

print(cnt // 2)

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

G = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
	G[a[i]].append(i)

cnt = 0
for i in range(1, n + 1):
	if a[i] in G[i] and i in G[a[i]]:
		cnt += 1
print(cnt // 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())
la = list(map(int, input().split()))

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

print(int(ans/2))

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 = 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] == i+1:
    ans += 1
print(ans//2)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left


def main():
    n = II()
    aa = MII()
    l = set()
    cnt = 0
    for i, a in enumerate(aa):
        if (i+1,a) in l:
            cnt += 1
        else:
            l.add((i+1,a))
            l.add((a,i+1))
    print(cnt)

if __name__ == '__main__':
    main()

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

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

Solution (Python):

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

Solution (Python):
def main():
    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)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(set)
ans = 0
for i, e in enumerate(a, start=1):
  d[i].add(e)
  if i in d[e]:
    ans += 1
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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())
a = list(map(int, input().split()))

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

Solution (Python):
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]

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

Solution (Python):

N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

pairs = 0

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

print(pairs)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
to = [0 for _ in range(n + 1)]

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
L = [[] for _ in range(N)]
for i in range(N):
    L[a[i]-1].append(i)
cnt = 0
for i in range(N):
    if a[i]-1 in L[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):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = 0
    for i in range(N):
        if i==A[A[i]-1]-1:
            ans += 1
    print(ans//2)


if __name__ == '__main__':
    main()

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










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

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    RA = readInts()
    ans = 0
    for i in range(n):
        if RA[RA[i]-1] == i+1:
            ans += 1
    print(ans//2)
if __name__ == '__main__':
  main()

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

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

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

Solution (Python):
import sys

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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

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

    print(res // 2)


if __name__ == '__main__':
    resolve()

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

Solution (Python):
n = int(input()) 
a = list(map(int,(input().split())))
a = {i+1: v for i, v in enumerate(a)}



counter = 0

for i,j in a.items():
    if i == a[j]:
        
        counter += 1

print(counter//2)

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

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

print(ans)

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()))
num = set()
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(_) for _ in input().split()]

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

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())
arr = list(map(int,input().split()))
ans = 0
for i in range(n):
    if arr[arr[i]-1] == i+1:
        ans += 1
print(ans//2)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
cnt = 0
B = [False for _ in range(n)]
for i,a in enumerate(A):
    if A[a-1] == i+1 and B[i] == False:
        cnt+=1
        B[a-1] = True
    B[i] = True
print(cnt)

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

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

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

res = 0
for i in range(n):
    if i==al[al[i]]:
        res += 1
print(res//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(count//2)

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

ans = 0

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

print(ans//2)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

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()))

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

Solution (Python):









import numpy as np






N = int(input())
arrA = np.array(input().split(),dtype=np.int64)
arrA = arrA -1

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

print(ans//2)

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   counter = 0
   for i in range(N):
      if(A[A[i]-1] == i + 1):
         counter += 1
   return counter//2


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
cnt = 0
for i in range(n):

    if i == A[A[i] - 1] - 1:
        cnt += 1
print(cnt // 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()))
A = [a-1 for a in A]
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):
    if i < a[i]-1:
        if i == a[a[i]-1]-1:
            cnt += 1
print(cnt)

Solution (Python):
*a, = map(int, open(0).read().split())
c = 0
for i, j in enumerate(a):
  c += (a[j:j+1] == [i])*(i > 0)
print(c // 2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
ls = []
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()))

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

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

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

like = {}
ans = 0

for i, r in enumerate(a):
    like[i+1] = r
    if r in like and like[r] == i+1:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
checked = [False] * n
ans = 0
for i, a in enumerate(A):
    if checked[i]:
        continue
    if A[a - 1] - 1 == i:
        ans += 1
        checked[i] = True
        checked[a - 1] = True
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    for i in range(n):
        a[i] -= 1
    ans = 0
    for i in range(n):
        ans += (a[a[i]] == i)&(a[i] > i)
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
count = 0

for i,l in enumerate(li):
    
    if li[l-1] == i+1:
        count+= 1
print(count//2)

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

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

print(cnt//2)

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

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
a = list(map(int,input().split()))
pair = []
for i in range(len(a)):
    koho = [i,a[i]-1]
    koho.sort()
    pair.append(koho)
pair.sort()
cnt = 0
for i in range(len(pair)-1):
    if pair[i] == pair[i+1]:
        cnt+=1
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = 0
for x in range(N):
    find = A[x]
    if A[find - 1] - 1 == x:
        count += 1
print(count // 2)

Solution (Python):
n = int(input())
a = list(map(int, 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())
aaa = [0] + list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
    j = aaa[i]
    if aaa[i] == j and aaa[j] == i:
        ans += 1
print(ans // 2)

Solution (Python):
n=int(input())
a=[0]*n
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()))
res = 0
for i, val in enumerate(a):
  if a[val - 1] == i + 1:
    res += 1
print(res//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] == i+1:
        ans+=1
print(ans//2)

Solution (Python):
n  = int(input())
As =  list(map(int,input().split(" ")))
ans = 0
for i,a in enumerate(As):
    if As[a-1] == i + 1:
        ans += 1
print(ans//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(count // 2)

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

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

print(count//2)

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

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

Solution (Python):
N = int(input())
A = list(map(int, 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())
A = list(map(int, input().split())) 

ans = 0
for i in range(N):
    suki = A[i]
    if A[suki-1] == i+1:
        ans = 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(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 = [0]+list(map(int,input().split()))
ans = 0
for i in range(1,n+1):
     if a[a[i]] == i:
        ans+=1
        
    
print(ans//2)

Solution (Python):
n = int(input())
A = [int(x) for x in input().split()]
dict = {}
res = 0
for i, a in enumerate(A, 1):
  dict[i] = a
for i in range(1, n+1):
  if dict[i] in dict.keys() and dict[dict[i]] == i:
    res += 1
print(res // 2)

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

Solution (Python):
N = int(input())
a = list(map(lambda s: int(s) - 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())
ans=0
table=[-1]*n
for i,j in enumerate(list(map(int,input().split()))):
    if table[j-1]==-1:table[i]=j-1
    elif table[j-1]==i:ans+=1
print(ans)

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

for i, j in enumerate(a):
    ai.append([i+1,j])
    ai[i].sort()

print(len(ai) - len(list(map(list,set(map(tuple, ai))))))

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
b=[]
for i in range(n):
    if a[i]==i+1:continue
    if a[a[i]-1]==i+1:
        t=[a[i]-1,i]
        b.append(sorted(t))

print(len(b)//2)

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

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)