#include <iostream>
#include <vector>
using namespace std;
int n;
int a[35];
int main() {
    while (cin >> n && n) {
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int cnt = 0, num = n;
        vector<int>ans;
        while (num > 1) {
            int maxn = 0, maxx = 0;
            for (int i = 1; i <= num; i++) {
                if (a[i] > maxx) {
                    maxx = a[i];
                    maxn = i;
                }
            }
            if(maxn == num)
            {
                num--;
                continue;
            }
            if (maxn == 1) {
                ans.push_back(num);
                for (int i = 1, j = num; i <= j; i++, j--) {
                    swap(a[i], a[j]);
                }
                cnt++;
            } else {
                ans.push_back(maxn);
                ans.push_back(num);
                for (int i = 1, j = maxn; i <= j; i++, j--) {
                    swap(a[i], a[j]);
                }
                for (int i = 1, j = num; i <= j; i++, j--) {
                    swap(a[i], a[j]);
                }
                cnt += 2;
            }
            num--;
        }
        cout << cnt;
        for (int i = 0; i < ans.size(); i++)
            cout << " " << ans[i];
        cout << endl;
    }
}