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

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

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

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

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

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

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

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

Solution (Python):




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

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

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

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

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

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

r_str = input().split()

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


t = 0

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

print(t)

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

Solution (Python):

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



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




    if other_pref == r:
        num_pairs += 1

print(num_pairs // 2)

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

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

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

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

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

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

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

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

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

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


A = dict([(i, int(j) - 1) for i, j in enumerate(raw_input().split(' '))])

count = 0


for i in A.keys():
    j = A[i]
    if A[j] == i:
        count += 1

count = count/2
print(count)

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

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

Solution (Python):


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

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

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

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)

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

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

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

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

INF = float('inf')


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)


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


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


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


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

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

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

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

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

Solution (Python):



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

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

Solution (Python):


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)

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

Solution (Python):

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

Solution (Python):

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

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

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

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

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