Nine Judges
Time limit2sMemory limit512 MB
Given n preference lists over k problems, output a p-subset that a random majority-driven swap process can return to infinitely often.
Problem
There are problems proposed for the contest, and exactly of them must be chosen for the final problem set.
The problems have been evaluated by judges. Each judge has built their own preference list containing all the proposed problems, in order from the problem they like the most to the problem they like the least.
The XCPC finals are still far away, and nobody knows whether they will be held at all. The actual problem set is therefore chosen by an infinite procedure.
Initially, and contains problems chosen uniformly at random from the proposed problems. Then the following actions are repeated indefinitely:
- Choose problems and uniformly at random such that and .
- If at least judges have put before in their preference list, let . Otherwise, let .
- Increase by one.
A problem set is called plausible if there exists a positive probability threshold such that there are infinitely many moments when the probability of is more than . In formal notation:
is plausible
Input
The first line contains three integers , , and (; is odd; ), the number of judges, the number of proposed problems, and the number of problems to choose.
Each of the following lines contains integers (, all values in a line are distinct). Here is the problem the -th judge likes the most, is the second most liked, and so on.
Output
Print distinct integers between 1 and in any order, denoting any plausible problem set.
Hint
In the example test case, some other possible answers are 1 2 5 and 2 4 5.