You are given a sequence a_1, a_2, ..., a_{n} consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.

Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.

Every element of the sequence must appear in exactly one subsequence.


-----Input-----

The first line of input data contains integer n (1 ≤ n ≤ 10^5) — the length of the sequence.

The second line of input data contains n different integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.


-----Output-----

In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.

In the next k lines print the description of subsequences in the following format: the number of elements in subsequence c_{i} (0 < c_{i} ≤ n), then c_{i} integers l_1, l_2, ..., l_{c}_{i} (1 ≤ l_{j} ≤ n) — indices of these elements in the original sequence. 

Indices could be printed in any order. Every index from 1 to n must appear in output exactly once.

If there are several possible answers, print any of them.


-----Examples-----
Input
6
3 2 1 6 5 4

Output
4
2 1 3
1 2
2 4 6
1 5

Input
6
83 -75 -49 11 37 62

Output
1
6 1 2 3 4 5 6



-----Note-----

In the first sample output:

After sorting the first subsequence we will get sequence 1 2 3 6 5 4.

Sorting the second subsequence changes nothing.

After sorting the third subsequence we will get sequence 1 2 3 4 5 6.

Sorting the last subsequence changes nothing.

Difficulty: competition

Starter code:

Solutions:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())
b=list(map(int,input().split()))
bb=sorted(b)
c={bb[i]:i for i in range(n)}
a=[c[b[i]] for i in range(n)]
vis=[0]*n

out=[]
for i in range(n):
    if vis[i]: continue
    vis[i]=1
    newlist=[i]
    while a[newlist[-1]]!=i:
        newlist.append(a[newlist[-1]])
        vis[newlist[-1]]=1
    out.append(newlist)

print(len(out))
for i in out:
    print(" ".join([str(x+1) for x in [len(i)-1]+i]))


n = int(input())
a = list(map(int, input().split()))

x = sorted([(a[i], i) for i in range(n)])

cycles = []

was = [False for i in range(n)]
for i in range(n):
    if was[i]:
        continue
    cur = i
    cyc = []
    while not was[cur]:
        was[cur] = True
        cyc.append(cur + 1)
        cur = x[cur][1]
    cycles.append(cyc)

print(len(cycles))
for cyc in cycles:
    print(len(cyc), ' '.join(map(str, cyc)))


n = int(input())

a = input().split()
a = [(int(a[i]), i) for i in range(n)]
a.sort()

start = 0
used = set()

b = []

while start < n:
    t = []
    cur = start
    first = True

    while cur != start or first:
        first = False
        t.append(cur+1)
        used.add(cur)
        cur = a[cur][1]
    
    b.append(t)
    while start in used: start += 1

print(len(b))

for t in b:
    print(len(t), end=' ')
    print(*t)

import sys
n = int(input())
a = list(map(int, input().split()))
a = sorted([(a[i], i) for i in range(n)])
d = []
c = [False]*n
for i in range(n):
    if not c[i]:
        k = i
        p = []
        while not c[k]:
            c[k] = True
            p.append(str(k+1))
            k = a[k][1]
        d.append(p)
        
print(len(d))
for i in d:
    print(str(len(i))+" "+" ".join(i))

def binSearch(arr, el):
    if len(arr) == 0: return -1
    l, p = 0, len(arr)-1
    while l != p:
        s = (l+p) // 2
        if arr[s] < el:
            l = s + 1
        else:
            p = s
    return l if arr[l] == el else -1

n = int(input())
a = [int(i) for i in input().split()]
s = sorted(a)

subsList = []
visited = [False for i in range(n)]
for i in range(n):
    ind = i
    newSub = False
    while not visited[ind]:
        if not newSub:
            subsList.append([])
        newSub = True
        visited[ind] = True
        subsList[-1].append(str(ind+1))
        ind = binSearch(s, a[ind])
    
out = str(len(subsList)) + "\n"
for lineNr in range(len(subsList)-1):
    
    out += str(len(subsList[lineNr])) + " "
    out += " ".join(subsList[lineNr]) + "\n"
out += str(len(subsList[-1])) + " "    
out += " ".join(subsList[-1])
print(out)
        



n = int(input())
a = list(map(int, input().split()))
a = sorted([(a[i], i) for i in range(n)])
b = []
c = [True] * n
for i in range(n):
    if c[i]:
        j = i
        d = []
        while c[j]:
            c[j] = False
            d.append(j + 1)
            j = a[j][1]
        b.append(d)

print(len(b))
for i in b:
    print(len(i),*i)

n = int(input())
a = [int(i) for i in input().split()]
a = [i[0] for i in sorted(enumerate(a), key= lambda x:x[1])]
checker = [0 for i in range(n)]
ans_set = []
for i in range(n):
    if checker[i] == 0:
        tmp = set([i])
        next_step = i
        next_step = a[next_step]
        while next_step != i:
            checker[next_step] = 1
            tmp.add(next_step)
            next_step = a[next_step]
        ans_set.append(tmp)
print(len(ans_set))
for tmp in ans_set:
    print(len(tmp), end = " ")
    for j in tmp:
        print(j+1, end = " ")
    print()
  				   	 		  	 		 	 	  	 			

