Keyboard Consensus
Time limit3sMemory limit512 MB
Kolya and Kostya alternately delete keyboards, each minimizing the survivor's rank in their own list; find the survivor and Kolya's optimal first deletions.
- Level
Medium6 of 10
- Topics
- Game theory, Greedy, Simulation
- Solved
- No attempts yet
Problem
Famous young programmers Kolya and Kostya are preparing for an upcoming team contest. They must pick a keyboard that both of them are comfortable with. To reach a consensus, they use the following procedure.
There are keyboards numbered from to . At first, the candidate set contains all keyboards. The programmers take turns, and Kolya goes first. On a turn, the programmer removes one keyboard from the set. The last keyboard remaining in the set is chosen for the contest.
Each programmer has a list of all keyboards, sorted from the one he likes most to the one he likes least. Both Kolya and Kostya want to minimize the position of the chosen keyboard in their own list. Each of them knows the other's list.
Find the keyboard that is chosen when both programmers play optimally. Also find all optimal first moves for Kolya, meaning the keyboards he can remove on his first turn to guarantee the best possible result for himself.
Input
The first line contains an integer (), the number of keyboards. The second line contains distinct integers from to , Kolya's list from the most liked to the least liked. The third line contains Kostya's list in the same format.
Output
Print the number of the chosen keyboard on the first line. On the second line, print the number of optimal first moves for Kolya. On the third line, print these moves in increasing order.
Hint
In the first example, Kolya removes keyboards 4 and 5 in either order, and Kostya removes keyboards 1 and 2 in either order. Keyboard 3 is therefore chosen.
In the second example, both like keyboard 1 most, so they remove all other keyboards in any order.
In the third example, the only optimal move for Kolya is to remove keyboard 1. Kostya then chooses between keyboards 2 and 3. Keyboard 3 is better for him, so he removes keyboard 2.
In the fourth example, a search through all possible moves shows that Kolya cannot force keyboard 4 to be chosen. The answer is 1.