#P4574. Minimize Rearranged Binary Sum

    ID: 17820 Type: Default 1000ms 256MiB

Minimize Rearranged Binary Sum

Minimize Rearranged Binary Sum

Given three integers \(a, b, c\), first convert each into its binary representation without any leading zero. For example, if \(a=7, b=6, c=9\) then their binary forms are: \(a=111\), \(b=110\), and \(c=1001\).

Next, pad the binary strings with leading zeros so that all three have the same length \(L\) (where \(L\) is the maximum length among the three binary strings). For the example, after padding we have \(a=0111\), \(b=0110\), and \(c=1001\).

Then, independently rearrange (i.e. permute) the digits (bits) of each padded binary string to obtain new numbers \(a'\), \(b'\), \(c'\) such that the equation \(a'+b'=c'\) holds, where the binary addition is performed in the usual way with carry propagation.

Your task is to choose rearrangements so that \(c'\) is minimized (when interpreted as a binary number with exactly \(L\) digits). If no valid rearrangement exists, output -1.

Note: The rearrangements for \(a\) and \(b\) can be chosen arbitrarily among all binary strings having exactly the same number of ones as the padded original. The number \(c'\) obtained by the addition must, as a padded binary string, have exactly the same number of ones as the padded binary representation of \(c\).

All formulas are shown in \(\LaTeX\) format.

inputFormat

The input consists of three integers \(a, b, c\) separated by spaces.

outputFormat

Output the minimized rearranged binary string \(c'\) (of length \(L\)). If no valid rearrangement exists, output -1.

sample

7 6 9
1010