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


int a, c, wynik, d, u, jk, l, k;

int main()
{

cin >> a;

int tab[a + 1];
int t[a + 1];
vector <int> b;
vector <int> suma;
vector <int> op;
for (int i = 0; i <a; i ++)
{
cin >> tab[i];
t[i] = tab[i];
}

sort (tab, tab + a);

 if (a % 2 == 1)
 {
    u = 1;
 }
 else
 {
     u = 0;
 }

while (true)
{

for (int y = 1; y <= a / 2 + u; y++)
{

for (int i = 0; i < a; i++)
{
if (t[i] == tab[a - y])
{
b.push_back(i + 1);
}
}
}


for (int i = 0 ; i < a/ 2 + u; i++)
{

    swap(t[b[i] - 1], t[a - 1 - i]);
}
for (int i = 1; i < a/2 + u;  i++)
{
b.push_back(a/2 + u + i);
}

for (int i = 0; i < a; i++) // w b są 2, 1, 3
{
if (t[i] == tab[i])
{

wynik ++;
}
}

int h = b.size();
suma.push_back(h);
for (int i = 0; i < h; i++)
{
    op.push_back(b[i]);
}
b.clear();
d ++;
if (wynik >= a - 1)
{
break;
}
wynik = 0;
}

cout << d << endl;
l = 0;
for (int i = 0; i < d; i++)
{
    cout << suma[i] << endl;

    for (int y = l; y < l + suma[i]; y++)
    {
        cout << op[y] << " ";
    }
    l = suma[i] + l;
}



}