import sys
cases = int(sys.stdin.readline())
input_arr = [int(x) for x in sys.stdin.readline().strip().split(" ")]
#input_arr = [-1, -4, 10, 9, 200]

sort = sorted(input_arr)
sorted_dict = dict()
for i in range(0, len(sort)):
  sorted_dict[sort[i]] = i + 1

array = []
for x in input_arr:
  array.append(sorted_dict[x])

seen = set()

my_dict = dict()
for i in range(1, len(array) + 1):
  my_dict[i] = array[i - 1]
  
def find_permutation(seen, x):
  permutation = []
  while(x not in seen):
    permutation.append(x)
    seen.add(x)
    x = my_dict[x]
    
  return(str(len(permutation)) + " " + " ".join(str(x) for x in sorted(permutation)))

num_perms = 0
to_print = []
for x in array:
  if(x not in seen):
    num_perms += 1
    to_print.append(find_permutation(seen, x)) 
    seen.add(x)

print(num_perms)
print('\n'.join(to_print))



n = int(input())

a = sorted(zip(list(map(int, input().split())), list(range(n))))

s = []

for i in range(n):

    if a[i]:

        l = []

        s.append(l)

        while a[i]:

            l.append(i + 1)

            a[i], i = None, a[i][1]

            

print(len(s))

for l in s:

    print(len(l), *l)







# Made By Mostafa_Khaled


n=int(input())
a=list(map(int,input().split()))
s=[(a[i],i) for i in range(n)]
s.sort()
x=[-1]*n
for i in range(n):
    x[s[i][1]]=i
ans=[]
for i in range(n):
    if x[i]!=-1:
        j=i
        q=[]
        while x[j]!=-1:
            q.append(str(j+1))
            t=j
            j=x[j]
            x[t]=-1
        ans.append(str(len(q))+' '+' '.join(q))
print(len(ans))
print(*ans, sep='\n')


import operator as op


input()
a = list(x[0] for x in sorted(enumerate(map(int, input().split())), key=op.itemgetter(1)))

ans = []
for i in range(len(a)):
    if a[i] != -1:
        j = a[i]
        a[i] = -1
        t = [i + 1]
        while j != i:
            t.append(j + 1)
            last = j
            j = a[j]
            a[last] = -1
        ans.append(t)

print(len(ans))
for i in range(len(ans)):
    print(len(ans[i]), *ans[i])


n = int(input())
a = sorted(zip(map(int, input().split()), range(n)))
# print(a)
s = []

for i in range(n):
    if a[i]:
        s.append([])
        j=i
        while a[j]:
            s[-1].append(j + 1)
            a[j], j = None, a[j][1]
            
print(len(s))
for l in s:
    print(len(l), *l)

MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n=ii()
l=il()
l2=sorted(l)
sd=dict((l2[i],i) for i in range(n))
ans=[]
lvis=set()
for i in range(n):
    if not l[i] in lvis:
        tmp=[i+1]
        x=sd[l[i]]
        lvis.add(l[i])
        while x!=i:
            lvis.add(l[x])
            tmp.append(x+1)
            x=sd[l[x]]
        ans.append(tmp)
print(len(ans))
for i in ans:
    print(len(i),*i)

n = int(input())
a = list(map(int,input().split()))
x = sorted([(a[i], i) for i in range(n)])
ans = []
visited = [False for i in range(n)]

for i in range(n):
    if visited[i]:
        continue
    cur = i
    cyc = []
    while not visited[cur]:
        visited[cur] = True
        cyc.append(cur + 1)
        cur = x[cur][1]
    ans.append(cyc)
 
print(len(ans))
for cyc in ans:
    print(len(cyc), ' '.join(map(str, cyc)))

n = int(input())
a = list(map(int,input().split()))
x = sorted([(a[i], i) for i in range(n)])
ans = []
visited = [False for i in range(n)]

for i in range(n):
    if visited[i]:
        continue
    cur = i
    cyc = []
    while not visited[cur]:
        visited[cur] = True
        cyc.append(cur + 1)
        cur = x[cur][1]
    ans.append(cyc)
 
print(len(ans))
for cyc in ans:
    print(len(cyc),*cyc)

import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

n = int(input())
a = list(map(int, input().split()))
b = a[:]
b.sort()
d = defaultdict(int)

for i in range(n):
    d[b[i]] = i

uf = Unionfind(n)

for i in range(n):
    uf.unite(i, d[a[i]])

ans = defaultdict(list)

for i in range(n):
    ans[uf.root(i)].append(i)

print(len(list(ans.keys())))

for l in ans.values():
    print(len(l), *list(map(lambda x: x+1, l)))

#!/usr/bin/env python

from sys import stdin
from collections import defaultdict

# Go from node start and return a list of visited nodes
def dfs(graph, seen, start):
    if seen[start]:
        return None

    visit = [start]
    ans = []
    while visit:
        node = visit.pop()
        seen[node] = True
        ans.append(node)
        for v in graph[node]:
            if not seen[v]:
                visit.append(v)

    return ans

