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
#include <ios>
#include <iostream>
#include <utility>
#include <vector>
#include <map>
#include <algorithm>
#define nl '\n'

using namespace std;

int n;
vector<int> h,h2;
map<int,int> m;
vector<vector<pair<int,int>>> changes;
bool used[3007];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0; i<n; ++i){
		int tmp;
		cin>>tmp;
		h.push_back(tmp);
		h2.push_back(tmp);
	}
	sort(h2.begin(),h2.end());
	for(int i=0; i<n; ++i){
		m[h2[i]] = i;
	}
	/*for(int i=0; i<n; ++i){
		h[i] = m[h[i]];
	}*/
	int j=0;
	vector<pair<int,int>> a;
	changes.push_back(a);
	while(j<n){
		for(int i=0; i<n; ++i){
			int index_doc = m[h[i]];
			if(i!=index_doc){
				if(!used[h[i]]&&!used[h[index_doc]]){
					changes.back().push_back({i,index_doc});
					swap(h[i],h[index_doc]);
					used[h[index_doc]] = true;
					used[h[i]] = true;
				}
			}
		}
		if(changes.back().empty()){
			break;
		}
		vector<pair<int,int>> a;
		changes.push_back(a);
		for(int i=0; i<3004; ++i){
			used[i] = false;
		}
		++j;
	}
	cout<<changes.size()-1<<nl;
	for(auto it:changes){
		if(it.empty()){
			break;
		}
		cout<<it.size()*2<<nl;
		for(int i=0; i<it.size(); ++i){
			cout<<it[i].first+1<<' ';
		}
		for(int i=it.size()-1; i>=0; --i){
			cout<<it[i].second+1<<' ';
		}
		cout<<nl;
	}
	return 0;
}