Drug interactions

Write a program that loads a list of drug interactions, and then allows the user to query it.

The input has two parts: data and queries.

The data part consists of an integer nn indicating how many drug-effect-drug triplets are to be read. Then, there are nn lines, each with a drug name, an effect, and another drug name. The drugs names and effect types are not constrained to a limited list.

After the nn data lines comes the query part. Here, a line may consists of a drug name and an effect followed by a question mark, or a question mark followed by an effect and a drug name. In the former case, the program must print all the drugs that are affected by the given one with the given effect. On the latter case, the program reports the drugs that have the given effect on the given drug

Input

The input consits of a number n0n\ge{0}, followed by nn triplets drug-effect-drug. After that, there is a sequence of queries, each of them consisting of a question mark and effect and a drug, or a drug, and effect and a question mark.

Output

For each query the list of drugs answering the query, alphabetically sorted. If no drugs are found for the given query, the program prints "not found"

Problem information

Author: Lluís Padró

Generation: 2026-01-25T13:08:56.677Z

© Jutge.org, 2006–2026.
https://jutge.org