#C8642. Library Borrowing System

    ID: 52647 Type: Default 1000ms 256MiB

Library Borrowing System

Library Borrowing System

You are tasked with designing a simplified library system that manages book borrowing and returning operations. In this system, each book is identified by its International Standard Book Number (ISBN) and can only be borrowed by one user at a time. The operations are given in the following format:

\(\texttt{BORROW\ userName\ ISBN}\)

\(\texttt{RETURN\ userName\ ISBN}\)

If a user attempts to borrow a book that is already borrowed by another user, the system should return an error message in the format: \(\texttt{ISBN already borrowed by another user}\). Similarly, a return operation only succeeds if the book is currently borrowed by the user performing the return. In all other cases, the transaction is simply ignored (i.e. no output is produced for that transaction).

Your program should process each transaction in the order provided and output the appropriate result for each valid operation.

inputFormat

The first line contains a single integer \(T\) (\(1 \leq T \leq 10^5\)), representing the number of transactions. Each of the following \(T\) lines contains a transaction in one of the following forms: \(\texttt{BORROW userName ISBN}\) or \(\texttt{RETURN userName ISBN}\). The fields in each transaction are space-separated.

outputFormat

For each transaction that produces a result, output the corresponding message on a new line, in the same order as the transactions are processed. The expected messages are:

  • \(\texttt{userName borrowed ISBN}\) — when a borrow operation is successful.
  • \(\texttt{ISBN already borrowed by another user}\) — when an attempt is made to borrow an already borrowed book.
  • \(\texttt{userName returned ISBN}\) — when a return operation is successful.
## sample
6
BORROW Alice 123
BORROW Bob 456
BORROW Alice 456
RETURN Bob 456
BORROW Alice 456
RETURN Alice 123
Alice borrowed 123

Bob borrowed 456 456 already borrowed by another user Bob returned 456 Alice borrowed 456 Alice returned 123

</p>