#K81957. Library Manager

    ID: 35868 Type: Default 1000ms 256MiB

Library Manager

Library Manager

You are given a series of library management queries. The library system processes three types of commands:

  • borrow x y: Member x tries to borrow book y. If the book is not currently borrowed, the borrowing succeeds and the book becomes associated with member x; otherwise, the command is ignored.
  • return x y: Member x returns book y if and only if member x is currently borrowing book y. Otherwise, the command is ignored.
  • status y: Check the status of book y. If the book is currently borrowed, output the member id; if not, output "available".

All queries must be processed sequentially. For every status query, print the result on a new line.

Mathematically, if we denote by \(B(y)\) the status of book \(y\), then the commands update the state as follows:

  • \(\text{if } B(y) \text{ is undefined, then } borrow(x, y) \Rightarrow B(y)=x\)
  • \(return(x, y)\) is effective only if \(B(y)=x\), in which case \(B(y)\) becomes undefined.
  • \(status(y)=\begin{cases} x & \text{if } B(y)=x, \\ \text{available} & \text{if } B(y) \text{ is undefined} \end{cases}\)

inputFormat

The first line of input contains an integer \(n\) representing the number of queries.

The next \(n\) lines each contain a query. Each query is in one of the three forms:

  • borrow x y
  • return x y
  • status y

Here, x and y are positive integers.

outputFormat

For each status query in the input, output the response on a new line. The response is either the member id (as an integer) who has currently borrowed the book, or "available" if the book is not borrowed.

## sample
7
borrow 1 100
status 100
borrow 2 100
status 100
return 1 100
borrow 2 100
status 100
1

1 2

</p>