Group of Interest

The UPF Hacklab offers students a space where they can share knowledge
to develop interests and skills in a multidisciplinary way. But each
time an interest group is created, all members of Hacklab receive an
email, spamming students who are not part of the interest group.

In order to automatize the mailing process, Alice has decided to create
a repository of students together with their interests.

Input

The input consists of several test cases. Each test case starts with an
integer N ≤ 500 of students. The following N lines contain the name of
each student, the number of topics 1 ≤ I_(n) ≤ 10 he or she is
interested in and the corresponding names of the topics.

Then, an integer M ≤ 500 of meetings will take place in the Hacklab.
Each meeting will start with the word “Union” or “Intersection”,
followed by the number of topics 1 ≤ T ≤ 10 and the name of each topic.
“Union” means that all students interested in any of the T topics are
invited, while “Intersection” means that only students interested in all
T topics are invited.

Output

For each test case, output the number of students we have to send email
to and their respective names in lexicographical order.

Problem information

Author: Javier Segovia

Generation: 2026-01-25T13:55:12.869Z

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