Generate all permutations


Submit solution

Points: 2
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Given n integers from 1 to n, arrange them in a row and output all possible permutations after random shuffling.

Input Format

An integer n.

Output Format

Output all possible permutations in ascending lexicographical order, one per line.

  • Adjacent numbers in the same line should be separated by a space.
  • Different permutations are sorted in ascending order according to the lexicographical order.

Constraints

1 ≤ n ≤ 9

Sample Input

3

Sample Output

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

Comments

There are no comments at the moment.