#C1262. Book Shelf Search

    ID: 42067 Type: Default 1000ms 256MiB

Book Shelf Search

You are given several bookshelves, where each shelf contains a sorted list of unique book codes. For a given series of queries, determine on which shelf a specific book code is located. If the code is not present on any shelf, output "Not Found".

Formally, let there be nn shelves and each shelf ii contains a sorted list AiA_i of book codes. For each query code qq, find an index ii (with 1in1 \leq i \leq n) such that qAiq \in A_i. If no such shelf exists, output (\text{Not Found}).

inputFormat

The input is given via standard input in the following format:

  • The first line contains an integer nn, the number of shelves.
  • The next nn lines each describe a shelf. Each of these lines starts with an integer kk, the number of books on the shelf, followed by kk integers representing the sorted book codes on that shelf.
  • The next line contains an integer qq, the number of queries.
  • The last line contains qq integers, each representing a query book code.

Note: If n=0n = 0, then there are no shelf lines.

outputFormat

For each query, print the 1-indexed shelf number in which the book code is found. If the book code isn’t present in any shelf, print "Not Found". Each answer should be printed on a new line.## sample

3
5 10 20 30 40 50
5 60 70 80 90 100
5 110 120 130 140 150
2
40 85
1

Not Found

</p>