def main(n, arr):
    orig = {}
    for i in range(n):
        val = arr[i]
        orig[val] = i
    _arr = sorted(arr)

    g = defaultdict(list)
    for i in range(n):
        val = _arr[i]
        origpos = orig[val]
        g[origpos].append(i) # there's a connection between this two positions
    
    seen = [False] * n
    ans = []
    for i in range(n): # ensure we visit all nodes
        if not seen[i]:
            ans.append(dfs(g, seen, i))

    print(len(ans))
    for a in ans:
        print(len(a), " ".join(map(lambda x: str(x + 1), a))) # add 1 for 1 based index


def __starting_point():
    n = int(stdin.readline())
    arr = list(map(int, stdin.readline().split(" ")))
    main(n, arr)
__starting_point()

from collections import Counter,defaultdict,deque
#alph = 'abcdefghijklmnopqrstuvwxyz'
#from math import factorial as fact
import math

#nl = '\n'
#import sys
#input=sys.stdin.readline
#print=sys.stdout.write

#tt = int(input())
#total=0
#n = int(input())
#n,m,k = [int(x) for x in input().split()]
#n = int(input())

#l,r = [int(x) for x in input().split()]

n = int(input())
arr = [int(x) for x in input().split()]
d = {}
visited = {}
for i in range(n):  
   d[arr[i]] = i  
   visited[arr[i]] = False
res =[]
sarr = sorted(arr)
for el in sarr:
   cur = []
   nxt = el
   while True:
      if visited[nxt]:
         break
      visited[nxt] = True
      cur.append(d[nxt])
      nxt = sarr[d[nxt]]
   if len(cur):
      res.append(cur)
print(len(res))
for el in res:
   print(len(el),end=' ')
   for p in el:
      print(p+1,end = ' ')
   print()
      
   
   
 


from sys import stdin
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
n=I();v=[1]*n
a=list(R());d={}
for i,j in enumerate(sorted(a)):d[j]=i
for i in range(n):a[i]=d[a[i]]
ans=[]
for i in a:
	if v[i]:
		ans+=[],
		while v[i]:
			ans[-1]+=i+1,
			v[i]=0
			i=a[i]
print(len(ans))
for i in ans:
	print(len(i),*i)

from sys import stdin
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
n=I();v=[1]*n
a=list(R());d={}
for i,j in enumerate(sorted(a)):d[j]=i
ans=[]
for i in a:
	p=d[i]
	if v[p]:
		ans+=[],
		while v[p]:
			ans[-1]+=p+1,
			v[p]=0
			p=d[a[p]]
print(len(ans))
for i in ans:
	print(len(i),*i)

from sys import stdin
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
n=I();v=[1]*n
a=list(R());d={}
for i,j in enumerate(sorted(a)):d[j]=i
ans=[]
for i in a:
	p=d[i]
	if v[p]:
		l=0
		ans+=[],
		while v[p]:
			ans[-1]+=p+1,
			v[p]=0
			p=d[a[p]]
			l+=1
		ans[-1]+=l,
print(len(ans))
for i in ans:
	print(i[-1],*i[:i[-1]])

from sys import stdin
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
n=I();v=[1]*n
a=list(R());d={}
for i,j in enumerate(sorted(a)):d[j]=i
ans=[]
for i in a:
	p=d[i]
	if v[p]:
		l=0
		ans+=[],
		while v[p]:
			ans[-1]+=p+1,
			v[p]=0
			p=d[a[p]]
			l+=1
		ans[-1]+=l,
print(len(ans))
for i in ans:
	print(i[-1],*i[:i[-1]])

n = int(input())
a = list(map(int, input().split()))

sorted_a = sorted(a)
d = {}
for i in range(len(a)): d[sorted_a[i]] = i
for i in range(len(a)): a[i] = d[a[i]]

res = []
done = [False]*n
for i in a:
    if done[i]: continue
    done[i] = True
    curr_subseq = set([i])
    next_item = a[i]
    while next_item not in curr_subseq:
        curr_subseq.add(next_item)
        done[next_item] = True
        next_item = a[next_item]
    res.append(curr_subseq)

print(len(res))
for i in res:
    curr = [str(j+1) for j in list(i)]
    print(len(curr), end=' ')
    print(' '.join(curr))

from collections import defaultdict
def DFS(d,visited,x):

	stack = [x]
	ans = []

	while len(stack):

		temp = stack.pop()
		visited[temp] = 1
		ans.append(temp+1)
		for i in d[temp]:

			if visited[i] == 0:
				stack.append(i)
				visited[temp] = 1

	return ans

n = int(input())
l = list(map(int,input().split()))
act_pos = {l[i]:i for i in range(n)}
pos = []
t = sorted(l)
pos = {t[i]:i for i in range(n)}

d = defaultdict(list)

for i in l:

	d[act_pos[i]].append(pos[i])


visited = [0 for i in range(n)]
ans = []
for i in range(n):

	if visited[i] == 0:

		k = list(DFS(d,visited,i))

		t1 = k[::-1]
		t1.append(len(k))

		ans.append(t1[::-1])
print(len(ans))
for i in ans:
	print(*i)