/*   @JUDGE_ID:   1705PZ   120   C */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void flip(int *table,int x)
{
	int i,temp;
	for(i = 0;i <= x / 2;i++)
	{
		temp = *(table + i);
		*(table + i) = *(table + x - i);
		*(table + x - i) = temp;
	}
}

int main()
{
	int i,j,count,max,temp;
	int table[30];
	char string[128];
	char *p;

	while(fgets(string,127,stdin))
	{
		count = 0;
		for(p = strtok(string," ");p;p = strtok(NULL," "))
		{
			temp = atoi(p);
			table[count++] = temp;
		}
		for(i = 0;i < count;i++)
			printf("%d ",table[i]);
		printf("\n");
		for(i = 0;i < count;i++)
		{
			max = 0;
			for(j = 0;j < count - i;j++)
			{
				if(table[j] > max)
				{
					max = table[j];
					temp = j;
				}
			}
			if(temp != count - i - 1)
			{
				flip(table,temp);
				if(temp)
					printf("%d ",count - temp);
				flip(table,count - i - 1);
				printf("%d ",i + 1);
			}
		}
		printf("0\n");
	}
}
@END_OF_SOURCE_CODE
