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



Sample input:
4
2 1 4 3


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

pairs = 0

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

print(pairs//2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
b = [int(e)-1 for e in raw_input().split(' ')]
count = 0
for i in xrange(a):
    if b[i] != -1:
        if b[b[i]] != -1:
            if b[b[i]] == i:
                count+=1
                b[b[i]] = -1
        b[i] = -1
print count

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int, raw_input().strip().split(" "))

if len(a) != N:
    raise Exception()

ans = 0

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

ans = ans // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())

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

print total / 2

Submission status: Accepted

Solution code:
a = int(input())
b = [int(k) for k in input().split()]

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

print (int(count / 2))

Submission status: Accepted

Solution code:
number = input()
pref = input()
pref2 = [int(i) for i in pref.split()]
cnt = 0
for i in range(0,int(number)):
    if pref2[pref2[i]-1] == i+1:
        cnt += 1
print(int(cnt/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = input()
    li = map(int, raw_input().split())

    print [li[li[i - 1] - 1] == i for i in range(1, n + 1)].count(True) / 2

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
aff = list(map(int,input().split()))

aff = [0] + aff

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

print(ans//2)

Submission status: Accepted

Solution code:
N = int(input())
like_rabbits_list = list(map(int, input().split()))

sum_of_pairs = 0
for i,rabbit in enumerate(like_rabbits_list):
    if like_rabbits_list[rabbit - 1] == (i+1):
        sum_of_pairs += 1

print (int(sum_of_pairs / 2))

Submission status: Accepted

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

Submission status: Accepted

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

pairs = []

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

print(len(pairs) // 2)

Submission status: Accepted

Solution code:
size = int(input())

r_str = input().split()

rabs = []
for r in r_str:
    rabs.append(int(r) - 1)

#visited = []
t = 0

for i in range(0, size):
    if rabs[rabs[i]] == i and (not rabs[i] < i):
        #visited.append(i)
        #visited.append(rabs[i])
        t += 1

print(t)

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int, raw_input().split())
ret  = 0
for idx, val in enumerate(a):
  if a[val-1] == (idx+1):
    ret += 1
print ret/2

Submission status: Accepted

Solution code:

N = int(input())
rabbits_str = input()

rabbits_prefs = rabbits_str.split()

rabbits = {}
for i in range(1, N + 1):
    rabbits[i] = int(rabbits_prefs[i-1])

##print(rabbits)

num_pairs = 0
for r in rabbits:
    curr_pref = rabbits[r]
    other_pref = rabbits[curr_pref]

##    print('curr_pref: {}'.format(curr_pref))
##    print('other_pref: {}'.format(other_pref))
##    print()
    if other_pref == r:
        num_pairs += 1

print(num_pairs // 2)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())
rabbits = map(int, sys.stdin.readline().split())
                                                                                                                                                                                                                                      
i = 0
pair = 0
while i< len(rabbits):
        if rabbits[rabbits[i]-1] == i + 1:
                pair += 1
        i += 1

print pair/2

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
a = [x - 1 for x in a]
s = 0
for i in xrange(n):
    if a[i] != i and a[a[i]] == i:
        s += 1
print s / 2

Submission status: Accepted

Solution code:
a = input()
b = map(int,raw_input().split())
ans = 0
for i in range(len(b)):
  if b[b[i]-1] == i+1:
    ans += 1
print ans/2

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
count = 0
for i, e in enumerate(a):
    if i+1 == a[e-1]:
        count += 1

print count / 2

Submission status: Accepted

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

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

print(num//2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
a = raw_input()

a = [int(i)-1 for i in a.split()]

count = 0

for i in range(len(a)):
    if(a[a[i]] == i):
        count+=1
#        print a[i],i
print count/2

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.insert(0,-1)
cnt = 0
for i in range(N+1):
    j = As[i]
    if j <= i:
        continue
    if As[j] == i:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())

# Note the numbers are 1 indexed
A = dict([(i, int(j) - 1) for i, j in enumerate(raw_input().split(' '))])

count = 0

# Beware of scope leak
for i in A.keys():
    j = A[i]
    if A[j] == i:
        count += 1

count = count/2
print(count)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())

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

print b/2

Submission status: Accepted

Solution code:
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(int(res/2))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
n  = input()
a = map(int, raw_input().split())
t = [False for i in xrange(n)]
count = 0

for i in xrange(n):
    if t[i-1]:
        continue
    j = a[i-1]
    if a[j-1] == i:
        count += 1
        t[j-1] = True
    t[i-1] = True
    
print count

Submission status: Accepted

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
cnt=0
for i in xrange(n):
    if a[a[i]-1]==i+1:
        cnt+=1

print(cnt/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(int(res/2))

Submission status: Accepted

Solution code:
n = int(input())
rabits =[int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
_=input()
a=list(map(int,input().rsplit(" ")))
print(sum([i+1==a[j-1] for i,j in enumerate(a)])//2)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
a = [None] + a
ans = 0
for i in xrange(1, n+1):
    if a[a[i]] == i:
        ans += 1
print ans/2

Submission status: Accepted

Solution code:
N=int(raw_input())
A=map(int,raw_input().split())

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

Submission status: Accepted

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

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

Submission status: Accepted

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


answer = 0
for i in range(len(A)):
    if A[i] < i:
        continue
    if A[A[i]] == i:
        answer += 1
print(answer)

Submission status: Accepted

Solution code:
N=int(raw_input())
Alist=[int(x) for x  in raw_input().split()]
ans=0
for i in range(N):
    ilike= Alist[i]-1
    if Alist[ilike]-1==i:
        ans+=1
print ans/2

Submission status: Accepted

Solution code:
n = int(raw_input())
values = list(map(lambda s: int(s) - 1, raw_input().split()))
result = 0
for i, x in enumerate(values):
    if values[x] == i:
        result += 1
result //= 2
print(result)

Submission status: Accepted

Solution code:
#read in input
n = int(raw_input())
a = map(int, raw_input().split())

numPairs = 0

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

print int(numPairs / 2)

Submission status: Accepted

Solution code:
N = int(raw_input())
rab = map(int, raw_input().split())

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

print cnt / 2

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
s = set()
for i in range(n):
    if a[a[i] - 1] == i + 1:
        s.add((min(i + 1, a[i]), max(i + 1, a[i])))
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(lambda x: int(x) - 1, input().split()))
a = 0
ys = set(range(n))
while ys:
    i = ys.pop()
    j = xs[i]
    if xs[j] == i:
        a += 1
        ys.remove(j)
print(a)

Submission status: Accepted

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in xrange(N):
    if i+1 == A[A[i]-1]:
        count += 1
        A[A[i]-1] = A[i] = 0
print count

Submission status: Accepted

Solution code:
N = input()
ans = 0
ls = map(int,raw_input().split(" "))
for i in range(N):
    v = ls[i]-1
    if i < v and ls[v] == i+1:
        ans += 1

print ans

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
res = 0
for i, e in enumerate(a):
    if i+1 == a[e-1]:
        res += 1
print res / 2

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

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

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

Submission status: Accepted

Solution code:
N=int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
As = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [tuple(sorted([i, aa])) for i, aa in enumerate(a, start=1)]
c = set(b)
print(len(b)-len(c))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(lambda s: int(s)-1, input().split()))
ans = 0
for i in range(n):
    if a[a[i]] == i and i < a[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N = int(raw_input())
a = map(int, raw_input().split())

ans = 0
used = [False]*N
for i in xrange(N):
    if not used[i]:
        if a[a[i] - 1] == i + 1 and not used[a[i] - 1]:
            ans += 1
            used[a[i] - 1] = True
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
a = map(lambda x:int(x)-1, raw_input().split())
ans = 0
for i in xrange(len(a)):
    if i == a[a[i]]:
       ans += 1
print ans/2

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
r = 0

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

print (r / 2)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(10000)

N = read()
a = [x-1 for x in reads()]

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

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))
answer = 0
for i, num in enumerate(nums, start=1):
  if i == nums[num] and i < num:
    answer += 1
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(lambda x:int(x)-1,input().split()))
ans = 0
paired = []
for i in range(n):
    if i in paired:
        continue
    else:
        if A[A[i]] == i:
            ans += 1
            paired.append(i)
            paired.append(A[i])
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
rabit = [ int(v) for v in input().split(" ") ]
skip = set()
num = 0
 
for i in range(N):
  n = rabit[i]
  if i in skip:
    continue
  if rabit[n-1] == i+1:
    skip.append(n-1)
    num += 1
 
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans=0

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans=0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
import collections

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

l = np.zeros((N, N))

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

lt = l.T
sum_l = l + lt

print(len(list(sum_l[sum_l == 2]))//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = tuple(map(lambda a:int(a)-1,input()))

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

like = {}
ans = 0

for i, r in enumerate(a):
    like[i] = r
    if like.get(r, default=0) == i:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:

use std::io::stdin;
use std::collections::BTreeMap;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().ok().unwrap();

    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let a =  buf.split_whitespace().map(|x| x.parse().ok().unwrap()).collect::<Vec<usize>>();

    let mut like = BTreeMap::new();

    let mut ans = 0usize;

    for (i, t) in a.iter().enumerate() {
        let handle = like.entry(i+1).or_insert(0);
        *handle = *t;
        if like.get(t) == Some(&(i+1)) {
            ans += 1;
        }
    }

    println!("{}", ans);
}

Submission status: Runtime Error

Solution code:

n = int(input())
a = list(map(int,input()))
ans = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
p = int(input())
A = list(map(int,input().split()))
a = list(range(1,p+1))
count = 0
for j,i in zip(a,A):
  if i == a[A.index(j)]:
    count += 1
print(count//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
from bisect import bisect_left, bisect_right

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

    x = sorted(x, key=lambda x:x[1])
    x1 = [i for i,j in x]
    x2 = [j for i,j in x]

    ans = 0
    for i in range(N):
        p = bisect_left(x2, x1[i])
        if x1[i] == x2[p]:
            if x2[i] == x1[p]:
                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))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=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)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input();*A,=map(int,input());print(sum(A[a]==i for i,a in enumerate(A))//2)

Submission status: Runtime Error

Solution code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int n;
  scanf("%d",&n);
  int i,a[n+1];
  for(i=0;i<n;i++)
  scanf("%d",&a[i+1]);
  int count=0;
  for(i=1;i<=n;i++)
  if(a[a[i]]==i)count++;

  printf("%d",count/2);
  return 0;
}


