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
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	unsigned short n, wzrost, zamiana1, zamiana2, i_z1, i_z2, r=0;
	string numery;
	
	cin >> n;
	
	unsigned short int wzrosty[n];
	unsigned short int s_wzrosty[n];
	
	for(short i=0; i<n; ++i) {
		cin >> wzrost;
		wzrosty[i] = wzrost;
		s_wzrosty[i] = wzrost;
	}
	
	qsort(s_wzrosty, n, sizeof(unsigned short int), [](const void * a, const void * b) {
		return ( *(unsigned short int*)a - *(unsigned short int*)b );
	});
	
	while(!is_sorted(wzrosty, wzrosty+n)) {
		++r;
		numery = "";
		
		for(short j=0; j<n; ++j) {
			if(wzrosty[j]!=s_wzrosty[j]) {
				zamiana1 = wzrosty[j];
				zamiana2 = s_wzrosty[j];
				
				i_z1 = j;
				
				for(short k=0; k<n; ++k) {
					if(wzrosty[k]==zamiana2) {
						i_z2 = k;
						break;
					}
				}
				
				swap(wzrosty[i_z1], wzrosty[i_z2]);
				
				++i_z1;
				++i_z2;
				
				numery.insert(j, to_string(i_z2));
				numery.insert(numery.length()-j-1, to_string(i_z1));
			}
		}
	} 
	
	cout << r << '\n';
	cout << numery.length() << '\n';
	
	for(short l=0; l<numery.length(); ++l) {
		cout << numery[l] << " ";
	}
	
	return 0;
}