output_description: Print the number of the friendly pairs.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      a_1 a_2 ... a_N
attempt: #!/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 not (0 <= p < N):
              continue
          if x1[i] == x2[p] and 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()
  
problem_description: 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.
samples: [{"input": "4\n    2 1 4 3", "output": "2\n    \n\nThere are two friendly pairs: (1\uff0c2) and (3\uff0c4).\n\n* * *"}, {"input": "3\n    2 3 1", "output": "0\n    \n\nThere are no friendly pairs.\n\n* * *"}, {"input": "5\n    5 5 5 5 1", "output": "1\n    \n\nThere is one friendly pair: (1\uff0c5)."}]