Under construction

Still being built. Things may change

Ainta, Binta, and Cinta

Time limit1.5sMemory limit1024 MB

Summary
Ainta overwrites cells of B and C with values from A so that both sorted, deduplicated sequences match, maximizing their length k and printing one such sequence.
Level

Medium7 of 10

Topics
Graph, Hash map
Solved
No attempts yet

Problem

Ainta, Binta, and Cinta each have a sequence of length nn. Ainta's sequence is A1,A2,…,AnA_1, A_2, \ldots, A_n, Binta's sequence is B1,B2,…,BnB_1, B_2, \ldots, B_n, and Cinta's sequence is C1,C2,…,CnC_1, C_2, \ldots, C_n.

Bored, Ainta decides to play a strange trick on Binta's sequence. Ainta can pick an index 1≤i≤n1 \le i \le n and overwrite BiB_i with AiA_i. This is an overwrite, not a swap, so BiB_i is replaced by AiA_i and AiA_i stays the same. Ainta may perform this operation any number of times, including zero.

Ainta plays the same kind of trick on Cinta's sequence. This trick is independent of the one on Binta's sequence. For example, overwriting B1B_1 with A1A_1 does not require doing the same to C1C_1.

The next day, Binta and Cinta each sort their sequence and remove all duplicate elements. For example, if B=[3,2,1,3,2]B = [3, 2, 1, 3, 2], sorting gives [1,2,2,3,3][1, 2, 2, 3, 3], and removing duplicates gives [1,2,3][1, 2, 3]. If the two resulting sequences are identical, Binta and Cinta are so moved that they cry for kk hours, where kk is the length of the sequence after duplicates are removed.

Ainta wants to move them as much as possible, so Ainta wants to maximize kk. Output the maximum possible kk and one sequence that achieves it. The output sequence is the one Binta and Cinta end up with after removing duplicates. It is guaranteed that a solution with k>0k > 0 always exists.

Input

The first line contains the length nn of the sequences (1≤n≤5 0001 \le n \le 5\,000).

The second line contains A1,A2,…,AnA_1, A_2, \ldots, A_n (1≤Ai≤10 0001 \le A_i \le 10\,000).

The third line contains B1,B2,…,BnB_1, B_2, \ldots, B_n (1≤Bi≤10 0001 \le B_i \le 10\,000).

The fourth line contains C1,C2,…,CnC_1, C_2, \ldots, C_n (1≤Ci≤10 0001 \le C_i \le 10\,000).

Output

On the first line, print the maximum possible kk.

On the second line, print the kk integers of the sequence that Binta and Cinta end up with. If there are several valid answers, print any one of them.

Examples1

  1. Example 1

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