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

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

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

Solution (Python):

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

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

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

b = []
c = []
for i in range(n):
	b.append((i, a[i]))
	c.append((a[i], i))

c = set(c)
b = set(b)

ans = len(b & c)
print(ans//2)

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

ans = 0
for i, a in enumerate(A):
    a -= 1
    if A[a] - 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())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
    if l[l[i]-1]-1 == i:
        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 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):
    target = A[i]
    if A[target - 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[i] != "": n = a[i] - 1
  if a[n] == i + 1:
    ans += 1
    a[n] = ""
print(ans)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
for i in range(n): A[i] -= 1
for i in range(n):
  if not A[i] > i:continue
  else:
    if A[A[i]] == i:ans += 1
print(ans)

Solution (Python):
if __name__ == "__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)

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

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

B=[0]*N

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

print(sum(B)//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
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
for x in range(N):
  y = a[x]
  if x + 1 == a[y - 1]: res += 1
print(res // 2)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
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()))

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

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

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

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

print(int(ans))

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

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

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

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
p = []
for i, a in enumerate(A):
    idx = i+1
    if a>idx:
        a,idx = idx, a
    p.append((a, idx))
c = Counter(p)
ans = 0
for k,v in c.items():
    if v==2:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
A = [int(i)-1 for i in input().split(" ")]
count = 0
for i in range(N):
    
    if i==A[A[i]]:
        count+=1

pair = count//2
print(pair)

Solution (Python):
import numpy as np
N = int(input())

a = list(map(int, input().split()))
a = np.array(a)
a = a - 1

cnt = 0

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

print(cnt//2)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    a = LI()
    ans = 0
    for i in range(n):
        ans += a[a[i] - 1] - 1 == i
    print(ans//2)
    return



if __name__ == '__main__':
    solve()

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

Solution (Python):
N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
checked = [False] * N
ans = 0

for i in range(N):
    if not checked[i] and A[A[i]] == i:
        ans += 1
        checked[i] = True
        checked[A[i]] = True

print(ans)

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

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

print(ans//2)

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

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

Solution (Python):
def main():
    rabbits = int(input())
    like = list(map(int, input().split()))
    answer = 0
    for i in range(rabbits):
        if like[like[i] - 1] == i + 1:
            answer += 1
    print(answer // 2)


if __name__ == '__main__':
    main()

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

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

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

cnt //= 2
print(cnt)

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

st = set()
cnt = 0
for i, e in enumerate(a, 1):
    pair = min(i, e), max(i, e)
    if pair in st:
        cnt += 1
    else:
        st.add(pair)

print(cnt)

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

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

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

cnt = 0
for idx in range(len(a)):
    lovers_love = a[a[idx]]
    if lovers_love == -1:
        continue
    if lovers_love == idx:
        cnt += 1
        a[a[idx]] = -1

print(cnt)

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

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
ans = cnt // 2
print(ans)

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

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

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

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

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

Solution (Python):
n, *a = map(int, open(0).read().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 itr, val in enumerate(A):
  if A[val - 1] == itr + 1:
    cnt += 1
    
print(cnt // 2)

Solution (Python):
if __name__ == "__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)

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

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

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

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


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

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

Solution (Python):
from sys import stdin,setrecursionlimit
setrecursionlimit(10**7)
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
point = 1
for i,j in enumerate(li):
    if li[j-1] == i+1:
        point += 1
point //= 2
print(point)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
l = [set([]) for k in range(N+1)]
ans = 0
for k in range(N):
    if k+1 in l[a[k]]:
        ans += 1
    l[k+1].add(a[k])
print(ans)

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

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

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

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

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


if __name__ == '__main__':
    main()

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 STR(): return input()
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 = sys.maxsize
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 = [int(i)-1 for i in input().split()]

from collections import defaultdict

flag = [True] * N

cnt = 0
for i in range(N):
    if flag[A[i]] and flag[i] and A[A[i]] == i:
        cnt += 1
        flag[A[i]] = False
        flag[i] = False

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    pair = 0
    A = [int(a) for a in input().split()]
    for i, a in enumerate(A):
        if A[a-1] == i + 1: pair += 1
    print(pair // 2)

    return 0

if __name__ =="__main__":
    solve()

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    f = [True]*n
    ans = 0
    for i in range(n):
        if f[i]:
            f[i] = False
            if a[a[i]-1]-1 == i:
                ans += 1
                f[a[i]-1] = False
    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
import numpy as np
N = int(input())
a = input().split()
a = np.array(a).astype(int)
count = 0
for i,ai in enumerate(a):
    
    if a[ai-1] == i+1:
        count = 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
print(ans//2)

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

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
l=[]
buf=[]
for i in range(N):
    buf=[a[i],i+1]
    buf.sort()
    l.append(buf[0]*N+buf[1])
print(len(l)-len(set(l)))

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

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

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

print(cnt//2)

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

for i in range(N):
    if alist[alist[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(1,n+1):
    if a[i-1]>i and a[a[i-1]-1]==i:
        ans+=1
print(ans)

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

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
d = dict()
res = 0
for i in range(n):
    d[i+1] = dat[i]
    if d.get(dat[i], -1) == (i + 1):
        res += 1
print(res)

Solution (Python):

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

Solution (Python):

n = int(input())
used = [False for _ in range(n)]
arr = list(map(int, input().split()))
ans = 0
for i, a in enumerate(arr):
    if i + 1 == arr[a - 1]:
        if used[i] == False:
            ans += 1
            used[i] = True
            used[a - 1] = True
print(ans)

Solution (Python):
import numpy as np

N = int(input())
A = np.array(tuple(map(int, input().split())))
print(np.count_nonzero(A[A - 1] == np.arange(N) + 1) // 2)

Solution (Python):


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

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

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

ans = int(cnt//2)
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()))
cnt = 0

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

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

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

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

print([A[i] - 1 > i and A[A[i] - 1] - 1 == i for i in range(N)].count(1))

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

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

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

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

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 

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

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

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = [1]+list(map(int,stdin.readline().rstrip().split()))
point = 0
for i in range(1,n+1):
    if li[li[i]] == i:
        point += 1
print(point//2)

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

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

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

print (count // 2)

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

cnt = 0

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

print(int(cnt * 0.5))

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

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

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

ans = 0
for idx,a in enumerate(al):
   if al[a-1]-1 == idx:
      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 = ans + 1
		

print(ans//2)

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

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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
A -= 1

ans = 0
seen = [0] * n
for i, ai in enumerate(A):
    if seen[i]:
        continue
    seen[i] = 1
    if A[ai] == i:
        ans += 1
        seen[ai] = 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=list(map(int,input().split()))

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

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

Solution (Python):
from collections import defaultdict
n=int(input())
a=[int(i) for i in input().split()]

dic = defaultdict(set)
ans=0
for i in range(n):
    dic[a[i]].add(i+1)
    if a[i] in dic[i+1]:
        ans+=1
print(ans)

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

A = [int(x) - 1 for x in input().split()]

cnt = 0
for i in range(N):
    if A[A[i]] == i:
        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(int(c//2))

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
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(10000000)
INF = 1<<32
from bisect import bisect_left, bisect_right

def solve(N: int, a: "List[int]"):
    
    ans = 0
    for i in range(N):
        if a[a[i]-1] == i+1:
            ans += 1

    print(ans//2)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
from bisect import bisect_left, bisect_right

def solve(N: int, a: "List[int]"):
    

    
    
    

    
    
    
    
    
    
    

    

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

    print(ans//2)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

N = ri()
A = rl()
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()))

ans = 0

for i in range(N):

    a[i] -= 1

for i in range(N):

    if a[i] > i and a[a[i]] == i:
        ans += 1

print (ans)

Solution (Python):
import collections
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(range(1, N + 1))

    C = collections.defaultdict(int)
    for a, b, in zip(A, B):
        a, b = min(a, b), max(a, b)
        C[(a, b)] += 1

    D = collections.Counter(C.values())
    print(D[2])


main()

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

Solution (Python):
n = int(input())
a = 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):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
A = {frozenset([i+1, a]) for i, a in enumerate(A)}
print(N-len(A))

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

G = [[] for _ in range(N)]

for i in range(N):
    G[A[i]-1].append(i)

ans = 0

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

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

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

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

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


s = {tuple(sorted([a[i],i+1]))for i in range(n)}
print(n-len(s))

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
s = { tuple(sorted([A[i], i+1])) for i in range(n) }
print(n-len(s))

Solution (Python):

import sys
def main():
    n, *a = map(int, sys.stdin.read().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)

if __name__ == '__main__':
    main()

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

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