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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 3e3+1;
vector <pair<int,int>> s;

int h[MAXN], hc[MAXN], wys[MAXN];
vector <int> ans2[MAXN];
bool odw[MAXN], us[MAXN];


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n; cin >> n;
	for (int i=1; i<=n; i++){cin >> h[i]; hc[i] = h[i];}
	sort(hc+1, hc+n+1);
	
	int mx = 0;
	for (int i=1; i<=n; i++){
		for (int j=i+1; j<=n; j++){
			if (h[i] == hc[j] || h[j] == hc[i]){
				s.push_back({i, j});
				wys[i]++;
				wys[j]++;
				mx=max(max(wys[i], wys[j]), mx);
				swap(h[i], h[j]);
			}
		}
	}
	cout << mx << '\n';
	int t=0;
	while (t < s.size()){
		vector <int> l, p;
		int te = 0;
		for (int i=0; i<s.size(); i++){
			auto x = s[i];
			if (!odw[x.first] && !odw[x.second] && !us[i]){
				us[i] = true;
				odw[x.first] = true, odw[x.second] = true;
				l.push_back(x.first); p.push_back(x.second);
				te+=2;
				t++;
			}
		}
		cout << te << '\n';
		reverse(p.begin(), p.end());
		for (auto x : l) cout << x << ' ';
		for (auto x : p) cout << x << ' ';
		cout << '\n';
		for (int i=1; i<=n; i++) odw[i] = false;
	}
}