Under construction

Still being built. Things may change

Keyboard Consensus

Time limit3sMemory limit512 MB

Summary
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 nn keyboards numbered from 11 to nn. At first, the candidate set contains all nn 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 nn 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 nn (2≤n≤1002 \le n \le 100), the number of keyboards. The second line contains nn distinct integers from 11 to nn, 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.

Examples4

  1. Example 1

    Input
    5
    1 2 3 4 5
    5 4 3 2 1
    
    Expected output
    3
    2
    4 5
    
  2. Example 2

    Input
    4
    1 2 3 4
    1 3 2 4
    
    Expected output
    1
    3
    2 3 4
    
  3. Example 3

    Input
    3
    3 1 2
    1 3 2
    
    Expected output
    3
    1
    1
    
  4. Example 4

    Input
    4
    4 1 3 2
    1 3 4 2
    
    Expected output
    1
    3
    2 3 4