let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun i -> Scanf.scanf " %d" pred
let ans = ref 0
let _ = Array.iteri (fun i a -> if a_s.(a_s.(i)) = i then incr ans) a_s; Printf.printf "%d\n" @@ !ans / 2