#C5754. Library Book Borrowing Simulation

    ID: 49438 Type: Default 1000ms 256MiB

Library Book Borrowing Simulation

Library Book Borrowing Simulation

This problem simulates the managing system for a library's book borrowing process. In this library, each member can borrow at most 5 books at any given time. The operations available are:

  • borrow BookID MemberID - A member attempts to borrow a book. The operation succeeds if the book is not currently borrowed and the member has not reached the borrowing limit. Otherwise, the system returns an appropriate message.
  • return BookID MemberID - A member attempts to return a book. The operation succeeds if the book was borrowed by that member. If the book was not borrowed or was borrowed by another member, an error message is produced.

Formally, let \( c_m \) be the number of books currently borrowed by member \( m \). Then a borrow operation is valid if \[ c_m < 5 \quad \text{and the book is not already borrowed.} \] All operations are processed in the given order.

inputFormat

The first line of input contains an integer n representing the number of operations.

Each of the following n lines contains a command in one of the following formats:

  • borrow BookID MemberID
  • return BookID MemberID

Here, BookID and MemberID are strings identifying the book and the member, respectively.

outputFormat

For each operation, output a single line that is one of the following messages:

  • Success
  • Already borrowed
  • Limit reached
  • Not borrowed
  • Wrong member

The messages indicate the result of processing each operation in order.

## sample
6
borrow Book1 Member1
borrow Book2 Member2
borrow Book1 Member3
return Book1 Member2
borrow Book1 Member1
return Book1 Member1
Success

Success Already borrowed Wrong member Success Success

</p>