#K1401. Permutations of a List
Permutations of a List
Permutations of a List
Given a list of n distinct integers, you are required to output all possible permutations of these integers.
The input starts with an integer n representing the number of elements, followed by n space‐separated integers. The output should print each permutation in a new line. Each permutation is printed as space-separated integers.
You may output the permutations in any order; however, for the sake of consistent checking, we expect the solutions to generate the permutations sorted in lexicographical order. In mathematical terms, if the given array is \( A = [a_1, a_2, \dots, a_n] \), then you need to output all sequences \( \pi(A) \) where \( \pi \) is a permutation of indices, sorted in lexicographic increasing order.
inputFormat
The first line contains an integer n ((1 \leq n \leq 10)) indicating the number of elements. The second line contains n space-separated distinct integers.
outputFormat
Print each permutation on a new line. In each line, print the permutation as n space-separated integers. The permutations should be printed in lexicographical order.## sample
1
1
1
</p>