Library

Simulate the behavior of the loans of books of a library. According to their theme, there are nn different types of books (1,2,,n1, 2, \dots, n). Initially, we have nn stacks with the available books of each type. Afterwards, two different requests may happen:

Input

Input starts with the number of types nn (a strictly positive natural number). Follow nn lines with the books of each type, given from the bottom of the stack up to the top. Each book is identified with its title (a word). Follows an empty line, and one or more requests, one per line: the word “RETURN” followed by the title and the type (an integer) of the returned book, or the word “LOAN” followed by the type of the asked book (an integer).

Output

Print the content of the nn stacks of books, from the bottom of the stack up to its top, following the format of the example.

Observation

The test cases are such that the final stacks are small enough to be printed by a simple recursive procedure, if the case that you program in C++ and you use stack’s.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:15:28.511Z

© Jutge.org, 2006–2026.
https://jutge.org