An educational institute developed a educational program. It offers several courses and students are required to take a certain number of these courses. Each course publishes its schedule of lectures on a day-wise basis, i.e., it publishes the days of the week on which it holds lectures. Each course chooses exactly three days of the week for lectures. Travelling to the institute is a nuisance and all the students who attend courses there, seek to minimise the number of days that they should have to travel. Given each course’s schedule, you have to help the students decide on a combination of courses, such that they minimise the number of days that they have to travel to the institute.
The institute has strict attendance norms and it insists that students should attend all the lectures that their respective course offers.
Assume that the number of courses required will never be greater than the number of courses offered. In addition, there will be a unique combination of days, which allows the students to take the required number of courses and minimise travel.
Input specification:
First line will contain total number of courses (T) and the number of courses you are required to register ® for.
The next T lines will each contain name of the course and those days on which the lectures for the course are held. The first word on each line is the name of the course and the rest of the words are three-letter words signifying the days of the week. E.g., “OOPJ MON WED FRI”.
Output specification:
You should output the names of the days on which the student is required to go to the institute to attend lectures. These should be printed on a single line in sorted order (SUN to SAT) with a single whitespace as a separator. Terminate the output with a newline.
Sample Input and Output:
Input:
6 3
OOPJ MON WED TUE
DSAL TUE WED THU
PCCP WED SAT THU
COOS MON FRI WED
DBMS TUE WED FRI
CNET MON THU FRI
Output:
MON TUE WED FRI
Input:
6 2
OOPJ SUN TUE WED
DSAL TUE WED THU
PCCP THU WED FRI
COOS MON WED FRI
DBMS THU TUE WED
CNET FRI MON THU
Output:
TUE WED THU