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())
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 = [int(i) for i in input().split()]
cnt = 0
for i in range(N):
    a = A[i]
    if A[a - 1] < a:
        continue
    if A[a - 1] - 1 == i:
        cnt += 1
print(cnt)

Solution (Python):
from collections import defaultdict

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

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

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

for i in range(n):
    if a[i] == -1:
        pass
    elif a[a[i] - 1] - 1 == i:
        c += 1
        a[a[i] - 1] = -1
        a[i] = -1
    else:
        pass

print(c)

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

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

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


print(int(ans/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):
def main():
    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)
        
if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
L = [[] for _ in range(N)]
ans = 0
for i in range(N):
    L[i].append(a[i])
    if i+1 in L[a[i]-1]:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
likes = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if likes[i] == -1:
        continue
    idx = likes[i]-1
    if likes[idx] == i + 1:
        cnt += 1
        likes[idx] = -1
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):
N = int(input())
A = list(map(int,input().split()))
a = 0
ans = 0

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

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

Solution (Python):
n = int(input())
a = list(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 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 in range(N):
    if a[a[i]-1] == i+1:
        cnt += 1
print(cnt//2)

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

nk = [0]*N
count = 0
for k,v in enumerate(a):
  if k+1 != v :
    nk[k] = v
    if nk[v-1] == k+1 :
      count += 1

print(count)

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

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

print(ans)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
a = LIST()

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 (i,j) in zip(range(n),a):
  if i==a[j-1]-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 A[A[i]-1] == i+1:
		cnt += 0.5


print(int(cnt))

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

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

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

counter = 0

for i, A_i in enumerate(A):
  if A[A[i]-1] == i + 1 :
    counter += 1
  
print(int(counter/2))

Solution (Python):

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()
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[a[i] - 1] == i + 1: ans += 1
print(ans // 2)

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Solution (Python):
import sys
import collections

def swap(t):
    if t[1] < t[0] :
        return (t[1],t[0])
    else:
        return t

n = int(sys.stdin.readline().rstrip())
a = [int(x) for x in sys.stdin.readline().rstrip().split()]

zippeda = list(map(swap,list(zip(range(1,n+1),a))))
zippeda.sort()
c = collections.Counter(zippeda)
counter = 0
for a in c.most_common():
    if a[1] < 2:
        break
    else:
        counter = counter + 1

print(counter)

Solution (Python):


import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

_, *A = map(int1, read().split())

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

print(ans // 2)

Solution (Python):
N = int(input())
a_list = [0]+[int(e) for e in input().split()]

ans = 0

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

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

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

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

if __name__ == '__main__':
    main()

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

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

print(ans//2)

Solution (Python):

import math


def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



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


n = inp()

a = inlist()
b = [0]
b += a
p = 0
for i in range(1, n+1):
    if b[b[i]] == i and b[i] > 0:
        p += 1


print(p//2)

Solution (Python):
input()
LOVE = [int(i) for i in input().split(' ')]
print(int(len([1 for i in range(len(LOVE)) if i + 1 == LOVE[LOVE[i] - 1]]) / 2))

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

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

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

count = count//2
print(int(count))

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

Solution (Python):

def main():
    n = int(input())
    a_s = list(map(int,input().split()))
    dct = {}
    for i,value in enumerate(a_s):
        i = i+1
        dct[i] = value
    counter = 0
    for key in dct.keys():
        if dct[dct[key]] == key:
            counter += 1
    print(counter//2)


if __name__ == '__main__':
    main()

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 = [int(i) - 1 for i in input().split()]
print(len([1 for i, a in enumerate(A) if i == A[a] and i < a]))

Solution (Python):
N,*A=map(int,open(0).read().split())
print(sum(i+1==A[A[i]-1]for i in range(N))//2)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
i=0
ans=0
while i<N:
    if i+1==A[A[i]-1]:
        ans+=1
    i+=1
print(ans//2)

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

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

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

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

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

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 = tuple(map(lambda x:int(x)-1, input().split()))

paired = [0] * n
c = 0
for i in range(n-1):
    if paired[i]:
        continue

    if A[A[i]] == i:
        c += 1
        paired[A[i]] = 1

print(c)

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(c//2)

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

Solution (Python):


n = int(input())
nums = [int(i) for i in input().split()]

ans = 0
d = set()
for i in range(n):
    a = i + 1
    b = nums[i]
    if (a, b) in d or (b, a) in d:
        ans += 1
    else:
        d.add((a, b))
        d.add((b, a))
print(ans)

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

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

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

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

Solution (Python):

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

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()))
counter = 0
for i, a in enumerate(A):
    if A[a-1] == i+1:
        counter += 1

print(counter//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())
a = [int(x)-1 for x in input().split()]

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

print(ans//2)

Solution (Python):



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

ans = 0
for itr, a in enumerate(A):
  if a - 1 > itr and A[a - 1] == itr + 1:
    ans += 1

print(ans)

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

if __name__ == "__main__":
  resolve()

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

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

print(point//2)

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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 i, ai in enumerate(a):
    if i + 1 == a[ai - 1]: ans += 1

ans //= 2
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
    a[a[i]-1] = 0
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
cnt = 0
for i in range(1,N+1):
    ind = A[i]
    if A[ind]==i:
        cnt += 1
print(cnt//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):
    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):
N = int(input())
A = list(map(int, input().split()))
con = 0
for i in range(N):
  if i == A[A[i]-1]-1:
    con += 1
print(int(con/2))

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

Solution (Python):
import itertools
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(len(a)):
    if i+1 == a[a[i]-1]:
        ans += 1
print(ans//2)

Solution (Python):
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() 
ni = lambda: int(readline().rstrip()) 
nm = lambda: map(int, readline().split()) 
nl = lambda: list(map(int, readline().split())) 

n = ni()
l = nl()
ans = 0

for i, usa in enumerate(l):
    if l[usa - 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()))

cnt = 0
chk = [False for i in range(n)]
for i in range(n):
	if chk[i]:
		continue
	chk[i] = True
	if i+1 == a[a[i]-1]:
		chk[a[i]-1] = True
		cnt += 1
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(int(ans/2))

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

Solution (Python):
n=int(input())
a=[int(_) for _ 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()))
count = 0
for i in range(n):
  if a[i] == 0:
    continue
  if a[a[i] - 1] == i + 1:
    a[a[i] - 1] = 0
    count += 1
print(count)

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

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

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

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

Solution (Python):
N = int(input())
R = {i:0 for i in range(1,N+1)}
A = list(map(int,input().split()))
for i in range(1,N+1):
    R[i] = A[i-1]
count = 0
for i in range(1,N+1):
    if i == R[R[i]]:
        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 == a[a[i] - 1] - 1:
        cnt += 1
print(cnt // 2)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
flags = [False] * n
ans = 0
for i in range(n):
    if a[a[i] - 1] - 1 == i and flags[a[i] - 1] == False:
        ans += 1
        flags[a[a[i] - 1] - 1] = True

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

if __name__ == '__main__':
    main()

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):
import math
import copy

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

Solution (Python):
from collections import Counter

n = map(int, input().split())

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

def f(): 
    for i, a in enumerate(A, 1):
        if i < a:
            yield i, a
        else:
            yield a, i

c = Counter(f())
print(len([k for k, v in c.items() if v == 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] and i < a[i]:
        cnt += 1
print(cnt)

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(c//2)

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
for i,x in enumerate(a,1):
    if x=='*':
        continue
    if a[x-1]==i:
        ans += 1
        a[x-1] = '*'
print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
count = 0
a_dict = {}
for i,x in enumerate(a,1):
    a_dict[i] = x
for k,v in a_dict.items():
    if k in [a_dict[v]]:
        count +=1
print(count//2)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
a_dict = {}
for i,x in enumerate(a,1):
    a_dict[i] = x
for k,v in a_dict.items():
    if k in [a_dict[v]]:
        ans +=1
print(ans//2)