A permutation of size n is a sequence of length n in which every integer from 1 to n appears exactly once. Denote such a permutation by a1,a2,…,an.
From a permutation a we build a permutation graph: an undirected graph on vertices numbered 1,2,…,n, in which two vertices i and j (1≤i<j≤n) are joined by an edge whenever ai>aj.
Find all connected components of this graph. Scanning the vertices from the smallest index to the largest, whenever you reach a vertex that has not been visited yet, gather it together with every vertex reachable from it into a single set (a connected component).
Because n can be as large as 1000000, the graph may contain up to O(n2) edges, so building every edge and running a naive depth-first search is too slow. Use the structure of the permutation to find the connected components efficiently.
The first line contains the length of the permutation n (1≤n≤1000000).
The second line contains n space-separated integers, the elements a1,a2,…,an of the permutation.
On the first line, print the number of connected components m.
On each of the next m lines, print one component: first its size si, then the si vertex numbers belonging to it in ascending order, separated by spaces.
When printing several components, sort them in ascending order by the smallest vertex number contained in each component.
The picture below shows the permutation graph built from the permutation in the first example.
