Codeforces Round 976 (Div. 2) and Divide By Zero 9.0
C
Bitwise Balancing
Codeforces
1400
原题
← BD →
翻译中…

You are given three non-negative integers $b$, $c$, and $d$.

翻译中…

Please find a non-negative integer $a \in [0, 2^{61}]$ such that $(a\, |\, b)-(a\, \&\, c)=d$, where $|$ and $\&$ denote the bitwise OR operation and the bitwise AND operation, respectively.

翻译中…

If such an $a$ exists, print its value. If there is no solution, print a single integer $-1$. If there are multiple solutions, print any of them.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows.

翻译中…

The only line of each test case contains three positive integers $b$, $c$, and $d$ ($0 \le b, c, d \le 10^{18}$).

翻译中…

Output

翻译中…

For each test case, output the value of $a$, or $-1$ if there is no solution. Please note that $a$ must be non-negative and cannot exceed $2^{61}$.

翻译中…

Note

翻译中…

In the first test case, $(0\,|\,2)-(0\,\&\,2)=2-0=2$. So, $a = 0$ is a correct answer.

翻译中…

In the second test case, no value of $a$ satisfies the equation.

翻译中…

In the third test case, $(12\,|\,10)-(12\,\&\,2)=14-0=14$. So, $a = 12$ is a correct answer.

翻译中…

样例

Input #1
3
2 2 2
4 2 6
10 2 14
Output #1
0
-1
12
InputCopy OutputCopy
题目信息
题号
2020C
时间限制
2 s
内存限制
256 MB
标签
位运算
哈希
模拟
数学
调度
三分

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。