#K78287. Library Command Processing

    ID: 35053 Type: Default 1000ms 256MiB

Library Command Processing

Library Command Processing

You are given a sequence of commands to manage a library's inventory. The library supports three operations: ADD, BORROW, and RETURN.

Commands Format:

  • ADD <book_title> <count> - Add the specified number of copies of a book to the library.
  • BORROW <book_title> - Borrow a book if at least one copy is available. If the book is not available, output Book not available.
  • RETURN <book_title> - Return a previously borrowed book. If no copy is borrowed, output All copies are already in the library.

For each BORROW and RETURN command, output the result on a new line. All input is given via stdin and all output should be sent to stdout.

The library keeps track of the total copies added and the number of copies currently borrowed. A borrow operation is successful only if the number of borrowed copies is less than the total copies available, and a return operation is successful only if at least one copy is out on loan.

Note: Any command that does not result in a borrow or return does not produce any output.

inputFormat

The first line contains an integer n representing the number of commands. Each of the following n lines contains a command in one of the formats described above.

outputFormat

For each BORROW and RETURN command, output a line with one of the following messages:

  • Borrow successful
  • Return successful
  • Book not available
  • All copies are already in the library
## sample
3
ADD HarryPotter 5
BORROW HarryPotter
BORROW HarryPotter
Borrow successful

Borrow successful

</p>