#K13086. Library System Genre Distribution

    ID: 23834 Type: Default 1000ms 256MiB

Library System Genre Distribution

Library System Genre Distribution

You are given a simulation of a library system that handles book borrowing and returning. Books are associated with a genre, and the system maintains the count of books in each genre currently available on the shelves.

The system accepts a series of operations given via standard input (stdin). Each operation is provided on its own line. The operations have the following formats:

  • BORROW book_id genre – A book with identifier book_id and genre genre is borrowed from the library. If the book is not already borrowed, it is added.
  • RETURN book_id genre – A book with identifier book_id and genre genre is returned to the library. If the book is currently borrowed, it is removed.
  • QUERY – The system should output the current genre distribution. The output consists of one or more lines; each line is of the form genre:count. The genres must be listed in lexicographical order. If no books are available, output EMPTY.
  • STOP – Indicates the end of the input. No further operations are processed.

Note: When a query operation results in multiple lines of output, preserve the newline characters as described in the specification.

Formula Note: If you need to refer to any formula (e.g., sorting lexicographically), use \(\text{sort}(\cdot)\) for clarification in \(\LaTeX\) format.

inputFormat

The input is provided via standard input (stdin). Each line contains an operation as described above. The input stops processing when a line with STOP is read.

outputFormat

For each QUERY operation, output the current distribution of genres on a new line. If the distribution contains multiple genres, output each genre:count pair on separate lines (in lexicographical order) without additional spaces. If there are no books available at the time of the query, output EMPTY.

## sample
BORROW 1 Fiction
QUERY
STOP
Fiction:1