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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import random

n = int(input())

#h = random.sample(range(1, 3001), n)
h = [int(input()) for _ in range(n)]

he = [0] * 4000
for v in h:
    he[v] = 1

for i in range(3500):
    he[i + 1] += he[i]

order = [he[v] - 1 for v in h]

#print(h, order)

l1, r1, l2, r2 = [], [], [], []

vis = [0] * n
for i in range(n):
    if vis[i]:
        continue

    c = [i]
    while order[c[-1]] != i:
        c.append(order[c[-1]])

    for v in c:
        vis[v] = 1

    m = len(c)
    #print(c)

    if len(c) == 1:
        pass
    elif len(c) == 2:
        l1.append(c[0] + 1)
        r1.append(c[1] + 1)
    elif len(c) % 2 == 0:
        for i in range(m // 2 - 1):
            l1.append(c[i + 1] + 1)
            r1.append(c[m - i - 1] + 1)

        for i in range(1, 1 + m // 2):
            l2.append(c[i] + 1)
            r2.append(c[(m + 1 - i) % m] + 1)
    else:
        for i in range(m // 2):
            l1.append(c[i + 1] + 1)
            r1.append(c[m - i - 1] + 1)

        for i in range(1, 1 + m // 2):
            l2.append(c[i] + 1)
            r2.append(c[(m + 1 - i) % m] + 1)

assert len(l1) == len(r1)
assert len(l2) == len(r2)

for u, v in zip(l1, r1):
    h[u - 1], h[v - 1] = h[v - 1], h[u - 1]

for u, v in zip(l2, r2):
    h[u - 1], h[v - 1] = h[v - 1], h[u - 1]

assert len(set(l1 + r1)) == len(l1 + r1)
assert len(set(l2 + r2)) == len(l2 + r2)
assert h == sorted(h)

if l2:
    print(2)
    print(len(l1) * 2)
    print(' '.join(map(str, l1 + r1[::-1])))
    print(len(l2) * 2)
    print(' '.join(map(str, l2 + r2[::-1])))
elif l1:
    print(1)
    print(len(l1) * 2)
    print(' '.join(map(str, l1 + r1[::-1])))
else:
    print(0)