#31786: 這個為何吃RE?


harrison0423 (小龍)


def cycle(s):
  nums = [int(i) for i in s.split(' ')]
  n = len(nums)
  nc = 0
  check = [1 for i in range(n)]
  ct = ''
  for i in range(n):
    st = '('
    j = i 
    while (check[j] == 1):
      check[j] = 0
      st += str(j) + ' '     
      j = nums[j]
    else:
      if (len(st)>1):
        st += ')'
        print(st)
        nc += 1
  return nc
print(cycle(input()))
#31808: Re: 這個為何吃RE?


cges30901 (cges30901)


def cycle(s):
  nums = [int(i) for i in s.split(' ')]
  n = len(nums)
  nc = 0
  check = [1 for i in range(n)]
  ct = ''
  for i in range(n):
    st = '('
    j = i 
    while (check[j] == 1):
      check[j] = 0
      st += str(j) + ' '     
      j = nums[j]
    else:
      if (len(st)>1):
        st += ')'
        print(st)
        nc += 1
  return nc
print(cycle(input()))

輸入第一行是人數