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 collections
N=int(input())
table=collections.defaultdict(int)
a=list(map(int,input().split()))
for i,x in enumerate(a):
  table[i+1]=x
ans=0
for x in table:
  b=table[x]
  if table[b]==x:
    ans+=1
    table[x]=0
print(ans)

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

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    cnt = 0
    for i in range(n):
        if i + 1 == a[a[i]-1]:
            cnt += 1
    print(cnt // 2)


if __name__ == '__main__':
    solve()

Solution (Python):
N=int(input())
a=[N+1]
a.extend(list(map(int,input().split())))

ans=sum([a[a[i]]==i for i in range(1,N+1)])//2

print(ans)

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

Solution (Python):
from operator import mul
from functools import reduce
from collections import Counter


















import sys

sys.setrecursionlimit(2000)


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



def cmb(n, r):
    
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def gcd(a, b):
    
    while b > 0:
        a, b = b, a % b

    return a


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


N = int(input())
A = inpl()
ans = 0
for i, a in enumerate(A):
    if A[a - 1] == i + 1:
        ans += 1

print(ans // 2)

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

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

print(cnt//2)

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

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

print(answer // 2)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=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( )))
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()) )

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

print(res // 2)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = [False] * n
res = 0
for i in range(n):
    if b[i]:
        continue
    if a[a[i]-1] == i+1:
        res += 1
        b[a[i]-1] = True
print(res)

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+=0.5
print(int(ans))

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

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

print(answer//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):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = []
for i, a in enumerate(A, 1):
    L.append(tuple(sorted([i, a])))
cnt = Counter(L)
print(list(cnt.values()).count(2))

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

count = 0 
for i in range(N):
  like = a[i]-1
  if a[i] == -1:
    pass
  elif a[i] != i+1 and a[like] == i+1:
    a[like] = -1
    count += 1

print(count)

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

ans = 0
for i in range(N):
  if rabbits[rabbits[i] - 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)}
cnt = 0
for k, v in a.items():
    if k == a[v]:
        cnt += 1
print(cnt//2)

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
a = {i+1: v for i, v in enumerate(a)}
cnt = 0
for k, v in a.items():
    if k == a[v]:
        cnt += 1
print(cnt//2)

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

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

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

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

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

for i in range(n):
  if aa[i]<0:
    continue
  if aa[aa[i]-1]-1==i:
    aa[aa[i]-1] = aa[i] = -1

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

print(ans//2)

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

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(input())
A = np.array(list(map(int, input().split())), dtype=int) - 1
print((A[A] == np.arange(N)).sum() // 2)

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


if __name__ == "__main__":
    resolve()

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
used = [False for i in range(N)]
ans = 0
for i in range(len(A)):
    if i + 1 == A[A[i] - 1] and not used[i] and not used[A[i] - 1]:
        ans += 1
        used[i] = True
        used[A[i] - 1] = True
print(ans)

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [i - 1 for i in list(map(int, input().rstrip('\n').split()))]
    cnt = 0
    for i in range(len(a)):
        if i == a[a[i]]:
            cnt += 1
    print(cnt // 2)


if __name__ == '__main__':
    slove()

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = LI()
cnt = 0
for i in range(n):
    if L[L[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 i == a[a[i]-1]-1:
        ans += 1

print(ans//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):
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=[0]+list(map(int,input().split()))

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

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

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

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

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

Solution (Python):


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

for index, num in enumerate(A, 1):
    if index == A[num - 1]:
        cnt += 1
print(cnt // 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(c//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()))
cnt= 0
for i in range(n):
    if i + 1 == a[a[i]-1] :
        cnt += 1
print(cnt//2)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(n):
        if i + 1 == a[a[i]-1]:
            cnt += 1
    print(cnt // 2)


if __name__ == '__main__':
    slove()

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

ll = [sorted((idx+1,i)) for idx,i in enumerate(l)]
ll = set([tuple(i) for i in ll])

print(len(l) - len(ll))

Solution (Python):
def main():

    N = int(input())
    A = list(map(int, input().split()))
    visited = set()
    count = 0
    for i in range(N):
        if A[A[i]-1] == i+1:
            count += 1
    return count // 2


if __name__ == '__main__':
    print(main())

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




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



if __name__ == '__main__':
    main()

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

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

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

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

visited = set()
for i in range(n):
    if i == a[a[i]]:
        visited.add(i)
        visited.add(a[i])

print(len(visited) // 2)

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

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

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

print(ans // 2)

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

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

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

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

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
x = []
for i in range(n):
    if i+1 > a[i]:
        x.append((a[i],i+1))
    else:
        x.append((i+1,a[i]))
print(n-len(list(set(x))))

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

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

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

Solution (Python):


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans, cand = 0, set()
    for i, j in enumerate(A, 1):
        i, j = min(i, j), max(i, j)
        if (i, j) in cand:
            ans += 1
        else:
            cand |= {(i, j)}
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans, cand = 0, set()
    for i, j in enumerate(A, 1):
        i, j = min(i, j), max(i, j)
        if (i, j) in cand:
            ans += 1
            cand.discard((i, j))
        else:
            cand |= {(i, j)}
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**7)
import math
from collections import defaultdict


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))



N = I()
a = III()

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

checked = [False] * N
ans = 0
for i in range(N):
    if not checked[i]:
        if a[a[i]-1]-1 == i:
            ans += 1
            checked[i] = True
            checked[a[i]-1] = True

print(ans)

Solution (Python):
input();*A,=map(int,input().split());print(sum(A[a-1]==i+1for i,a in enumerate(A))//2)

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

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

dict = {}
for i,a in enumerate(A):
    idx = a - 1
    t = (idx, i)
    if i <= idx:
        t = (i, idx)
    if t in dict:
        dict[t] += 1
    else:
        dict[t] = 1


ans = 0
for d in dict.values():
    if d == 2:
        ans += 1
print(ans)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N = ii()
As = list(map(lambda x: int(x)-1, input().split())) 
lovesWho = [-1]*N

ans = 0
for i, i_love in enumerate(As):
  if lovesWho[i_love] == i:
    ans += 1
  else:
    lovesWho[i] = i_love

print(ans)

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

g = [{} for _ in range(N)]
for i, a in enumerate(A):
	g[i][a - 1] = True

count = 0
for n in range(N):
	for r in g[n]:
		if n in g[r]:
			count += 1
print(count // 2)

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
    if i==a[a[i]-1]-1:x+=1
print(x//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] == i + 1:
            ans += 1
    print(ans//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]==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()]
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()))
pair = set()
for i in range(N):
    if a[a[i]-1] == i+1:
        pair.add((min(a[a[i]-1], a[i]), max(a[a[i]-1], a[i])))
print(len(pair))

Solution (Python):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
like = [(i, j) if i < j else (j, i) for i, j in zip(range(1, N+1), A)]
cnt = Counter(like)
ans = 0
for v in cnt.values():
    ans += v // 2
print(ans)

Solution (Python):
def solve(n, a):
    edge = {i: set() for i in range(n)}
    for i in range(n):
        edge[i].add(a[i]-1)
    num = 0
    for v, neighbors in edge.items():
        for u in neighbors:
            if (u in edge) and (v in edge[u]):
                num += 1
    return num // 2

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

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

if __name__=="__main__": main()

Solution (Python):
n = int(input())
a = [int(i) for i in 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 = [None] + [int(x) for x in input().split()]

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

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

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

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

Solution (Python):

"""
B - 仲良しうさぎ / Friendly Rabbits
https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b

"""
import sys


def solve(N, rabbits):
    ans = 0
    for i, r in enumerate(rabbits[1:], start=1):
        if rabbits[r] == i:
            ans += 1
    return ans // 2


def main(args):
    N = int(input())
    rabbits = [-1] + [int(a) for a in input().split()]
    ans = solve(N, rabbits)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

c = 0
for i in range(1,N+1) :
    
    if (i == li[li[i-1]-1]) :
        c += 1

print(c//2)

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

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

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) - 1 for i in input().split()]

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

print(count // 2)

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

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()]
ans = 0
from collections import defaultdict
d = defaultdict(int)
for i, a in enumerate(A):
    t = tuple(sorted([i+1, a]))
    d[t] += 1
    if d[t] == 2:
        ans += 1
print(ans)

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

ans = 0

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

ans //= 2 
print(ans)

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

ad = [set() for _ in range(N)]

for i, a in enumerate(A):
    ad[a].add(i)

ans = 0

for i, a in enumerate(A):
    if a in ad[i]:
        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
for i,a in enumerate(A):
    if i == A[a - 1] - 1:
        cnt +=1
print(cnt // 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_s = [int(x) for x in input().split()]

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

print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

like=[set() for i in range(N)]
cnt=0
for i in range(N):
    if i+1<A[i]:
        like[A[i]-1].add(i+1)
    else:
        if A[i] in like[i]:
            cnt+=1
print(cnt)

Solution (Python):
n=int(input())
ans=chk=0
d=set()
l=[int(i) for i in input().split()]
for i in range(n):
    a,b=min(i+1,l[i]),max(i+1,l[i])
    if (a,b) in d:
        ans+=1
    else:
        d.add((a,b))

print(ans)

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

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

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




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

count = count//2
print(count)

Solution (Python):
import sys
MOD = 10 ** 9+7
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N = ii()
a = lmi()
cnt = 0

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

print(cnt//2)

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

ans //= 2
print(ans)

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]=0
        continue
print(cnt)

Solution (Python):


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    sum = 0
    for i in range(N):
        if i == a[a[i]-1]-1:
            sum += 1
    sum = sum // 2
    print(sum)

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

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

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

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

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

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

print(p // 2)

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