P4574 [CQOI2013] Binary A+B

Description

You are given three integers $a, b, c$ and write them as binary integers without leading zeros. For example, when $a=7, b=6, c=9$, their binary forms are $a=(111)_2, b=(110)_2, c=(1001)_2$. Next, pad the shorter ones with leading zeros so that $a, b, c$ have the same number of bits as the longest one. In the example above, after padding we get $a=(0111)_2, b=(0110)_2, c=(1001)_2$. Finally, rearrange the bits of $a, b, c$ to obtain $a', b', c'$ such that $a' + b' = c'$. In the example above, one possible rearrangement is $a'=(0111)_2, b'=(0011)_2, c'=(1010)_2$. Your task is to make $c'$ as small as possible. If there is no solution, output $-1$.

Input Format

The input contains a single line with three integers $a, b, c$.

Output Format

Output a single line with the minimum value of $c'$.

Explanation/Hint

For all testdata, $a,b,c \le 2^{30}$. Translated by ChatGPT 5