bio
The population of planet Algorithm is threatened by extremely dangerous viruses. Fortunately, the planet's biologists have managed to analyze the genetic structure of the viruses and to obtain a complete description of the way they evolve. As such, the nucleotides that make up the DNA structure of a virus can be written using digits 0 to 9 (0,1,2,3,4,5,6,7,8,9). Of these, some are adult and cannot evolve any more (cannot be transformed) while others are still young and can evolve (can be further transformed into other nucleotides). The virus' structure is represented by a sequence of digits (nucleotides), read from left to right.
The evolution consits in a series of steps, and each of these can be formally described as follows: a young nucleotide transforms into (is replaced by) two other nucleotides or transforms into (is replaced by) an adult nucleotide. These transformations are determined by some known rules, of the form: "C transforms into X Y" or "C transforms into X"; these rules can translate as follows: in the sequence of digits that represents the virus' structure, the nucleotide C is erased and in its place the nucleotides XY are inserted (in this order, X to the left of Y), and respectively replaced by the nucleotide X. It has been observed that a sequence of digits represents the structure of a virus if and only if it can be obtained by successively applying the evolution rules on the nucleotide 0; any other sequence of digits represents a different organism. It is also known that a virus whose DNA structure contains only adult nucleotides is less dangerous than a virus whose DNA structure contains young nucleotides.
Task
Being given the list of nucleotides considered as adult, the rules of evolution and a sequence representing the DNA structure of an organism, the task is to state whether that sequence can represent the structure of a virus, in which case you should mention whether it is comprised only of adult nucleotides or also has in its composition young nucleotides.
Input Data
The input file contains on
line one a positive integer m
representing the number of young nucleotides. Line two contains a row of m digits each separated by a space, c1, c2, ..., cm, representing the digits that identify young nucleotides.
Line three contains a positive integer n representing the number of
rules of evolution that are to be described in the file. Each of the following n lines contains a triplet in the
following form
c11
c12 c13
c21 c22 c23
...
cn1 cn2 cn3
If rule j is of the first type (i.e. a young nucleotide can transform into two other nucleotides) then all three values, cj1, cj2 and cj3 are digits that represent nucleotides, with the meaning that nucleotide cj1 transforms into nucleotides cj2 and cj3. If rule j is of the second type (i.e. a young nucleotide can transform into a specific adult nucleotide) then cj1 and cj2 are digits representing nucleotides (with the meaning that nucleotide cj1 transforms into adult nucleotide cj2), and cj3 is –1. The three numbers of each triplet are separated by a space.
The following line of the input file contains a positive integer k that represents the number of organisms whose structures must be analyzed. The following k lines contain k sequences of digits, each on another new line; the k sequences represent the structures of k organisms.
Output Data
For each of the k sequences of the input file a new "not a virus" message (if the respective sequence doesn't represent the structure of a virus), "an adult virus" message (if the respective row represents the structure of an adult virus), or "a young virus" message (if the respective row represents the structure of a virus containing young nucleotides) must be displayed.
Restrictions and Mentions
Example
bio.in |
bio.out |
bio.in |
bio.out |
3 |
an adult virus |
4 |
an
adult virus |
Time limit: 0.4 seconds/test
prep. Florin Manea
University of Bucharest, Mathematics and Computer Science Faculty
Contact: flmanea@gmail.com