1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
N = int(input().strip())

x = []

for i in range(N):
    x.append(int(input().strip()))


import numpy as np

x = np.argsort(x)

vis = [False] * len(x)

cycles = []

curr = []
for i in range(N):
    if not vis[i]:
        vis[i] = True
        c = i
        curr.append(i)
        while x[c] != i:
            curr.append(x[c])
            c = x[c]
            vis[c] = True
        cycles.append(curr)
        curr = []

r = max(len(c) - 1 for c in cycles)

print(r)

for i in range(r):
    xx = []
    yy = []
    for cyc in cycles:
        if len(cyc) > 1:
            xx.append(cyc[0]+1)
            yy.append(cyc.pop()+1)
    yy.reverse()
    res = xx + yy
    print(len(res))
    print(' '.join((str(x) for x in res)))