// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename A>
using vpix = vector<pair<int, A>>;

vpix<char> u;
vpix<string> m;

int f(string s) {
  int c = 0, l = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    for (auto p : u) {
      if (s[i] == p.second) {
        c += p.first * (l <= p.first ? 1 : -1);
        l = p.first;
      }
    }
  }
  return c;
}

void solve() {
  u.pb(mp(1000, 'M'));
  u.pb(mp(500, 'D'));
  u.pb(mp(100, 'C'));
  u.pb(mp(50, 'L'));
  u.pb(mp(10, 'X'));
  u.pb(mp(5, 'V'));
  u.pb(mp(1, 'I'));
  string s;
  while (cin >> s) cout << f(s) << endl;
}
#include "bits/stdc++.h"
#include <unordered_set>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;

//==============================================
vi A, G;

int cnt = 0;
int gSize;

void insertionSort(int n,int g) {
	REP2(i, g, n) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int n) {
	int h = 1;
	while (h <= n) {
		G.push_back(h);
		h = 3 * h + 1;
	}
	gSize = G.size();

	RREP(i, gSize) {
		insertionSort(n, G[i]);
	}
	
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	int tmp;
	REP(i, n) cin >> tmp, A.push_back(tmp);

	shellSort(n);

	cout << gSize << "\n";
	RREP(i, gSize) {
		cout << G[i];
		if (i)cout << " ";
	}
	cout << "\n";
	cout << cnt << "\n";

	REP(i, n) {
		cout << A[i] << "\n";
	}
	return 0;
}