We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example
24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8
is a permutation of $1,2,...,8$. Of course,
12345678123456781 \quad 2 \quad 3 \quad 4 \quad 5 \quad 6 \quad 7 \quad 8
is also a permutation of $1,2,...,8$.
We can "walk around" a permutation in a interesting way and here is how it is done for the permutation above:
Start at position $1$. At position $1$ we have $2$ and so we go to position $2$. Here we find $4$ and so we go to position $4$. Here we find $1$, which is a position that we have already visited. This completes the first part of our walk and we denote this walk by  ($1$ $2$ $4$ $1$). Such a walk is called a cycle. An interesting property of such walks, that you may take for granted, is that the position we revisit will always be the one we started from!
We continue our walk by jumping to first unvisited position, in this case position $3$ and continue in the same manner. This time we find $5$ at position $3$ and so we go to position $5$ and find $7$ and we go to position $7$ and find $3$ and thus we get the cycle ($3$ $5$ $7$ $3$). Next we start at position $6$ and get ($6$ $6$), and finally we start at position $8$ and get the cycle ($8$ $8$). We have exhausted all the positions. Our walk through this permutation consists of $4$ cycles.
One can carry out this walk through any permutation and obtain a set of cycles as the result. Your task is to print out the cycles that result from walking through a given permutation.

-----Input:-----
The first line of the input is a positive integer $N$ indicating the length of the permutation. The next line contains $N$ integers and is a permutation of $1,2,...,N$.

-----Output:-----
The first line of the output must contain a single integer $k$ denoting the number of cycles in the permutation. Line $2$ should describe the first cycle, line $3$ the second cycle and so on and line $k+1$ should describe the $k^{th}$ cycle.

-----Constraints:-----
- $1 \leq N \leq 1000$.

-----Sample input 1:-----
8
2 4 5 1 7 6 3 8

-----Sample output 1:-----
4
1 2 4 1
3 5 7 3
6 6
8 8 

-----Sample input 2:-----
8
1 2 3 4 5 6 7 8

-----Sample output 2:-----
8
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
n = int(input())
arr = [0] + [int(x) for x in input().split()]
used = []
ans = []
for i in range(1, n + 1):
	d = []
	(start, end) = (i, arr[i])
	if i not in used:
		d.append(i)
		used.append(i)
		while True:
			d.append(end)
			if end == start:
				break
			else:
				used.append(end)
				end = arr[end]
	if len(d) > 0:
		ans.append(d)
print(len(ans))
for i in ans:
	print(*i)


def visit(arr, i, visited):
	ans = []
	temp = arr[i]
	ans.append(i)
	visited[i] = 1
	if temp == arr[temp]:
		ans.append(temp)
		return ans
	while temp != arr[temp]:
		ans.append(temp)
		if visited[i] == 1 and temp == i:
			break
		visited[temp] = 1
		temp = arr[temp]
	return ans
n = int(input())
arr = [0]
arr1 = list(map(int, input().split()))
for i in arr1:
	arr.append(i)
visited = [0] * (n + 1)
x = []
for i in range(1, n + 1):
	if visited[i] == 0:
		x.append(visit(arr, i, visited))
print(len(x))
for i in x:
	print(*i)