#C3903. Organize Books
Organize Books
Organize Books
You are given a list of books along with their associated tags. Each book description is provided as a single line where the book title (which may contain spaces) is followed by an integer indicating the number of tags attached to that book, and then the tags themselves. The task is to sort the books primarily by the number of tags in ascending order and secondarily by the book title in lexicographical order.
Input Format: The first line contains an integer \(n\) representing the number of books. The following \(n\) lines each contain a book description. In each line, the book title appears first, followed by an integer (in \(\texttt{\LaTeX}\) format: \(k\)) indicating the number of tags, and then exactly \(k\) tags.
Output Format: Output the sorted book titles, one title per line.
inputFormat
The input is read from standard input (stdin). The first line contains an integer \(n\) indicating the number of books. Each of the next \(n\) lines contains a single book description. A book description consists of a title (which may contain spaces) followed by an integer representing the number of tags and then that many tags separated by spaces. It is guaranteed that the first numeric token in each line is the number of tags.
outputFormat
For each test case, output the sorted titles of the books on standard output (stdout), each on a new line. The books should be sorted in ascending order by the number of tags and then in lexicographical (alphabetical) order by title.
## sample3
the great gatsby 3 classic literature fiction
moby dick 2 sea adventure
to kill a mockingbird 2 classic fiction
moby dick
to kill a mockingbird
the great gatsby
</p>