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
83
84
85
#include <bits/stdc++.h>
#define qio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cerr<<#x<<" "<<x<<endl
#define ll long long 
#define st first
#define nd second
using namespace std;

int n, t, tab[3003], ile;
vector <int> res[2];

map<int, int> M;

deque <int> dq;

void skalowanie() {
	int x = 0;
	for (auto it : M) {
		x++;
		M[it.st] = x;
	}
	for (int i = 1; i <= n; i++) {
		tab[i] = M[tab[i]];
	}
}

bool rosnie() {
	for (int i = 1; i < n; i++) {
		if (tab[i] > tab[i + 1]) return 0;
	}
	return 1;
}

void solve() {
	deque <int> dq;
	bool vis[3003];
	for (int i = 1; i <= n; i++) vis[i] = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			vis[i] = 1;
			int x = i;
			vector <int> temp;
			temp.push_back(i);
			x = tab[x];
			while (x != i) {
				vis[x] = 1;
				temp.push_back(x);
				x = tab[x];
			}
			for (int j = 0; j < temp.size() / 2; j++) {
				swap(tab[temp[j]], tab[temp[temp.size() - j - 1]]);
				dq.push_front(temp[j]);
				dq.push_back(temp[temp.size() - j - 1]);
			}
		}
	}
	while (!dq.empty()) {
		res[ile].push_back(dq.front());
		dq.pop_front();
	}
}
int main()
{
	qio;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> tab[i];
		M[tab[i]] = 1;
	}
	skalowanie();
	ile = 0;
	while (!rosnie()) {
		//debug(ile);
		solve();
		ile++;
	}
	cout << ile << endl;
	for (int i = 0; i < ile; i++) {
		cout << res[i].size() << endl;
		for (int j = 0; j < res[i].size(); j++) {
			cout << res[i][j] << " ";
		}
		cout << endl;
	}
}