For given an integer $n$, print all permutations of $\\{1, 2, ..., n\\}$ in lexicographic order.

Constraints

* $1 \leq n \leq 9$

Input

An integer $n$ is given in a line.

Output

Print each permutation in a line in order. Separate adjacency elements by a space character.

Examples

Input

2


Output

1 2
2 1


Input

3


Output

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
import java.util.*;
// import java.io.*;
// import java.time.*;

public class Main {
    static StringBuilder sb;
    static List<List<Integer>> permutations;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sb = new StringBuilder();

        int num = sc.nextInt();

        ArrayList<Integer> array = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            array.add(i + 1);
        }

        permutations = new ArrayList<List<Integer>>();
        permutation(array, new ArrayList<>());

        for (int i = 0; i < permutations.size(); i++) {
            printListWithWhiteSpace(permutations.get(i));
        }

        System.out.print(sb);
        
        sc.close();
    }

    public static void permutation(List<Integer> q, List<Integer> ans){
        // Base Case
        if(q.size() <= 1) {
            List<Integer> tmp = new ArrayList<>();
            tmp.addAll(new ArrayList<>(ans));
            tmp.add(q.get(0));
            permutations.add(tmp);
        }
        // General Case
        else {
            for (int i = 0; i < q.size(); i++) {
                List<Integer> new_q = new ArrayList<>();
                new_q.addAll(new ArrayList<>(q.subList(0, i)));
                new_q.addAll(new ArrayList<>(q.subList(i + 1, q.size())));
                List<Integer> new_ans = new ArrayList<>();
                new_ans.addAll(new ArrayList<>(ans));
                new_ans.add(q.get(i));
                permutation(new_q, new_ans);
            }
        }
    }

    public static void printListWithWhiteSpace(List<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i));
            if (i != list.size() - 1) sb.append(' ');
            else sb.append("\n");
        }
    }
}

