You are given a sequence a1, a2, ..., an 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 ≤ 105) — the length of the sequence.

The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — 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 ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤ lj ≤ 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: MEDIUM
Tags: Graph traversal

Sorting

Implementation

Mathematics

Spanning trees
Skill types: Sorting

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
a = sorted(range(n), key=lambda i: a[i])
s = []
for i in range(n):
	if a[i] + 1:
		l = []
		s.append(l)
		while a[i] + 1:
			l.append(i + 1)
			(a[i], i) = (-1, a[i])
print(len(s))
for l in s:
	print(len(l), *l)


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 = sorted(zip(map(int, input().split()), range(n)))
s = []
for i in range(n):
	if a[i]:
		s.append([])
		while a[i]:
			s[-1].append(i + 1)
			(a[i], i) = (None, a[i][1])
print(len(s))
for l in s:
	print(len(l), *l)


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
n = int(input())
seqin = list(rint())
seq = []
for i in range(n):
	seq.append((seqin[i], i))
seq.sort()
subseqs = []
done = [0 for i in range(n)]
for i in range(n):
	s = i
	if done[s]:
		continue
	else:
		subseq = []
	while done[s] != 1:
		done[s] = 1
		subseq.append(s + 1)
		s = seq[s][1]
	subseqs.append(subseq)
print(len(subseqs))
for subseq in subseqs:
	print(len(subseq), *subseq)


from __future__ import print_function
import sys
sys.setrecursionlimit(100005)
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
pos = {}
for i in range(n):
	pos[b[i]] = i
g = [[] for _ in range(n)]
used = [False for _ in range(n)]
for i in range(n):
	g[i] += [pos[a[i]]]
b = []
for i in range(n):
	if used[i] == False:
		w = []
		q = [i]
		while q:
			v = q[-1]
			q.pop()
			w.append(v)
			used[v] = True
			for to in g[v]:
				if used[to] == False:
					q += [to]
		b.append(list(w))
print(len(b))
for i in range(len(b)):
	b[i] = [x + 1 for x in b[i]]
	print(len(b[i]), *b[i], sep=' ')


n = int(input())
a = [int(x) for x in input().split()]
a = list(enumerate(a))
a = sorted(a, key=lambda x: x[1])
a = [(i, x, j) for (j, (i, x)) in enumerate(a)]
a = sorted(a, key=lambda x: x[0])
count_cycles = 0
cycle = [-1] * n
i = 0
while True:
	while i < n and cycle[i] >= 0:
		i += 1
	if i == n:
		break
	k = i
	cycle[i] = count_cycles
	while a[k][2] != i:
		k = a[k][2]
		cycle[k] = count_cycles
	count_cycles += 1
print(count_cycles)
cycles = [[] for i in range(count_cycles)]
for i in range(n):
	cycles[cycle[i]].append(i + 1)
for i in range(count_cycles):
	print(str(len(cycles[i])) + ' ' + ' '.join([str(x) for x in cycles[i]]))


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


n = int(input())
a = list(map(int, input().split()))
ind = sorted(range(n), key=lambda i: a[i])
v = [False] * n
s = []
for i in range(n):
	if not v[i]:
		l = []
		s.append(l)
		while not v[i]:
			v[i] = True
			l.append(i + 1)
			i = ind[i]
print(len(s))
for l in s:
	print(len(l), *l)


n = int(input())
anss = 0
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([i, a[i]])
b = sorted(b, key=lambda a: a[1])
c = []
d = []
e = [0] * n
for i in range(n):
	if e[i] != 1:
		j = i
		d.append(0)
		p = []
		while e[j] != 1:
			d[anss] = d[anss] + 1
			e[j] = 1
			p.append(str(j + 1))
			j = b[j][0]
		c.append(p)
		anss = anss + 1
print(anss)
for i in c:
	print(str(len(i)) + ' ' + ' '.join(i))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([a[i], i])
b.sort()
destinations = [0] * n
inverses = [0] * n
for i in range(n):
	y = b[i][1]
	destinations[i] = y
	inverses[y] = i
visited = [0] * n
k = []
for i in range(n):
	if visited[i]:
		continue
	visited[i] = 1
	k.append([])
	k[-1].append(i)
	curr = destinations[i]
	while visited[curr] == 0:
		visited[curr] = 1
		k[-1].append(curr)
		curr = destinations[curr]
	curr = inverses[i]
	while visited[curr] == 0:
		visited[curr] = 1
		k[-1].append(curr)
		curr = inverses[curr]
ans = []
ans.append(str(len(k)))
for r in k:
	ans.append(str(len(r)))
	for j in r:
		ans.append(str(j + 1))
print(' '.join(ans))


n = int(input())
lis = list(map(int, input().split()))
a = sorted(lis)[:]
d = {}
for i in range(n):
	d[a[i]] = i
vis = [0] * n
ans = []
for i in range(n):
	tmp = []
	if vis[i] == 0:
		j = i
		while vis[j] == 0:
			vis[j] = 1
			tmp.append(j + 1)
			j = d[lis[j]]
		ans.append([len(tmp)] + tmp)
print(len(ans))
for i in ans:
	print(*i)


