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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

const int MAXN = 1000007;

vector<pii> ord;
int t[MAXN];
int vis[MAXN];
int n;

void swap_cycle(int x) {
	vector<int> cyc;
	
	while (!vis[x]) {
		vis[x] = 1;
		cyc.push_back(x);
		x = t[x];
	}
	
	for (int i=0; cyc.size()-1-i > i; i++) {
		ord.push_back({cyc[i], cyc[cyc.size()-1-i]});
		swap(t[cyc[i]], t[cyc[cyc.size()-1-i]]);
	}
}

vector<vector<int>> res;

bool is_sorted() {
	for (int i=0; i<n-1; i++) {
		if (t[i] > t[i+1])
			return false;
	}
	
	return true;
}

void print_res() {
	printf("%d\n", res.size());
	for (const auto &row : res) {
		printf("%d\n", row.size());
		for (int a : row)
			printf("%d ", a+1);
		printf("\n");
	}
}

bool flush_swaps() {
	for (int i=0; i<n; i++)
		vis[i] = 0;
	
	res.push_back({});
	vector<int> tmp;
	
	for (auto p : ord) {
		res.back().push_back(p.first);
		tmp.push_back(p.second);
	}
	
	while (!tmp.empty()) {
		res.back().push_back(tmp.back());
		tmp.pop_back();
	}
	
	ord.clear();
	
	if (is_sorted()) {
		print_res();
		return true;
	} else {
		return false;
	}
}

int main() {
	scanf("%d", &n);
	
	for (int i=0; i<n; i++) {
		int a;
		scanf("%d", &a);
		ord.push_back({a, i});
	}
	
	sort(ord.begin(), ord.end());
	
	for (int i=0; i<n; i++) {
		t[ord[i].second] = i;
	}
	
	if (is_sorted()) {
		print_res();
		return 0;
	}
	
// 	for (int i=0; i<n; i++)
// 		printf("%d ", t[i]);
// 	printf("\n");
	
	
	while (2) {
		ord.clear();
		
		for (int i=0; i<n; i++) {
			if (vis[i] == 0)
				swap_cycle(i);
		}
		
		if (flush_swaps())
			break;
	}
	
	return 0;
}