#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

ll fibrest(ll x0, ll y0, ll n, bool isx) {
    ll iter = 0;
    vector<ll> fib = {x0, y0};
    ll x = x0;
    ll y = y0;
    ll op = 0;
    while (true) {
        if (isx) {
            x = x + y;
        } else {
            y = y + x;
        }
        if (x >= n) break;
        op++;
        isx = !isx;
    }
    return op;
}
void op(vector<ll> &ops, ll &x, ll &y, ll t) {
    if (t == 1) {
        x = x + 1;
    }
    if (t == 2) {
        y = y + 1;
    }
    if (t == 3) {
        x = x + y;
    }
    if (t == 4) {
        y = y + x;
    }
    ops.push_back(t);
}
void output(vector<ll> &ops) {
    ll k = ops.size();
    print(ops.size());
    for (auto ope : ops) {
        print(ope);
    }
}

int main() {
    ioinit();

    ll n;
    cin >> n;
    // while (fib.back() < n) {
    //     fib.push_back(fib[fib.size() - 1] + fib[fib.size() - 2]);
    // }
    // ll m = fib.size();

    ll x = 0;
    ll y = 0;

    vector<ll> ops;
    if (n < 120) {
        while (x < n) {
            op(ops, x, y, 1);
        }
        output(ops);
        return 0;
    }

    op(ops, x, y, 1);
    bool isx = false;
    while (true) {
        if (x + y > n) {
            while (x < n) {
                op(ops, x, y, 1);
            }
            break;
        }
        ll curop = fibrest(x, y, n, isx);

        {
            ll k = 0;
            while (true) {
                ll r = fibrest(x + k + 1, y, n, isx);
                if (r != curop) break;
                //perr(curop, r);
                op(ops, x, y, 1);
                k = k + 1;
            }
        }
        if (isx) {
            op(ops, x, y, 3);
        } else {
            op(ops, x, y, 4);
        }
        isx = !isx;
        if (x >= n) break;
    }
    output(ops);
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> p(n), pos(n), res;
	REP(i, n) cin >> p[i], pos[--p[i]] = i;

	vector<bool> used(n-1, false);
	REP(i, n) {
		int now = pos[i];
		while (i < now) {
			int before = now - 1;
			if (used[before]) { cout << -1 << '\n'; return 0; }
			used[before] = true;
			pos[p[now]] = before;
			pos[p[before]] = now;
			swap(p[before], p[now]);
			res.emplace_back(before);
			now--;
		}
	}

	if ((int)res.size() != n-1) cout << -1 << '\n';
	else REP(i, n-1) cout << res[i] + 1 << '\n';
    return 0;
}