#include <stdio.h>
#include <math.h>

void shellSort(int numbers[], int array_size);
int calculation(int value);

int main(){
	int N;
	int i;
	printf("??´??°?????°?????\??? N < 1000000 \n");
	scanf("%d", &N);

	static int a[1000000];

	for (i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}

	shellSort(a, N);

	for (i = 0; i < N; i++){
		printf(" %d \n", a[i]);
	}


}

void shellSort(int numbers[], int array_size)
{

	int i, j, increment, temp, p, x;
	//increment????¨????
	increment = 1;
	for (p = 0;; p++){
		if (increment > array_size){
			x = p + 1;
			break;
		}
		increment = 3 * increment + 1;
	}

	p = calculation(x);

	//printf("??????????????°_%d??¨increment??????_%d\n", x, p);

	while (x > 0){
		for (i = 0; i < array_size; i++){
			j = i;
			temp = numbers[i];
			while ((j >= calculation(x)) && (numbers[j - calculation(x)]>temp)){
				numbers[j] = numbers[j - calculation(x)];
				j = j - calculation(x);
			}
			numbers[j] = temp;
		}

		x--;
	}
}

int calculation(int value){
	int i;
	int h;
	h = 0;
	for (i = 1; i < value; i++){
		h = 3 * h + 1;
	}

	return h;
}