#K85577. Track Book Transactions

    ID: 36672 Type: Default 1000ms 256MiB

Track Book Transactions

Track Book Transactions

You are given a series of book transactions. Each transaction is one of two types: borrowing or returning a book. A transaction is represented by three values:

  • A character 'B' or 'R' indicating Borrow or Return respectively,
  • An integer book_id, and
  • An integer transaction_time (provided for information, transactions are in order of occurrence).

Your task is to compute the final status of each book after processing all transactions. If the last transaction for a book is a borrow 'B', then the book is Borrowed. If the last transaction is a return 'R', then the book is Available.

Note: The output must display the final status of each book sorted by the book ID in ascending order.

Mathematically, if we denote the status of a book i after transaction j by \( S_{i,j} \), then the update rule can be expressed as:

[ S_{i,j} = \begin{cases} \text{Borrowed} & \text{if transaction } j \text{ is } 'B', \ \text{Available} & \text{if transaction } j \text{ is } 'R'. \end{cases} ]

After all transactions, output the final state \( S_{i,\text{final}} \) for each book i in separate lines as book_id status.

inputFormat

The input is read from stdin and its format is as follows:

  1. An integer n representing the number of transactions.
  2. n lines follow, each containing three space-separated values:
    • A character 'B' or 'R' indicating a borrow or return transaction.
    • An integer book_id.
    • An integer transaction_time (the transactions are provided in chronological order).

outputFormat

Write the output to stdout where each line contains the book_id and its final status (either Borrowed or Available), separated by a space. The books should be output in ascending order of book_id.

## sample
4
B 1 5
B 2 6
R 1 8
B 1 10
1 Borrowed

2 Available

</p>