#C3706. Library Catalog System

    ID: 47163 Type: Default 1000ms 256MiB

Library Catalog System

Library Catalog System

You are required to implement a Library Catalog System. The system supports three operations: adding a book with a given book ID and its genre, retrieving the genre of a specific book, and retrieving all book IDs for a given genre in ascending order.

When a book is added using the operation "ADD", its book ID and genre are recorded. For the operation "GENRE", the genre corresponding to the book ID is returned. For the operation "BOOKS", the list of book IDs in ascending order belonging to the specified genre is returned, separated by a space.

The operations are defined as follows:
$$\text{ADD book_id genre}$$
$$\text{GENRE book_id}$$
$$\text{BOOKS genre}$$

inputFormat

The first line contains an integer Q, representing the number of operations. Each of the following Q lines contains one of the following operations:
ADD book_id genre: Add a book with the given book ID and genre to the library.
GENRE book_id: Print the genre of the book with the given book ID.
BOOKS genre: Print all book IDs that belong to the specified genre in ascending order, separated by a space.

Input is read from standard input (stdin). Note: There is no output for ADD operations.

outputFormat

For each GENRE and BOOKS operation, output the result on a new line to standard output (stdout). For GENRE, output the genre of the specified book. For BOOKS, output the list of book IDs in ascending order, separated by a space.## sample

6
ADD 101 fiction
ADD 102 science
GENRE 101
BOOKS fiction
ADD 103 fiction
BOOKS fiction
fiction

101 101 103

</p>