Write a program that prints all the permutations of with inversions, for a given and . An inversion is a pair of elements and such that and such that appears before in the permutation.
Input consists of two natural numbers and , such that and .
Print all the permutations of with inversions.
You can print the solutions to this exercise in any order.
Here, a very simple algorithm may be too slow.
Input
5 2
Output
(1,2,4,5,3) (1,2,5,3,4) (1,3,2,5,4) (1,3,4,2,5) (1,4,2,3,5) (2,1,3,5,4) (2,1,4,3,5) (2,3,1,4,5) (3,1,2,4,5)
Input
10 45
Output
(10,9,8,7,6,5,4,3,2,1)