#include<iostream>
#include<iomanip>
using namespace std;
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<set>
#define MAX 128
int a[MAX];
int myfind(int x,int n) {
	for (int i = 1; i <= n; i++) 
		if (a[i] == x)return i;
	return 0;
}
int main() {
	ios::sync_with_stdio(false);

	int n;
	while (cin >> n) {
		if (n == 0)break;
		vector<int>v;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (int i = n; i >= 1; i--) {
			if (a[i] != i) {
				while (a[i] != i) {
					int pos = myfind(i,n);
					if (pos == 1) {
						v.push_back(i);
						reverse(a + 1, a + 1 + i);
					}
					else {
						v.push_back(pos);
						reverse(a + 1, a + 1 + pos);
						v.push_back(i);
						reverse(a + 1, a + 1 + i);
					}
					
				}
			}
			else {
				continue;
			}
		}
		cout << v.size()<<" " ;
		for (int i = 0; i < v.size(); i++)
			cout << v[i] << " ";
		cout << endl;

	}


	
	return 0;
}