import java.util.Arrays;

public class Text13 {

    static int h = 0;

    public static void main(String[] args) {
        int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        permute(array, 0);
    }

    // 验证
    public static int[] text(int[] array) {
        boolean a = array[0] < array[1] && array[0] < array[2];
        boolean b = array[1] < array[3] && array[1] < array[4];
        boolean c = array[2] < array[4] && array[2] < array[5];
        boolean d = array[3] < array[6] && array[3] < array[7];
        boolean e = array[4] < array[7] && array[4] < array[8];
        boolean f = array[5] < array[8] && array[5] < array[9];
        if (a & b & c & d & e & f) {
            return array;
        }
        return null;
    }

    // 递归排列
    public static void permute(int[] array, int start) {
        if (start == array.length - 1 && text(array) != null) {
            System.out.println(++h + " " + Arrays.toString(text(array)));
        }
        for (int i = start; i < array.length; i++) {
            swap(array, start, i);
            permute(array, start + 1);
            swap(array, start, i);
        }
    }

    // 交换
    public static void swap(int[] array, int start, int end) {
        int telp = array[start];
        array[start] = array[end];
        array[end] = telp;
    }
}
