Sadism

(This problem was inspired by a nice sketch of a 2014 Christmas theater play at FME )

Consider nn persons and mm activities. For every person, we know the activities where he or she excels. Print all the ways to assign one activity to each person. All people must excel in their assigned activities, and no activity can be assigned more than once.

Input

Input consists in several cases. Every case begins with nn and the names of the nn persons in alphabetical order. Follow mm, and the names of the mm activities in alphabetical order. Finally, we have a matrix n×mn \times m, where at the column jj of the row ii we have a 1 if person ii excels in jj, and we have a 0 otherwise. You can assume 1nm101 \le n \le m \le 10, and that there are no repeated words.

Output

For each case, print all the possible assignments. Inside every combination, persons must be sorted alphabetically. Combinations must be sorted lexicographically by activity. Print a line with 20 dots at the end of every combination, and a line with 30 dashes at the end of every case.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:31:23.733Z

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