Permutation Generator

You are given a list of n unique elements. Your task is to generate all possible permutations of the elements in the list and output them in lexicographical order.

Input

The first line contains a single integer n (1 ≀ n ≀ 6), representing the length of the list. The second line contains n space-separated distinct integers (1 ≀ ≀ 100), denoting the elements of the list.

Output

Output all possible permutations of the given list, with each permutation printed on a separate line. Each permutation should be represented as a space-separated sequence of elements.

Examples

Input
Output
3 1 3 2
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue