cho.sh
Notes
Loading...

Graduation

Time limit

2s

Memory limit

128 MB

Problem

Sejun is an academic counselor at Hyungtaek University. Graduation requirements differ from student to student, and a student must satisfy all of their requirements. Each requirement has a form such as “take 2 courses among courses 1, 2, 3, and 4.”

The graduation rules have changed: a course used to satisfy one requirement cannot be used again for another requirement. In other words, each course can be assigned to at most one graduation requirement.

You are given the courses Jungmoon has already taken and the graduation requirements. Find the minimum number of additional courses Jungmoon must take to graduate, and output which course numbers should be taken.

Each course is represented by one integer from 1 to 100.

Input

The first line contains M, the number of courses Jungmoon has already taken. M is between 0 and 100, inclusive.

The second line contains the course numbers Jungmoon has already taken, separated by spaces. If M is 0, this line is empty.

The third line contains N, the number of graduation requirements. N is between 1 and 100, inclusive.

Each of the next N lines describes one graduation requirement. The first number is how many courses are needed to satisfy that requirement, and the second number is how many courses appear in that requirement. The remaining numbers are the course numbers in the requirement.

For example, “take 2 courses among courses 1, 2, 3, and 4” is given as 2 4 1 2 3 4. The first two numbers on each requirement line are positive integers not greater than 100. No two graduation requirements are identical.

Output

On the first line, print the minimum number of additional courses Jungmoon must take.

On the second line, print the additional course numbers separated by spaces. If there are multiple answers with the minimum number of courses, print the lexicographically smallest sequence. A course cannot be taken more than once.

If graduation is impossible no matter what courses are taken, print -1 on the first line.

Hint

The already completed course 1 can be used for only one requirement. Assign course 2 with it for one requirement, and assign courses 3 and 4 to the other requirement to satisfy all requirements.