/// confirm df==0 ///

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = 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)

Submission status: Runtime Error

Solution code:
N = int(input())
*a, = map(int, input().split())
ans = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
size = int(raw_input())
rabbit_list = raw_input().split()
rabbits = [int(x) for x in rabbits_input]
count = 0
for i in range(size):
    if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
size = int(input())
rabbit_list = input().split()
rabbits = [int(x) for x in rabbits_input]
count = 0
for i in range(size):
    if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input());s=list(input());print(n-len(set(tuple(sorted((i+1,int(s[i*2]))))for i in range(n))))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
nums = [int(input()) - 1 for i in range(n)]
count = 0
for i in range(n):
    if i == nums[nums[i]]:
        count += 1
print(count // 2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import qualified Data.IntMap as M              

main :: IO ()
main = do
    n  <- readLn
    as <- map read . words <$> getLine
    print $ solve n as

solve :: Int -> [Int] -> Int
solve n as = go mp0
  where
    mp0 = M.fromList $ zip [1 .. n] as

    go :: M.IntMap Int -> Int
    go mp = case M.minViewWithKey mp of
        Nothing -> 0
        Just ((k, a), mp') | M.lookup a mp' == Just k -> 1 + go mp'
                           | otherwise                -> go mp'

Submission status: Runtime Error

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