public static void sort(Integer[] a) {
        int N = a.length;
        int h = 1;
        while (h <= N / 3)
            h = h * 3 + 1;
        System.out.println(h);

        int outer, inner, temp;
        while (h > 0) {
            for (outer = h; outer < N; outer++) {
                temp = a[outer];
                inner = outer;
                while (inner > h - 1 && a[inner - h] >= temp) {
                    a[inner] = a[inner - h];
                    inner -= h;
                }
                a[inner] = temp;
            }
            h = (h - 1) / 3;
        }
    }