#include <iostream>
#include <algorithm>
#include <vector>
typedef int TInt;
typedef std::vector<TInt> TList;

TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i];
    }
    return List;
}
int insertionSort(TList& A, int g)
{
    int cnt = 0;
    for(int i = g; i < A.size(); ++i){
        TInt v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    return cnt;
}
void Reverse(TList& List)
{
    TList R;
    for(TList::reverse_iterator It = List.rbegin();
        It != List.rend();
        ++It)
    {
        R.push_back(*It);
    }
    std::swap(R, List);
}
TList GetG(int Max)
{
    TList G;
    int h = 1;
    while(h <= Max){
        G.push_back(h);
        h = 3 * h + 1;
    }
    // Reverse(G);
    std::reverse(G.begin(), G.end());
    return G;
}
int shellSort(TList& A, const TList& G)
{
    int cnt = 0;
    for(TList::const_iterator It = G.begin();
        It != G.end();
        ++It){
        cnt += insertionSort(A, *It);
    }
    return cnt;
}
void OutputLine(const TList& List)
{
    TList::const_iterator It = List.begin();
    std::cout << *(It++);
    for(; It != List.end(); ++It){
        std::cout << " " << *It;
    }
    std::cout << std::endl;
}
void Output(const TList& List)
{
    TList::const_iterator It = List.begin();
    // std::cout << *(It++);
    for(; It != List.end(); ++It){
        std::cout << *It << std::endl;
    }
}
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    TList A = Input();
    TList G = GetG(A.size());
    int cnt = shellSort(A, G);
    std::cout << G.size() << std::endl;
    OutputLine(G);
    std::cout << cnt << std::endl;
    Output(A);
    return 0;   
}
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	
	while (cin >> n, n){
		vector<pair<double, string>> veg(n);
		REP(i, n){
			double a, b, c, d, e, f, g, h, m;
				cin >> veg[i].second;
				cin >> a >> b >> c >> d >> e >> f >> g >> h >> m;
				veg[i].first = -(m*h*g-a)/((b+c+d)+(e+f)*m);
				
		}
		SORT(veg);
		REP(i, n){
			cout << veg[i].second << endl;
		}
		cout << '#' << endl;
	}
}