#K4571. Unique Permutations of Books

    ID: 27814 Type: Default 1000ms 256MiB

Unique Permutations of Books

Unique Permutations of Books

Given a list of book names as a single line of input (each separated by whitespace), print all the unique permutations of these books in lexicographical order. Permutations must be printed one per line with the book names separated by a single space.

Let \(B = \{b_1, b_2, \dots, b_n\}\) be the input list of books. First, sort \(B\) lexicographically. Then, generate all permutations \(P\) of \(B\) and output them in lexicographical order. Each permutation \(p \in P\) should be printed as:

[ p = (b_{i_1}, b_{i_2}, \dots, b_{i_n}) ]

where the names are separated by a space.

inputFormat

The input consists of a single line containing one or more book names separated by spaces.

outputFormat

Output all unique permutations of the book names in lexicographical order. Each permutation should be printed on a separate line, with the book names separated by a single space.

## sample
red
red

</p>