LogiQuest

211. Unique Permutations

MediumBacktracking

The values may repeat. Print all distinct permutations in lexicographic order.

Input format

Line 1: n Line 2: n integers

Output format

The distinct permutations.

Example 1

Input

3
1 1 2

Output

1 1 2
1 2 1
2 1 1

Example 2

Input

3
2 2 2

Output

2 2 2

Constraints

1 ≤ n ≤ 8

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…