Ainta, Binta, and Cinta
Time limit1.5sMemory limit1024 MB
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.
Problem
Ainta, Binta, and Cinta each have a sequence of length . Ainta's sequence is , Binta's sequence is , and Cinta's sequence is .
Bored, Ainta decides to play a strange trick on Binta's sequence. Ainta can pick an index and overwrite with . This is an overwrite, not a swap, so is replaced by and 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 with does not require doing the same to .
The next day, Binta and Cinta each sort their sequence and remove all duplicate elements. For example, if , sorting gives , and removing duplicates gives . If the two resulting sequences are identical, Binta and Cinta are so moved that they cry for hours, where is the length of the sequence after duplicates are removed.
Ainta wants to move them as much as possible, so Ainta wants to maximize . Output the maximum possible 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 always exists.
Input
The first line contains the length of the sequences ().
The second line contains ().
The third line contains ().
The fourth line contains ().
Output
On the first line, print the maximum possible .
On the second line, print the integers of the sequence that Binta and Cinta end up with. If there are several valid answers, print any one of them.