n = int(input())
a = list(map(int, input().split()))
ans = sorted(a)
ind = {a[i]: i for i in range(n)}
done = [False] * n
total = 0
total_moves = []
for i in range(n):
	if done[i] == False:
		start = a[i]
		done[i] = True
		moves = []
		moves.append(i + 1)
		end = ans[i]
		while start != end:
			moves.append(ind[end] + 1)
			done[ind[end]] = True
			end = ans[ind[end]]
		total_moves.append(moves)
print(len(total_moves))
for i in total_moves:
	print(len(i), end=' ')
	for j in i:
		print(j, end=' ')
	print()


n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
sg = {}
for i in range(n):
	sg[sa[i]] = i
vis = set()
ans = []
for i in range(n):
	if i in vis:
		continue
	vis.add(i)
	c = [i + 1]
	v = i
	while 1:
		nv = sg[a[v]]
		if nv not in vis:
			vis.add(nv)
			c.append(nv + 1)
			v = nv
		else:
			break
	ans.append(c)
print(len(ans))
for c in ans:
	print(len(c), ' '.join([str(e) for e in c]))


n = int(input())
anss = 0
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([i, a[i], 0])
b = sorted(b, key=lambda a: a[1])
for i in range(n):
	b[i].append(i)
b = sorted(b, key=lambda a: a[0])
for i in range(n):
	if b[i][2] != 1:
		j = i
		anss = anss + 1
		while b[j][2] != 1:
			b[j][2] = b[j][2] + 1
			j = b[j][3]
print(anss)
for i in range(n):
	if b[i][2] != 2:
		c = []
		ans = 0
		j = i
		p = []
		while b[j][2] != 2:
			b[j][2] = b[j][2] + 1
			p.append(str(j + 1))
			ans = ans + 1
			j = b[j][3]
		print(str(len(p)) + ' ' + ' '.join(p))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
N = int(input())
A = [int(x) for x in input().split()]
B = [x for x in A]
B.sort()
ind = {v: i for (i, v) in enumerate(B)}
order = [ind[A[i]] for i in range(N)]
done = [0] * N
ans = []
for i in range(N):
	if not done[i]:
		g = []
		cur = i
		while not done[cur]:
			g.append(cur)
			done[cur] = 1
			cur = order[cur]
		ans.append([len(g)] + [j + 1 for j in g])
print(len(ans))
for row in ans:
	print(' '.join(map(str, row)))


n = int(input())
s = list(map(int, input().split()))
s1 = sorted(s)
d = {s1[i]: i for i in range(n)}
ans = []
for i in range(n):
	if d[s[i]] > -1:
		curans = [i + 1]
		cur = i
		place = d[s[cur]]
		while place != i:
			curans.append(place + 1)
			d[s[cur]] = -1
			cur = place
			place = d[s[cur]]
		d[s[cur]] = -1
		ans.append(curans)
print(len(ans))
for a in ans:
	print(len(a), end=' ')
	print(*a)


n = int(input())
m = list(map(int, input().split()))
d = {}
for (i, k) in enumerate(sorted(m)):
	d[k] = i
r = set()
ans = []
for (i, k) in enumerate(m, start=1):
	if k not in r:
		r.add(k)
		ans.append({i})
		j = k
		while m[d[j]] != k:
			r.add(m[d[j]])
			ans[-1].add(d[j] + 1)
			j = m[d[j]]
print(len(ans))
for s in ans:
	print(len(s), *s)


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)


n = int(input())
d = list(map(int, input().split()))
temp = d[:]
d.sort()
from bisect import bisect_left
A = [bisect_left(d, i) for i in temp]
del d, temp
f = [False] * len(A)
result = []
for i in range(n):
	if not f[i]:
		L = [i + 1]
		f[i] = True
		j = A[i]
		while j != i:
			L.append(j + 1)
			f[j] = True
			j = A[j]
		result.append(L)
print(len(result))
for L in result:
	print(len(L), ' '.join(map(str, L)))


from sys import stdin
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().strip().split()))
a = [(a[i], i + 1) for i in range(n)]
a.sort(key=lambda x: x[0])
used = [False] * (n + 1)
ss = []
for i in range(1, n + 1):
	if not used[i]:
		s = [i]
		used[i] = True
		j = i
		while True:
			j = a[j - 1][1]
			if not used[j]:
				s.append(j)
				used[j] = True
			else:
				break
		ss.append(s)
print(len(ss))
for s in ss:
	print(len(s), ' '.join(list(map(str, s))))


from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int, stdin.readline().rstrip().split()))
dic = {}
for (idx, val) in enumerate(data):
	dic[val] = idx + 1
dd = {}
data.sort()
nData = [0]
count = 1
for val in data:
	dd[count] = dic[val]
	count += 1
data = [0] * (n + 1)
for key in dd:
	data[dd[key]] = key
rs = []
mark = [False] * (n + 1)
for i in range(1, n + 1):
	val = i
	itrt = []
	if mark[i]:
		continue
	while True:
		itrt.append(val)
		mark[val] = True
		val = data[val]
		if val == i:
			break
	rs.append(itrt)
print(len(rs))
for ll in rs:
	print('{0} {1}'.format(len(ll), ' '.join(list(map(str, ll)))))