#P9173. Replace and Order

    ID: 22329 Type: Default 1000ms 256MiB

Replace and Order

Replace and Order

Given two binary arrays of lengths \(n\) and \(m\) respectively, your task is to replace each \(0\) and \(1\) with an even and odd positive integer respectively so that, after replacement, each array is strictly increasing and every element is greater than 0. In addition, each positive integer may be used at most once across both arrays and the maximum number used should be as small as possible.

In other words, if an element is \(0\) it must be replaced by an even number, and if it is \(1\) it must be replaced by an odd number. Moreover, if an array is transformed into \(a_1, a_2, \ldots, a_k\) then \(a_1 < a_2 < \cdots < a_k\) must hold. All formulas are given in \(\LaTeX\) format.

inputFormat

The first line contains two integers \(n\) and \(m\) --- the lengths of the two arrays.

The second line contains \(n\) space‐separated integers, each being either 0 or 1, representing the first array.

The third line contains \(m\) space‐separated integers, each being either 0 or 1, representing the second array.

outputFormat

Output two lines:

The first line contains \(n\) space‐separated positive integers denoting the replaced first array.

The second line contains \(m\) space‐separated positive integers denoting the replaced second array.

sample

2 2
1 0
0 1
1 4

2 3

</p>