Permutation Magic
Time limit2sMemory limit1024 MB
Apply a permutation of 1 to M to sequence A so it matches B in the most positions, and output the lexicographically smallest such result.
Problem
There are sequences and with the same length . is the -th element of , and its value is an integer between and . The same holds for , the -th element of .
You can apply a magic trick to exactly once. Prepare a permutation of the integers from through , and change into by setting ().
You want to be closer to after the trick. The distance between two sequences is the Hamming distance, which is the number of positions where the corresponding values differ.
Among all possible , find a sequence that satisfies both of the following conditions.
- No other possible has a smaller distance to than this sequence.
- Among the possible sequences with that same distance to , it is the lexicographically smallest.
A sequence is lexicographically smaller than if there is an index such that for all and .
Input
The input is given in the following format.
The first line contains two integers () and (). Each sequence has values between and .
The second line contains integers, where the -th integer is ().
The third line contains integers, where the -th integer is ().
Output
Print integers separated by spaces. The -th integer is the -th element of a sequence that satisfies all the conditions above. Print each element as an integer.