#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <algorithm>
using namespace std;
const char *p = " ";
int s[35];
int st[35];
char sr[5010];
int jl[3000];
bool pd(int k)
{
for(int i = 0; i < k; i++)
{
if(s[i] != st[i])
return false;
}
return true;
}
int main()
{
int k;
char zh[4];
char *q = zh;
while(gets(sr))
{
k = 0;
int js = 0;
q = strtok(sr,p);
while(q != NULL)
{
s[k] = atoi(q);
st[k] = s[k];
k++;
q = strtok(NULL,p);
}
for(int i = 0;i < k;i++)
{
printf("%d",s[i]);
if(i < k - 1)
printf(" ");
}
printf("\n");
sort(st,st + k);
int n = k;
while(!pd(k) && n != 0)
{
int mx = -1;
int xb = -1;
for(int i = 0;i < n;i++)
{
if(mx < s[i])
{
mx = s[i];
xb = i;
}
}
if(s[n - 1] != mx)
{
if(s[0] == mx)
{
int *x = &s[0];
int *y = &s[n - 1];
while(x < y)
{
int tmp = *x;
*x = *y;
*y = tmp;
x++;
y--;
}
jl[js++] = k - n + 1;
n--;
}
else
{
int *x = &s[0];
int *y = &s[xb];
while(x < y)
{
int tmp = *x;
*x = *y;
*y = tmp;
x++;
y--;
}
jl[js++] = k - xb;
}
}
else
n--;
}
for(int i = 0;i < js;i++)
{
printf("%d ",jl[i]);
}
printf("0\n");
}
return 0;
}