Hide

Problem G
Guaranteed Victory

/problems/guaranteedvictory/file/statement/en/img-0001.jpeg
Curtis’s blueprint

Curtis is challenging Porco Rosso to a duel again. Curtis has a new plan: this time, he is going to make the perfect airplane. He has devised a list of $R$ blueprints. Blueprints indicate the resources required to create a unique resultant airplane part. These airplane parts can also be used as resources in other blueprints. In his plans to beat Porco, Curtis has access to an infinite supply of $N$ resources.

With his original blueprints, Curtis can create any airplane part described by those blueprints; however, there’s a problem. Somewhere in his blueprints, Fio has tampered with one blueprint by listing an additional resource. Curtis has been going in circles trying to determine which blueprints are affected by this additional resource. However, he realizes that he still might be able to create all of his airplane parts.

As Curtis’s mechanic, your job is to figure out what Fio has sabotaged. You are already certain that Fio has added exactly one resource to exactly one blueprint. Because Fio is sneaky, she chose an existing resource to add. If Curtis can still create his airplane, tell Curtis that he is ready to beat Porco. Otherwise, tell Curtis how many parts he can no longer create.

Input

The first line of input is two space-separated integers $N$ and $R \: (1 \leq N,R \leq 500)$, representing the number of resources and number of blueprints, respectively.

The next $N$ lines are resources. Each of these lines contains a single string, representing a resource. Each string contains only lowercase letters, numbers, and hyphens. Resources are unique.

The next $R$ pairs of lines are blueprints. The first line in a pair contains the number of space-separated strings $R_i$. The second line in this pair contains $R_i$ space-separated strings. The first string of this line is the resultant airplane part for the blueprint. The rest of the strings contain the resources necessary to build that part. All blueprints require at least one resource.

It is guaranteed that $\sum {R_i} \leq 500\, 000$. All strings in the input are guaranteed to either be a resource or a result of a blueprint. Any string in the input consists only of lowercase letters $a-z$, numerical digits $0-9$, and the hyphen character $-$. Moreover, the length of each string does not exceed $36$ characters.

Output

If Curtis can still create his airplane, output one line containing the string "GUARANTEED VICTORY" (not including the quotes). Otherwise, output one line containing the number of airplane parts Curtis cannot create.

Sample Input 1 Sample Output 1
4 3
wrench
monkey
steel
engine
3
propeller steel monkey
3
monkeywrench monkey wrench
5
airplane propeller monkeywrench engine steel
GUARANTEED VICTORY
Sample Input 2 Sample Output 2
1 2
life
3
chicken life egg
3
egg chicken life
2

Please log in to submit a solution to this problem

Log in