Recursion
Recursion-17
Recursion-18
Recursion-19
~/algor $ cat problems/rekursiya-orin-almashtirishlar
All permutations
Medium
1000 ms
128 MB
56%
You are given $n$ distinct integers. Print all their permutations (orders in which every number appears exactly once) in lexicographic order: first by the smaller first element, with equal first elements by the smaller second one, and so on.
Input
The first line contains a positive integer $n$. The second line contains $n$ distinct integers $a_{i}$ separated by spaces.
Output
$n!$ lines, each with $n$ integers separated by spaces.
Note
$1 \le n \le 8$
$-100 \le a_{i} \le 100$
the numbers $a_{i}$ are distinct
Examples
Input #1
3 2 1 3
Output #1
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Input #2
1 7
Output #2
7