description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
def main():
import sys
input = sys.stdin.buffer.readline
u, v = map(int, input().split())
if u > v:
print(-1)
exit()
if u & 1 != v & 1:
print(-1)
exit()
if u == v == 0:
print(0)
exit()
a = 0
b = 0
w = v - u >> 1
for i in range(100):
if w >> i & 1:
if u >> i & 1:
a ^= 1 << i
b ^= 1 << i
else:
a ^= 1 << i
u ^= 1 << i
ans = [u]
if a:
ans.append(a)
if b:
ans.append(b)
print(len(ans))
print(*ans)
main() | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
def compute(S, X):
A = (S - X) // 2
a = 0
b = 0
for i in range(64):
Xi = X & 1 << i
Ai = A & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif Xi > 0 and Ai == 0:
a = 1 << i | a
else:
return [-1, -1]
return [a, b]
Xor, Sum = map(int, sys.stdin.readline().split())
if Xor > Sum or Xor % 2 != Sum % 2:
print(-1)
elif Xor == Sum:
if Sum != 0:
print(1)
print(Xor)
else:
p = compute(Sum, Xor)
if p[0] > 0 and p[1] > 0:
print(2)
print(p[0], p[1])
else:
print(3)
print(Xor, (Sum - Xor) // 2, (Sum - Xor) // 2) | IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER NUMBER RETURN LIST VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | a, b = list(map(int, input().split()))
if a == b and a == 0:
print(0)
elif a == b:
print(1)
print(a)
elif a > b:
print(-1)
elif (b - a) % 2 == 0:
c = (b - a) // 2
if c ^ a == c + a:
print(2)
print(c + a, c)
else:
print(3)
print(c, c, a)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def solve(u, v):
if u > v or (v - u) % 2 == 1:
return None
if u == v == 0:
return []
if u == v:
return [u]
w = (v - u) // 2
if not w & u:
return [w, v - w]
return [u, w, w]
u, v = map(int, input().split())
a = solve(u, v)
if a is None:
print(-1)
else:
print(len(a))
print(*a) | FUNC_DEF IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NONE IF VAR VAR NUMBER RETURN LIST IF VAR VAR RETURN LIST VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR RETURN LIST VAR BIN_OP VAR VAR RETURN LIST VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v:
print(-1)
elif u == v and u == 0:
print(0)
elif u == v:
print(1)
print(u)
elif u % 2 == 0 and v % 2 != 0 or u % 2 != 0 and v % 2 == 0:
print(-1)
elif u == 1:
print(v)
for i in range(v):
print(1, end=" ")
print()
else:
a = (v - u) // 2
b = (v - u) // 2 + u
if a ^ b == u:
print(2)
print(a, b)
else:
print(3)
print(u, a, a) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
u, v = map(int, input().split())
if u > v:
print(-1)
sys.exit(0)
if u == v and u == 0:
print(0)
sys.exit(0)
if u == v:
print(1)
print(u)
sys.exit(0)
if (v - u) % 2 == 1:
print(-1)
sys.exit(0)
ans = [0] * 64
ans[0] = u
v -= u
for i in range(65, -1, -1):
if u & 1 << i:
j = 63
while (1 << i) * (j - 1) > v:
j -= 2
v -= (1 << i) * (j - 1)
for k in range(1, j):
ans[k] += 1 << i
else:
j = 64
while (1 << i) * j > v:
j -= 2
v -= (1 << i) * j
for k in range(j):
ans[k] += 1 << i
if v != 0:
print(-1)
sys.exit(0)
i = 0
answ = []
while ans[i] != 0:
answ.append(ans[i])
i += 1
print(len(answ))
print(*answ) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
inp = sys.stdin.readline
def input():
return inp().strip()
def iin():
return int(input())
def lin():
return list(map(int, input().split()))
def main():
T = 1
while T:
T -= 1
u, v = lin()
if u > v:
print(-1)
else:
a = []
ch = 0
v -= u
while u:
if u & 1:
a.append(1 << ch)
ch += 1
u >>= 1
if v % 2 == 0:
if v:
a.append(v // 2)
a.append(v // 2)
chg = 1
while chg:
chg = 0
l = len(a)
na = []
done = set()
for i in range(l):
if i in done:
continue
for j in range(i + 1, l):
if j in done:
continue
elif a[i] & a[j] == 0:
chg = 1
na.append(a[i] + a[j])
done.update([i, j])
break
for i in range(l):
if i not in done:
na.append(a[i])
a = na
print(len(a))
print(*a)
else:
print(-1)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR VAR WHILE VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | a, b = list(map(int, input().split()))
if a > b or (b - a) % 2 != 0:
print(-1)
else:
k = b - a
if k == 0:
if a == 0:
print(0)
else:
print(1, "\n" + str(a))
elif a & k // 2 == 0:
print(2)
print(a + k // 2, k // 2)
else:
print(3)
print(a, k // 2, k // 2) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP STRING FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v or u & 1 != v & 1:
print(-1)
elif v == u and u == 0:
print(0)
elif v == u:
print(1)
print(u)
else:
r = (v - u) // 2
if r & u:
print(3)
print(u, r, r)
else:
print(2)
print(u ^ r, r) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def sol():
u, v = map(int, input().split())
if u > v or (u - v) % 2 != 0:
return -1
if u == v:
if u == 0:
return 0
else:
return "1\n%d" % u
x = (v - u) // 2
a, b = 0, 0
i = 1
u_ = u
x_ = x
while u_ or x_:
m, n = u_ % 2, x_ % 2
if n == 1:
if m == 1:
return "3\n{} {} {}".format(u, x, x)
else:
a += i
b += i
elif m == 1:
a += i
u_ //= 2
x_ //= 2
i *= 2
return "2\n%d %d" % (a, b)
print(sol()) | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL STRING VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
A = (v - u) // 2
if A < 0 or (v - u) % 2 != 0:
print(-1)
elif u == 0 and v == 0:
print(0)
else:
a = 0
b = 0
c = 0
for i in range(61):
ui = u & 1 << i
Ai = A & 1 << i
if ui == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif ui > 0 and Ai == 0:
a = 1 << i | a
elif ui > 0 and Ai > 0:
c = 1 << i | c
a = 1 << i | a
b = 1 << i | b
if b == 0:
print(1)
print(a)
elif c == 0:
print(2)
print(a, b)
else:
print(3)
print(a, b, c) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
if u > v or (v - u) % 2:
print("-1")
elif u == v == 0:
print("0\n")
elif u == v:
print("1\n%d" % u)
else:
diff = (v - u) // 2
if diff & u == 0:
print("2\n%d %d" % (u | diff, diff))
else:
print("3\n%d %d %d" % (diff, diff, u)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
if v > u:
if (v - u) % 2 == 0:
b = (v - u) // 2
if (u ^ b) + b == v:
print(2)
print(*[u ^ b, b])
else:
print(3)
print(*[u, b, b])
else:
print(-1)
elif v == u:
if u == 0:
print(0)
else:
print(1)
print(u)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | m, n = [int(i) for i in input().split()]
if m > n or (n - m) % 2 != 0:
print(-1)
else:
rz2 = (n - m) // 2
rz3 = rz2
if n == 0:
print(0)
elif n == m:
print(1)
print(n)
elif m ^ rz2 ^ rz3 == m + rz2 ^ rz3:
print(2)
print(m + rz2, rz3)
else:
print(3)
print(m, rz2, rz3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def compute(x, s):
rem = (s - x) // 2
a, b = 0, 0
for i in range(64):
j = x & 1 << i
k = rem & 1 << i
if j == 0 and k == 0:
pass
elif j == 0 and k > 0:
a = 1 << i | a
b = 1 << i | b
elif j > 0 and k == 0:
a = 1 << i | a
else:
print(3)
print(x, rem, rem)
return
print(2)
print(a, b)
x, s = map(int, input().split())
if x == 0 and s == 0:
print(0)
elif x == s:
print(1)
print(x)
elif x > s or (x - s) % 2 == 1:
print(-1)
else:
compute(x, s) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def solve(x, s):
a = (s - x) // 2
aa, bb = 0, 0
for i in range(0, 64):
ai = 1 << i & a
xi = 1 << i & x
if ai == 0 and xi == 0:
pass
elif ai > 0 and xi == 0:
aa = 1 << i | aa
bb = 1 << i | bb
elif ai == 0 and xi > 0:
aa = 1 << i | aa
else:
return [x, a, a]
return [aa, bb]
x, s = map(int, input().split())
if x == s == 0:
print(0)
elif x == s:
print(1)
print(x)
elif x > s or (s - x) % 2:
print(-1)
else:
ans = solve(x, s)
print(len(ans))
print(*ans) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST VAR VAR VAR RETURN LIST VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def codechef(s, x):
if s == x == 0:
print(0)
elif s == x != 0:
print(1)
print(s)
else:
a = (s - x) // 2
if s - x & 1:
print(-1)
elif a < 0:
print(-1)
elif x & a == 0:
print(2)
print(int(x + a), int(a))
else:
print(3)
print(int(x), int(a), int(a))
x, s = map(int, input().split())
codechef(s, x) | FUNC_DEF IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | n, m = map(int, input().split())
if n > m:
print(-1)
elif n == m:
if n == 0:
print(0)
else:
print(1)
print(n)
elif (m - n) % 2 == 1:
print(-1)
else:
a = n
b = (m - n) // 2
if a ^ b == a + b:
print(2)
print(a ^ b, b)
else:
print(3)
print(a, b, b) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | MX = 64
u, v = map(int, input().split())
cx = list(map(int, reversed(bin(u)[2:])))
cx += [0] * (MX - len(cx))
cs = list(map(int, reversed(bin(v)[2:])))
cs += [0] * (MX - len(cs))
imp = False
for i in reversed(range(MX)):
if cs[i] % 2 == cx[i]:
continue
if i == 0:
imp = True
break
if cx[i] and cs[i] == 0:
for j in range(i + 1, MX):
if cs[j] >= 2:
break
else:
imp = True
break
cs[j] -= 2
for k in range(i + 1, j):
cs[k] += 2
cs[i] += 4
cs[i] -= 1
cs[i - 1] += 2
if imp:
print(-1)
else:
ans = [0] * max(cs)
for i in range(MX):
for j in range(cs[i]):
ans[j] += 2**i
print(len(ans))
print(*ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def two(u, a):
for k in range(70):
if a >> k & 1 and u >> k & 1:
return False
return True
def main():
u, v = MI()
if u > v or v - u & 1:
print(-1)
exit()
elif v == 0:
print(0)
exit()
elif u == v:
ans = [u]
else:
a = v - u >> 1
if two(u, a):
ans = [a, a | u]
else:
ans = [u, (v - u) // 2, (v - u) // 2]
print(len(ans))
print(*ans)
main() | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v or u % 2 != v % 2:
print(-1)
exit()
if u == 0 and v == 0:
print(0)
exit()
if u == v:
print(1)
print(u)
exit()
w = (v - u) // 2
W = format(w, "b")
U = format(u, "b")
L = max(len(W), len(U))
W = "0" * (L - len(W)) + W
U = "0" * (L - len(U)) + U
a, b = 0, 0
for i in range(L):
if W[i] == "1":
if U[i] == "1":
print(3)
print(w, w, u)
break
else:
a += 2 ** (L - 1 - i)
b += 2 ** (L - 1 - i)
elif U[i] == "1":
a += 2 ** (L - 1 - i)
else:
print(2)
print(a, b) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | xor, sm = map(int, input().split())
diff = sm - xor
if diff < 0 or diff % 2:
l = -1
elif xor == sm == 0:
l = 0
elif xor == sm:
l = 1
ans = [sm]
else:
l = 2
for i in range(60):
if xor >> i & diff >> i + 1:
l = 3
ans = [0] * l
for i in range(60):
j = 0
if xor >> i & 1:
ans[j] += 1 << i
j += 1
if diff >> i + 1 & 1:
ans[j] += 1 << i
ans[j + 1] += 1 << i
j += 2
print(l)
if l > 0:
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
def d(v=-1):
print(v)
exit(0)
if u > v:
d()
if u == v:
if u == 0:
d(0)
else:
print(1)
d(u)
bit_u = [0] * 600
bit_v = [0] * 600
for i in range(64):
if 1 << i & u:
bit_u[i] = 1
if 1 << i & v:
bit_v[i] = 1
for i in range(63, 0, -1):
if bit_u[i] == bit_v[i] % 2:
bit_v[i - 1] += bit_v[i] >> 1 << 2
bit_v[i] %= 2
else:
if bit_v[i] == 0:
d()
bit_v[i] -= 1
bit_v[i - 1] += 2
bit_v[i - 1] += bit_v[i] >> 1 << 2
bit_v[i] %= 2
for i in range(500):
up = bit_v[i] >> 2 << 1
bit_v[i + 1] += up
bit_v[i] -= up << 1
n = max(bit_v)
res = [0] * n
for i in range(n):
for j in range(600):
if bit_v[j] > i:
res[i] |= 1 << j
xr, sm = 0, 0
for i in res:
xr ^= i
sm += i
if xr != u or sm != v:
d()
exit(0)
print(n)
print(*res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def main_function():
u, v = list(map(int, input().split(" ")))
if u > v or (v - u) % 2 == 1:
print("-1")
elif (v - u) % 2 == 0:
sup_num = (v - u) // 2
A = [sup_num, u + sup_num]
if A[0] ^ A[1] == u:
if A[0] != 0:
print(2)
else:
print(1 if u != 0 else 0)
A = [u] if u != 0 else []
print(*A)
else:
print(3)
print(sup_num, sup_num, u)
else:
print("ghost or phantom")
main_function() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | for _ in range(1):
u, v = map(int, input().split())
if u == v and u + v != 0:
print(1)
print(u)
elif v < u:
print(-1)
elif (v - u) % 2 == 1:
print(-1)
elif u + v == 0:
print(0)
else:
z = v - u
if z // 2 + u ^ z // 2 == u:
print(2)
print(z // 2 + u, z // 2)
else:
print(3)
print(z // 2, z // 2, u) | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def solve():
u, v = map(int, input().split())
if u > v:
print("-1")
return
if u % 2 != v % 2:
print("-1")
return
if u == 0 and v == 0:
print(0)
return
if u == v:
print(1)
print(u)
return
x = (v - u) // 2
if u & x:
print(3)
print(u, end=" ")
print(x, end=" ")
print(x)
return
print(2)
print(u + x, end=" ")
print(x)
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = sys.stdin.readline
x, s = [int(x) for x in input().split()]
if x > s or x % 2 != s % 2:
print(-1)
exit()
elif x == s:
if x == 0:
print(0)
else:
print(1)
print(x)
exit()
ans1, ans2 = 0, 0
a = (s - x) // 2
if a & x:
print(3)
print(x, a, a)
else:
print(2)
print(x ^ a, a) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | v, u = map(int, input().split())
count = [0] * 100
index = 0
works = True
while u >= 0 and v >= 0 and (v > 0 or u > 0):
u2 = u & 1
v2 = v & 1
if u2 != v2:
u -= 1
if index:
count[index - 1] += 2
else:
works = False
break
elif u2:
u -= 1
v -= 1
count[index] += 1
else:
u >>= 1
v >>= 1
index += 1
if works and u >= 0 and v >= 0:
out = []
for i in range(100):
while len(out) < count[i]:
out.append(0)
for j in range(count[i]):
out[j] ^= 1 << i
print(len(out))
print(" ".join(map(str, out)))
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | x, s = map(int, input().split())
if x == 0 and s == 0:
print(0)
exit()
if x > s:
print(-1)
exit()
if x & 1 != s & 1:
print(-1)
exit()
if x == s:
print(1)
print(x)
exit()
if x == 0:
print(2)
print(s // 2, s // 2)
exit()
b = (s - x) // 2
f = 1
bx = bin(x)[2:]
ba = ""
bb = bin(b)[2:]
while len(bb) < len(bx):
bb = "0" + bb
while len(bx) < len(bb):
bx = "0" + bx
for i in range(len(bx)):
if bb[i] == "1":
ba += "1"
elif bb[i] == "0" and bx[i] == "1":
ba += "1"
else:
ba += "0"
a = int(ba, 2)
if a ^ b == x and a + b == s:
print(2)
print(a, b)
exit()
print(3)
print(x, (s - x) // 2, (s - x) // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
def go():
x, s = map(int, input().split())
if x > s:
return -1
if x == s == 0:
return 0
left = 0
bits = []
for b in range(s.bit_length() - 1, -1, -1):
f = 1 << b
curbit = 0
left = left * 2 + ((s & f) >> b)
cur = (x & f) >> b
if cur > left:
borrow = len(bits) - 1
while borrow >= 0 and bits[borrow] < 2:
borrow -= 1
if borrow < 0:
return -1
bits[borrow] -= 2
for bor in range(borrow + 1, len(bits)):
bits[bor] += 2
left += 4
if cur == 1:
cur -= 1
left -= 1
curbit = 1
curbit += left - left % 2
left = left % 2
bits.append(curbit)
if left:
return -1
vals = []
for i in range(1, max(bits) + 1):
v = 0
for bb in bits:
v = v * 2 + (bb >= i)
vals.append(v)
return str(len(vals)) + "\n" + " ".join(map(str, vals))
t = 1
for _ in range(t):
print(go()) | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = [int(x) for x in input().split()]
if u == v == 0:
print(0)
exit()
if u == v:
print("1\n" + str(u))
exit()
if u > v:
print(-1)
exit()
if (u - v) % 2 == 1:
print(-1)
exit()
a = (v - u) // 2
b = v - a
if a & b != a:
print("3\n" + str(u) + " " + str(a) + " " + str(a))
else:
print("2\n" + str(a) + " " + str(b)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
u, v = [int(v) for v in sys.stdin.readline().split()]
def m():
if (v - u) % 2 == 1:
return None
ar = []
h = (v - u) // 2
if u & h == 0:
ar.append(u | h)
ar.append(h)
else:
ar.append(u)
ar.append(h)
ar.append(h)
return ar
if u > v:
print(-1)
elif u == v:
if u == 0:
print(0)
else:
print(1)
print(u)
else:
ar = m()
if ar is not None:
print(len(ar))
print(" ".join(map(str, ar)))
else:
print(-1) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NONE ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NONE EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin
u, v = map(int, stdin.readline().split())
k = u
if (u - v) % 2 != 0:
print(-1)
exit()
if u == v:
if u == 0:
print(0)
exit()
else:
print(1)
print(u)
exit()
if v < u:
print(-1)
exit()
x = (v - u) // 2
u = [int(z) for z in list(bin(u)[2:][::-1])]
x_b = [int(z) for z in list(bin(x)[2:][::-1])]
l = max(len(u), len(x_b))
u += [0] * (l - len(u))
x_b += [0] * (l - len(x_b))
ans = []
c, d = [], []
for i in range(l):
a, b = u[i], x_b[i]
if a == b == 1:
print(3)
print(k, x, x)
break
elif a == b == 0:
c.append(0)
d.append(0)
elif a == 1 and b == 0:
c.append(1)
d.append(0)
else:
c.append(1)
d.append(1)
if i == l - 1:
c = "".join([str(x) for x in c[::-1]])
d = "".join([str(x) for x in d[::-1]])
c, d = int(c, 2), int(d, 2)
print(2)
print(c, d) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | xor, sm = map(int, input().split())
if xor > sm:
print("-1")
elif xor % 2 != sm % 2:
print("-1")
elif xor == 0 and sm == 0:
print("0")
elif xor == 0:
print("2")
v = sm // 2
print(v, v)
elif xor == 1 and sm == 1:
print("1")
print("1")
elif xor == sm:
print("1")
print(xor)
else:
val = sm - xor
val //= 2
AND = val
a = 0
b = 0
bl = True
for i in range(64):
x1 = xor & 1 << i
and2 = AND & 1 << i
if x1 == 0 and and2 == 0:
continue
elif x1 == 0 and and2 > 0:
a = 1 << i | a
b = 1 << i | b
elif x1 > 0 and and2 == 0:
a = 1 << i | a
else:
bl = False
break
if bl == True:
print("2")
print(a, b)
else:
print("3")
print(val, val, xor) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = [int(i) for i in input().split(" ")]
if v == 0:
print(0)
elif v == u:
print(1)
print(v)
elif v > u and (v - u) % 2 == 0:
if u ^ (v - u) // 2 == u + (v - u) // 2:
print(2)
print(u + (v - u) // 2, (v - u) // 2)
else:
print(3)
print(u, (v - u) // 2, (v - u) // 2)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
if u > v:
print(-1)
elif u == v:
if u == v == 0:
print(0)
else:
print(1)
print(u)
elif (v - u) % 2 == 1:
print(-1)
else:
a = u
b = 0
for i in reversed(list(range(65))):
res = v - (a + b)
if u & 1 << i:
continue
if res >= 2 * (1 << i):
a += 1 << i
b += 1 << i
else:
continue
if a + b == v:
print(2)
print(a, b)
else:
print(3)
k = (v - u) // 2
print(u, k, k) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def kset(n, k):
if n >> k - 1 and 1:
return 1
else:
return 0
def compute(S, X):
A = (S - X) // 2
a = 0
b = 0
for i in range(64):
Ai = A & 1 << i
Xi = X & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai != 0:
a = 1 << i | a
b = 1 << i | b
elif Xi != 0 and Ai == 0:
a = 1 << i | a
else:
return [-1, -1]
return [a, b]
return [a, b]
ss = input().split()
x = int(ss[0])
s = int(ss[1])
if x == s == 0:
print(0)
elif s == x and x != 0 and s != 0:
print(1)
print(s)
elif s < x or (s - x) % 2 != 0:
print(-1)
else:
z = compute(s, x)
if z[0] == -1:
print(3)
print((s - x) // 2, (s - x) // 2, x)
else:
print(2)
print(z[0], z[1]) | FUNC_DEF IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER NUMBER RETURN LIST VAR VAR RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v or u % 2 != v % 2:
print("-1")
elif u == 0 and v == 0:
print("0")
elif u == v:
print("1\n")
print(u)
else:
x = int((v - u) // 2)
if u & x == 0:
print("2")
print(u + x, x, sep=" ")
else:
print("3")
print(u, x, x, sep=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR STRING |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u == 0 and v == 0:
print(0)
exit()
if u == v:
print(1)
print(u)
exit()
if v < u or v - u & 1:
print(-1)
exit()
a, b, c = u, (v - u) // 2, (v - u) // 2
if a + b == a ^ b:
print(2)
print(a + b, c)
else:
print(3)
print(a, b, c) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def compute(S, X):
A = (S - X) // 2
a = 0
b = 0
if (S - X) % 2 != 0:
return -1
for i in range(64):
Xi = X & 1 << i
Ai = A & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif Xi > 0 and Ai == 0:
a = 1 << i | a
else:
return -1
return a, b
x, s = list(map(int, input().split()))
ans = compute(s, x)
if ans != -1:
if ans[0] == 0 and ans[1] == 0:
print(0)
elif ans[1] == 0:
print(1)
print(ans[0])
else:
print(2)
print(ans[0], ans[1])
elif x == 0 or x > s:
print(-1)
elif s % x == 0 and s // x % 2 != 0:
print(s // x)
print(*([x] * (s // x)))
elif (s - x) % 2 == 0:
print(3)
print(x, (s - x) // 2, (s - x) // 2)
else:
print(-1) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def solve():
u, v = map(int, input().split())
if u % 2 != v % 2 or u > v:
print(-1)
return
if u == v:
if u:
print(1)
print(u)
else:
print(0)
return
x = (v - u) // 2
if u & x:
print(3)
print(u, x, x)
else:
print(2)
print(u ^ x, x)
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def f():
xor, sum = [int(s) for s in input().split()]
rem = sum - xor
if rem < 0 or rem & 1:
print(-1)
return
if sum == 0:
print(0)
return
if rem == 0:
print(1)
print(xor)
return
rem >>= 1
if rem & xor == 0:
print(2)
print("{} {}".format(rem + xor, rem))
return
print(3)
print("{} {} {}".format(rem, rem, xor))
f() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def linput(a):
return [int(i) for i in a.split()]
for ughblnk in range(1):
u, v = linput(input())
if u > v:
print(-1)
elif u % 2 != v % 2:
print(-1)
elif u == 0 and v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
t = (v - u) // 2
if u + t ^ t != u:
print(3)
print(u, t, t)
else:
print(2)
print(u + t, t) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = input().split()
u = int(u)
v = int(v)
delta = v - u
if delta < 0 or delta % 2 == 1:
print(-1)
elif delta == 0:
if u == 0:
print("0")
else:
print("1", "\n", u, sep="")
else:
d2 = delta // 2
if d2 & u:
print("3", "\n", d2, " ", d2, " ", u, sep="")
else:
print("2\n", d2, " ", d2 ^ u, sep="") | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING VAR STRING BIN_OP VAR VAR STRING |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | sp = lambda: list(map(int, input().split()))
si = lambda: int(input())
u, v = sp()
k = (v - u) // 2
if u > v or u % 2 != v % 2:
print(-1)
elif u == 0:
if v == 0:
print(0)
else:
print(2)
print(k, k)
elif k == 0:
print(1)
print(u)
elif k & u == 0:
print(2)
print(u + k, k)
else:
print(3)
print(u, k, k) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def pr1(a):
print(a)
exit()
flag = [0] * 100
u, v = map(int, input().split())
if u <= v:
if v == 0:
pr1(0)
if v == u:
print(1)
print(v)
exit()
if (v - u) % 2 == 1:
pr1(-1)
fl = True
for i in range(70):
if v - u & 1 << i:
flag[i - 1] += 1
if u & 1 << i - 1:
fl = False
result = [u, 0]
for i in range(70):
if flag[i]:
result[1] += 1 << i
if fl:
for i in range(70):
if flag[i]:
result[0] += 1 << i
else:
result.append(0)
for i in range(70):
if flag[i]:
result[2] += 1 << i
print(len(result))
print(*result[::-1])
else:
pr1(-1) | FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP NUMBER VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = sys.stdin.readline
def inp():
return int(input())
def inlt():
return list(map(int, input().split()))
def insr():
s = input()
return list(s[: len(s) - 1])
def invr():
return map(int, input().split())
n, k = invr()
if k < n or abs(k - n) % 2 != 0:
print(-1)
elif n == 0 == k:
print(0)
elif n == k:
print(1)
print(n)
else:
mp = {}
nd = (k - n) // 2
a = nd + n
if a ^ nd == n:
print(2)
print(a, nd)
else:
print(3)
print(n, (k - n) // 2, (k - n) // 2) | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
ans = []
tmp = v
for i in range(1000):
if u >> i & 1 == 1 and v >> i & 1 == 0:
if i - 1 < 0:
print(-1)
exit()
ans.append(1 << i - 1)
ans.append(1 << i - 1)
ans.append(1 << i)
v -= 1 << i + 1
elif u >> i & 1 == 0 and v >> i & 1 == 1:
if i - 1 < 0:
print(-1)
exit()
ans.append(1 << i - 1)
ans.append(1 << i - 1)
elif u >> i & 1 == 1 and v >> i & 1 == 1:
ans.append(1 << i)
elif u >> i & 1 == 0 and v >> i & 1 == 0:
pass
if sum(ans) != tmp:
print(-1)
exit()
cnt = [0] * 100
for num in ans:
for i in range(100):
if 1 << i & num:
cnt[i] += 1
res = []
for i in range(len(ans)):
tmp = 0
for i in range(100):
if cnt[i] >= 1:
tmp += 1 << i
cnt[i] -= 1
if tmp > 0:
res.append(tmp)
else:
break
print(len(res))
print(*res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
def main():
u, v = readIntArr()
ans = []
if u > v:
ans.append([-1])
elif u == v:
if u == 0:
ans.append([0])
else:
ans.append([1])
ans.append([u])
else:
w = v - u
if w % 2 == 1:
ans.append([-1])
else:
x = w // 2
canFit = True
i = 0
while 2**i < 10**18:
if u & 1 << i > 0 and x & 1 << i > 0:
canFit = False
i += 1
if canFit == True:
ans.append([2])
ans.append([u | x, x])
else:
ans.append([3])
ans.append([u, x, x])
multiLineArrayOfArraysPrint(ans)
return
input = lambda: sys.stdin.readline().rstrip("\r\n")
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
inf = float("inf")
MOD = 10**9 + 7
for _ in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR LIST NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def f(a):
b = 0
while a > 0:
b += 1
a //= 2
return 2 ** (b - 1)
u, v = map(int, input().split())
if u > v:
print(-1)
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(v)
else:
k = 0
while True:
if u == 0:
break
c = f(u)
u -= c
v -= c
k += c
if v % 2 == 1:
print(-1)
elif k & v // 2 == 0:
k += v // 2
print(2)
print(k, v // 2)
else:
print(3)
print(k, v // 2, v // 2) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if v < u or (v - u) % 2 != 0:
print(-1)
elif u == v:
if u == 0:
print(0)
else:
print("1\n" + str(u))
else:
w = (v - u) // 2
if w | u == w + u:
print("2\n" + str(w | u) + " " + str(w))
else:
print("3\n" + str(u) + " " + str(w) + " " + str(w)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | x, s = map(int, input().split())
def odw(l):
wyn = 0
pot = 1
for i in l:
wyn += pot * i
pot *= 2
return wyn
def konw(n):
l = []
while n > 0:
l.append(n % 2)
n //= 2
return l
xx = konw(x)
ss = konw(s)
if x == 0 and s == 0:
print(0)
else:
if x > s:
print(-1)
if x == s:
print(1)
print(x)
if x < s:
if (x - s) % 2 == 1:
print(-1)
else:
kan1 = []
kan2 = []
for i in range(len(xx)):
if xx[i] == 0:
kan1.append(0)
kan2.append(0)
else:
kan1.append(1)
kan2.append(0)
for j in range(len(xx), len(ss)):
kan1.append(0)
kan2.append(0)
ind = len(ss) - 1
while odw(kan1) + odw(kan2) < s:
while ind >= 0:
if not (kan1[ind] == kan2[ind] and kan1[ind] == 0):
ind -= 1
elif 2 ** (ind + 1) + odw(kan1) + odw(kan2) > s:
ind -= 1
else:
break
if ind == -1:
break
kan1[ind] = 1
kan2[ind] = 1
if odw(kan1) + odw(kan2) == s:
print(2)
print(odw(kan1), odw(kan2))
else:
print(3)
print(x, (s - x) // 2, (s - x) // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u == v == 0:
print(0)
exit()
if u == v:
print(1)
print(u)
exit()
if u > v:
print(-1)
exit()
a = (v - u) // 2
b = v - a
if a ^ b == u:
print(2)
print(a, b)
exit()
if (v - u) % 2 == 0:
print(3)
print(u, (v - u) // 2, (v - u) // 2)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v or (v - u) % 2 == 1:
print(-1)
return
v = (v - u) // 2
a = u | v
b = v
c = u & v
if a == 0:
print(0)
elif b == 0:
print(1)
print(a)
elif c == 0:
print(2)
print(a, b)
else:
print(3)
print(a, b, c) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v:
print(-1)
elif u == v:
if u == 0:
print(0)
else:
print(1)
print(u)
else:
dif = v - u
if dif % 2 == 0:
ha = dif // 2
tr = ha + u
if ha ^ tr == u:
print(2)
print(tr, ha)
else:
print(3)
print(ha, ha, u)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u % 2 != v % 2 or u > v:
print(-1)
exit()
s = bin(u)[2:].rjust(60, "0")
cnt = [0] * 60
for i in range(60):
cnt[i] += int(s[i])
dif = v - u
for i in range(60):
if i == 55:
h = 0
cur = dif // (1 << 60 - i - 1)
cur -= cur % 2
if 1 << 60 - i - 1 <= dif and cur != 0:
cnt[i] += cur
dif -= (1 << 60 - i - 1) * cur
ans = [[(0) for i in range(60)] for j in range(max(cnt))]
for i in range(len(ans)):
for j in range(60):
if ans[i][j] == 0 and cnt[j] != 0:
ans[i][j] += 1
cnt[j] -= 1
for i in range(len(ans)):
for j in range(60):
ans[i][j] = str(ans[i][j])
print(len(ans))
for i in ans:
print(int("".join(i), 2), end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER STRING |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
if u > v:
print(-1)
elif u == 0 and v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
a, b, c = u, (v - u) // 2, (v - u) // 2
d, e = (v - u) // 2 + u, (v - u) // 2
if d + e == v and d ^ e == u:
print(2)
print(d, e)
elif a + b + c == v and a ^ b ^ c == u:
print(3)
print(a, b, c)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
u, v = list(map(int, sys.stdin.readline().strip().split()))
w = v - u
if w % 2 == 1 or w < 0:
print(-1)
elif w == 0:
if u == 0:
print(0)
else:
print(1)
print(str(u))
else:
w = w // 2
if u & w == 0:
print(2)
print(str(u + w) + " " + str(w))
else:
print(3)
print(str(u) + " " + str(w) + " " + str(w)) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
bits = [0] * 61
i = 0
if u & 1 != v & 1:
print(-1)
else:
c = 0
while u or v:
a = u & 1
b = v & 1
if a == 1 and b == 1:
bits[i] += 1
if c == 1:
bits[i - 1] += 2
elif a == 1 and b == 0:
bits[i] += 1
if c != 1:
bits[i - 1] += 2
c = 1
elif a == 0 and b == 1:
if c != 1:
bits[i - 1] += 2
else:
c -= 1
elif a == 0 and b == 0:
if c == 1:
bits[i - 1] += 2
i += 1
u >>= 1
v >>= 1
if c != 0:
print(-1)
else:
mbit = max(bits)
A = []
for j in range(mbit):
s = ""
for i in range(len(bits)):
if bits[i] >= j + 1:
s = "1" + s
else:
s = "0" + s
A.append(int(s, 2))
print(mbit)
print(*A) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
def sameforbin(a, b):
aa = bin(a)[2:]
bb = bin(b)[2:]
for i in range(1, min(len(aa), len(bb)) + 1):
if aa[-i] == bb[-i] == "1":
return True
return False
if u > v or (v - u) % 2:
print(-1)
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
d = (v - u) // 2
if sameforbin(d, u):
print(3)
print(d, d, u)
else:
print(2)
print(d, u + d) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = [int(x) for x in input().split()]
if u > v or (v - u) % 2 == 1:
print(-1)
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
a, b = u | (v - u) // 2, (v - u) // 2
if a ^ b == u and a + b == v:
print(2)
print(a, b)
else:
print(3)
print((v - u) // 2, (v - u) // 2, u) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | [u, v] = list(map(int, input().split(" ")))
if u == 0 and v == 0:
print(0)
elif u > v or u % 2 != v % 2:
print(-1)
elif u == v:
print(1)
print(v)
else:
t = (v - u) // 2
if t & u:
print(3)
print(str(t) + " " + str(t) + " " + str(u))
else:
print(2)
print(str(t) + " " + str(t ^ u)) | ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin, stdout
u, v = map(int, stdin.readline().split())
if u > v:
print("-1")
elif u % 2 != v % 2:
print("-1")
elif u == 0 and v == 0:
print("0")
elif u == 0:
print(2)
print(v // 2, v // 2)
elif u == v:
print(1)
print(u)
else:
t = (v - u) // 2
if t & u != 0:
print(3)
print(u, t, t)
else:
print(2)
print(u + t, t) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | x, y = map(int, input().split())
if x == 0 and y == 0:
print(0)
elif x == y:
print(1)
print(x)
elif abs(x - y) % 2 == 1 or x > y:
print(-1)
else:
y = y - x
y = y // 2
yy = y
xx = x
p = 0
while yy > 0:
if yy % 2 == 1 and xx % 2 == 1:
p = 1
break
xx //= 2
yy //= 2
if p == 1:
print(3)
print(y, y, x)
else:
print(2)
print(y, x + y) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def calc():
tot = 2
a = u
b = 0
c = 0
d = v - u
nb = 0
while d > 0:
if d & 1:
if 1 << nb - 1 & a:
tot = 3
b += 1 << nb - 1
c += 1 << nb - 1
else:
a += 1 << nb - 1
b += 1 << nb - 1
d >>= 1
nb += 1
return [a, b, c, tot]
u, v = map(int, input().split())
if u == v and u == 0:
print(0)
exit(0)
if u > v:
print(-1)
elif u == v:
print(1)
print(u)
elif v - u & 1:
print(-1)
else:
ans = calc()
print(ans[-1])
print(ans[0], ans[1], end=" ")
if ans[-1] == 3:
print(ans[2]) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN LIST VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v or u % 2 != v % 2:
print("-1")
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(u)
elif u & (v - u) // 2 is not 0:
print(3)
print(u, (v - u) // 2, (v - u) // 2)
else:
print(2)
print(u + (v - u) // 2, (v - u) // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = lambda: sys.stdin.readline().rstrip()
u, v = map(int, input().split())
if u == 0 and v == 0:
print(0)
elif v < u or (v - u) % 2 == 1:
print(-1)
elif u == v:
print(1)
print(u)
else:
Ans = [u, (v - u) // 2, (v - u) // 2]
if Ans[0] + Ans[1] == Ans[0] | Ans[1]:
Ans = [Ans[0] + Ans[1], Ans[2]]
print(len(Ans))
print(*Ans) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u & 1 ^ v & 1 or u > v:
print(-1)
exit()
if not u and not v:
print(0)
exit()
if u == v:
print(1)
print(u)
exit()
_and = (v - u) // 2
c = int(u + _and)
d = int(_and)
if c ^ d == u:
print(2)
print(c, d)
exit()
print(3)
print((v - u) // 2, u, (v - u) // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
from sys import stdin
tt = 1
for loop in range(tt):
u, v = map(int, stdin.readline().split())
if v == u == 0:
print(0)
sys.exit()
if u % 2 != v % 2 or u > v:
print(-1)
sys.exit()
if u == v:
print(1)
print(u)
sys.exit()
ans = [0, 0]
ulis = []
vrem = v
for i in range(65):
if 2**i & u > 0:
vrem -= 2**i
ans[0] += 2**i
else:
ulis.append(2 ** (i + 1))
ulis.sort()
ulis.reverse()
for i in ulis:
if i <= vrem:
vrem -= i
ans[0] += i // 2
ans[1] += i // 2
if ans[0] ^ ans[1] == u and ans[0] + ans[1] == v:
print(2)
print(*ans)
sys.exit()
print(3)
print(*[u, (v - u) // 2, (v - u) // 2]) | IMPORT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import exit
v, u = map(int, input().split())
arr = []
for i in range(64):
if v >> i & 1:
arr.append(1 << i)
x = u - v
if x < 0 or x % 2 != 0:
print(-1)
exit(0)
for i in range(64):
if x >> i & 1:
arr.append(1 << i - 1)
arr.append(1 << i - 1)
for i in range(len(arr)):
for b in range(0, 64):
if arr[i] >> b & 1 == 0:
continue
for j in range(i + 1, len(arr)):
if arr[j] >> b & 1 == 1:
continue
arr[j] |= 1 << b
arr[i] &= ~(1 << b)
break
brr = []
for el in arr:
if el == 0:
continue
brr.append(el)
print(len(brr))
print(*brr) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | a, b = map(int, input().split())
x = (b - a) // 2
if a > b or (a - b) % 2:
print(-1)
elif b == 0:
print(0)
elif a == b:
print(1)
print(b)
elif x + a ^ x == a:
print(2)
print(x + a, x)
else:
print(3)
print((b - a) // 2, (b - a) // 2, a) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
rem = v - u
out = [u]
if rem < 0:
print(-1)
elif v == u == 0:
print(0)
elif rem == 0:
print(1)
print(u)
elif rem % 2 == 0:
add = rem // 2
if add + u == add ^ u:
print(2)
print(add + u, add)
else:
print(3)
print(u, add, add)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | xor, sum = map(int, input().split())
answer = []
if xor > sum or sum - xor & 1:
print(-1)
exit()
elif xor == sum:
if xor == 0:
print(0)
exit()
answer.append(xor)
else:
carry = False
X, S = xor, sum
xor, sum = bin(xor)[2:][::-1], bin(sum)[2:][::-1]
xor = xor + "0" * (len(sum) - len(xor))
answer = ["", ""]
for index, bit_xor, bit_sum in zip(range(len(xor)), xor, sum):
if bit_xor == bit_sum == "1" and not carry:
answer[0] += "1"
answer[1] += "0"
elif bit_sum == bit_xor == "0" and not carry:
if index < len(xor) - 1 and sum[index + 1] != xor[index + 1]:
carry = True
answer[0] += "1"
answer[1] += "1"
else:
answer[0] += "0"
answer[1] += "0"
elif bit_sum == "1" and bit_xor == "0" and carry:
if index < len(sum) - 1 and sum[index + 1] != xor[index + 1]:
answer[0] += "1"
answer[1] += "1"
else:
carry = False
answer[0] += "0"
answer[1] += "0"
elif bit_sum == "0" and bit_xor == "1" and carry:
answer[0] += "1"
answer[1] += "0"
else:
answer = [X, (S - X) // 2, (S - X) // 2]
carry = None
break
if carry == True:
answer[0].append("1")
if carry != None:
answer = [int(x[::-1], 2) for x in answer]
print(str(len(answer)) + "\n" + "".join(str(x) + " " for x in answer)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR VAR NUMBER STRING VAR NUMBER STRING IF VAR VAR STRING VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING IF VAR STRING VAR STRING VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER STRING VAR NUMBER STRING IF VAR STRING VAR STRING VAR VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NONE IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL STRING BIN_OP FUNC_CALL VAR VAR STRING VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | s = input().split()
u = int(s[0])
v = int(s[1])
if u > v or (u + v) % 2 == 1:
print(-1)
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(u)
elif (u + v) % 2 == 0:
if (v + u) // 2 ^ (v - u) // 2 == u:
print(2)
print((v + u) // 2, " ", (v - u) // 2)
else:
print(3)
print(u, " ", (v - u) // 2, " ", (v - u) // 2) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = sys.stdin.readline
def main():
U, V = [int(x) for x in input().split()]
if U > V:
print(-1)
return
if V == 0:
print(0)
return
if U == V:
print(1)
print(U)
return
if abs(U - V) % 2 != 0:
print(-1)
return
if (V - U) // 2 & U == 0:
print(2)
print((V - U) // 2, U + (V - U) // 2)
else:
print(3)
print((V - U) // 2, (V - U) // 2, U)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin, stdout
def main():
a, b = list(map(int, stdin.readline().split()))
if a == 0:
if b == 0:
print("0")
return
elif b % 2 == 0:
print("2")
print(str(int(b / 2)) + " " + str(int(b / 2)))
return
else:
print("-1")
return
ans = []
b -= a
if b == 0:
print("1")
print(a)
return
if b % 2 == 1 or b < 0:
print("-1")
return
half = b >> 1
if half | a == half + a:
print("2")
print(half + a, half)
else:
print("3")
print(half, half, a)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if (u - v) % 2 != 0 or u > v:
print(-1)
elif u == 0 == v:
print(0)
elif u == v:
print(1)
print(u)
else:
U = u
V = v
u = bin(u)[2:]
v = bin(v)[2:]
u = "0" * (70 - len(u)) + u
v = "0" * (70 - len(v)) + v
A = [0] * 70
b = True
for i in range(70):
if u[i] == "0" and v[i] == "0":
continue
if u[i] == "0" and v[i] == "1":
if i == 69:
print(-1)
exit(0)
A[i + 1] += 2
if u[i] == "1" and v[i] == "1":
A[i] += 1
if u[i] == "1" and v[i] == "0":
if i == 69:
b = False
flag = False
for j in range(i, -1, -1):
if A[j] == 0:
A[j] = 2
elif A[j] == 1:
break
else:
A[j] -= 2
flag = True
break
if not flag:
b = False
A[i] += 1
A[i + 1] = 2
continue
if max(A) >= 3 or not b:
print(3)
print((V - U) // 2, (V - U) // 2, U)
exit(0)
print(max(A))
for i in range(1, 1 + max(A)):
num = 0
for j in range(1, 70):
if A[-j] >= i:
num += 2 ** (j - 1)
print(num, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | ch = input()
L = [int(i) for i in ch.split()]
a = L[0]
b = L[1]
if a > b:
print(-1)
elif a == b:
if a == 0:
print(a)
else:
print(1)
print(a)
elif (b - a) % 2 == 1:
print(-1)
elif a & (b - a) // 2 == 0:
print(2)
print(a + (b - a) // 2, (b - a) // 2)
else:
print(3)
print(a, (b - a) // 2, (b - a) // 2) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def compute(S, X):
A = (S - X) // 2
a = 0
b = 0
for i in range(64):
Xi = X & 1 << i
Ai = A & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif Xi > 0 and Ai == 0:
a = 1 << i | a
else:
return -1
if a + b != S:
return -1
return a, b
a, b = list(map(int, input().strip().split()))
if a == b == 0:
print(0)
exit()
if a == b:
print(1)
print(a)
exit()
if (b - a) % 2 != 0:
print(-1)
exit()
o = compute(b, a)
if o != -1:
print(2)
print(*o)
exit()
v = (b - a) // 2
if v < 0:
print(-1)
exit()
print(3)
print(a, v, v) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
def xorcise(u, v):
if u > v or v & 1 != u & 1:
print(-1)
return
m = v.bit_length()
r_bits = list(map(int, reversed(format(v - u, "b").zfill(m))))
x = u
y = 0
z = 0
for b in range(m - 1):
d = 1 << b
if r_bits[b + 1]:
if x & d:
y += d
z += d
else:
x += d
y += d
out = []
if x:
out.append(x)
if y:
out.append(y)
if z:
out.append(z)
print(len(out))
if out:
print(*out)
xorcise(u, v) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def two(s, x):
aa = (s - x) // 2
a = 0
b = 0
for i in range(0, 100):
nowi = x & 1 << i
nowa = aa & 1 << i
if nowi == 0 and nowa == 0:
continue
if nowi == 0 and nowa > 0:
a = 1 << i | a
b = 1 << i | b
elif nowi > 0 and nowa == 0:
a = 1 << i | a
else:
return 0, 0
return a, b
def main():
u, v = [int(i) for i in input().split()]
if (v - u) % 2 != 0:
print(-1)
return 0
if u == v:
if u == 0:
print(0)
return 0
else:
print(1, v)
return 0
if u > v:
print(-1)
return 0
if two(v, u) != (0, 0):
print(2)
print(two(v, u)[0], two(v, u)[1])
return 0
if (v - u) % 2 != 0:
print(-1)
return 0
print(3)
print((v - u) // 2, (v - u) // 2, u)
main() | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR NUMBER VAR RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
u, v = list(map(int, input().split()))
if u > v:
print(-1)
elif u == v:
if u == 0:
print(0)
else:
print(1)
print(u)
elif u % 2 == 0:
if v % 2 == 0:
num = (v - u) // 2
num2 = int(num & u)
if not num2:
print(2)
print(str(u + num) + " " + str(num))
else:
print(3)
print(str(u) + " " + str(num) + " " + str(num))
else:
print(-1)
elif v % 2 == 0:
print(-1)
else:
num = (v - u) // 2
num2 = int(num & u)
if not num2:
print(2)
print(str(u + num) + " " + str(num))
else:
print(3)
print(str(u) + " " + str(num) + " " + str(num)) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | powers = [(2**i) for i in range(61)]
x, s = map(int, input().split())
if x > s:
print(-1)
elif x == s:
if x == 0:
print(0)
else:
print(1)
print(x)
else:
bckt = [0] * 3
bckt[0] = x
s -= x
i = 0
bad = set()
good = set()
while i < 61:
query = x >> i
if query % 2:
bad.add(i)
else:
good.add(i)
i += 1
while s > 1:
to_add = 1
for i in range(61):
if powers[i] <= s // 2:
to_add = i
s -= 2 * powers[to_add]
if to_add in bad:
bckt[1] += powers[to_add]
bckt[2] += powers[to_add]
elif to_add in good:
bckt[0] += powers[to_add]
bckt[1] += powers[to_add]
if s % 2:
print(-1)
elif 0 in bckt:
to_print = [i for i in bckt if i > 0]
print(len(to_print))
print(*to_print)
else:
print(3)
print(*bckt) | ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def linput(a):
return [int(i) for i in a.split()]
for ughblnk in range(1):
u, v = linput(input())
if u > v:
print(-1)
elif u % 2 != v % 2:
print(-1)
elif u == 0 and v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
t = (v - u) // 2
bu = bin(u)[2:][::-1]
bt = bin(t)[2:][::-1]
i, q = 0, 0
while i < len(bu) and i < len(bt) and q == 0:
if bu[i] == bt[i] and bu[i] == "1":
q = 1
i += 1
if q == 1:
print(3)
print(u, t, t)
else:
print(2)
print(u + t, t) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def solve(u, v):
if u == v:
return [u]
elif u > v:
return None
if (v - u) % 2 == 0:
x = (v - u) // 2
if u & x == 0:
return [u | x, x]
else:
return [u, x, x]
else:
return None
u, v = map(int, input().split())
r = solve(u, v)
if not r:
print(-1)
elif u == v == 0:
print(0)
else:
print("{}\n{}".format(len(r), " ".join(map(str, r)))) | FUNC_DEF IF VAR VAR RETURN LIST VAR IF VAR VAR RETURN NONE IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN LIST BIN_OP VAR VAR VAR RETURN LIST VAR VAR VAR RETURN NONE ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin
for line in stdin:
u, v = map(int, line.split())
if u > v or (v - u) % 2 == 1:
print("-1")
elif u == v:
if v == 0:
print("0")
else:
print("1")
print(u)
else:
t = (v - u) // 2
if u & t == 0:
print("2")
print(f"{u + t} {t}")
else:
print("3")
print(f"{u} {t} {t}") | FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING VAR STRING VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def f(u, v):
x = [int(y) for y in bin(u)[2:]]
s = [int(z) for z in bin(v)[2:]]
x = [0] * (len(s) - len(x)) + x
a = [0] * len(x)
b = [0] * len(x)
for i in range(len(x) - 1, 0, -1):
if x[i] == 1:
a[i] = 0
b[i] = 1
elif s[i - 1] == x[i - 1]:
a[i] = 0
b[i] = 0
else:
a[i] = 1
b[i] = 1
if x[0] == 1:
a[0] = 0
b[0] = 1
c = 0
d = 0
for i in range(len(a)):
c += pow(2, len(a) - i - 1) * a[i]
d += pow(2, len(a) - i - 1) * b[i]
return c, d
u, v = map(int, input().split())
if u % 2 != v % 2 or v < u:
print(-1)
elif u == 0 and v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
c, d = f(u, v)
if c + d == v and c ^ d == u:
print(2)
print(c, d)
else:
print(3)
print(u, (v - u) // 2, (v - u) // 2) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | def main():
u, v = map(int, input().split())
if u > v:
print(-1)
return
if u == v:
if u == 0:
print(0)
return
print(1)
print(u)
return
diff = v - u
if diff % 2 == 0:
arr = [u, diff // 2, diff // 2]
a = diff // 2
b = v - a
if a & b == diff // 2:
arr = [a, b]
else:
print(-1)
return
print(len(arr))
for i in arr:
print(i, end=" ")
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u == v and u == 0:
print(0)
elif v < u or (v - u) % 2 == 1:
print(-1)
elif u == v:
print(1)
print(u)
else:
ub = []
a1 = u
while u > 0:
ub.append(u % 2)
u = u // 2
vb = []
v = (v - a1) // 2
a2 = v
while v > 0:
vb.append(v % 2)
v = v // 2
flag = 0
for i in range(min(len(ub), len(vb))):
if ub[i] == vb[i] and ub[i] == 1:
flag = 1
break
if flag == 1:
print(3)
print(a1, a2, a2)
else:
print(2)
print(a1 + a2, a2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | x, s = map(int, input().split())
if s == 0:
print(0)
elif x > s or (s - x) % 2 == 1:
print(-1)
elif x == 0:
print(2)
print(s // 2, s // 2)
elif x == s:
print(1)
print(s)
elif (
int("1" * (len(bin(x)) - 2), 2) ^ s - int("1" * (len(bin(x)) - 2), 2) == x
and s - int("1" * (len(bin(x)) - 2), 2) >= 0
):
print(2)
print(int("1" * (len(bin(x)) - 2), 2), s - int("1" * (len(bin(x)) - 2), 2))
elif (x ^ (s - x) // 2) + (s - x) // 2 == s:
print(2)
print((s - x) // 2, x ^ (s - x) // 2)
else:
print(3)
print((s - x) // 2, (s - x) // 2, x) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin
input = stdin.buffer.readline
u, v = map(int, input().split())
if u > v or u & 1 != v & 1:
print(-1)
elif u == v:
print("1\n{}".format(u) if u else "0")
else:
z = (v - u) // 2
print("3\n{} {} {}".format(u, z, z) if u & z != 0 else "2\n{} {}".format(u + z, z)) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL STRING VAR VAR VAR FUNC_CALL STRING BIN_OP VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u > v:
print(-1)
exit(0)
if u == 0 and v == 0:
print(0)
exit(0)
if u == v:
print(1)
print(u)
exit(0)
binary = [(2**i) for i in range(61)]
p = [0] * 60
d = v - u
v1 = v - u
u1 = u
for i in range(60 - 1, -1, -1):
p[i] += u1 // binary[i]
u1 %= binary[i]
answer = []
for i in range(60 - 1, 0, -1):
if v1 >= binary[i]:
p[i - 1] += 2
v1 %= binary[i]
f = True
if p[0] % 2 == 1 and d % 2 == 1:
print(-1)
exit(0)
m = max(p)
while f:
f = False
k = 0
for i in range(60 - 1, -1, -1):
if p[i] > 0:
f = True
p[i] -= 1
k += binary[i]
if f:
answer.append(k)
if sum(answer) != v:
print(-1)
else:
print(m)
print(*answer) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = map(int, input().split())
if u == v:
if u > 0:
ans = [u]
else:
ans = []
elif u > v:
ans = None
else:
diff = v - u
if diff % 2:
ans = None
elif u + diff // 2 == u ^ diff // 2:
ans = [u + diff // 2, diff // 2]
else:
ans = [u, diff // 2, diff // 2]
if ans is None:
print(-1)
else:
print(len(ans))
print(" ".join(map(str, ans)))
if sum(ans) != v:
raise ValueError(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST IF VAR VAR ASSIGN VAR NONE ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR NONE IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin
inf = stdin
v, u = map(int, inf.readline().split(" "))
if u > v:
if v % 2 != u % 2:
print(-1)
else:
posi = v
temp = (u - v) // 2
if posi + temp == posi ^ temp:
print(2)
print(posi + temp, temp)
else:
print(3)
print(temp, temp, posi)
elif u == v:
if u != 0:
print(1)
print(u)
else:
print(-1) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = sys.stdin.readline
u, v = map(int, input().split())
if u > v:
print(-1)
elif (v - u) % 2 == 1:
print(-1)
elif u == v == 0:
print(0)
elif u == v:
print(1)
print(u)
else:
A = (v - u) // 2
B = (v - u) // 2
REST = u
for i in range(64):
if REST & 1 << i != 0 and A & 1 << i == 0:
A += 1 << i
REST -= 1 << i
if REST == 0:
print(2)
print(A, B)
else:
print(3)
print(A, B, REST) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
def input():
return sys.stdin.readline()
def iinput():
return int(input())
def rinput():
return input().split()
def rlinput():
return [int(i) for i in input().split()]
def main():
q = [0] * 100
u, v = rlinput()
if u <= v:
if v == 0:
print(0)
return 0
if v == u:
print(1)
print(v)
return 0
if (v - u) % 2 == 1:
print(-1)
return 0
fl = True
for i in range(70):
if v - u & 1 << i:
q[i - 1] += 1
if u & 1 << i - 1:
fl = False
w = [u, 0]
if fl:
for i in range(70):
if q[i]:
w[1] += 1 << i
w[0] += 1 << i
else:
w.append(0)
for i in range(70):
if q[i]:
w[1] += 1 << i
w[2] += 1 << i
print(len(w))
print(*w)
else:
print(-1)
for i in range(1):
main() | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | import sys
input = sys.stdin.readline
def solve():
u, v = map(int, input().split())
if u == 0:
if v == 0:
print(0)
return
if v % 2 == 1:
print(-1)
return
print(2)
print(v // 2, v // 2)
return
if u > v:
print(-1)
return
if u == v:
print(1)
print(u)
return
if u < v:
if (v - u) % 2 == 1:
print(-1)
return
vu = (v - u) // 2
if u + vu == u ^ vu:
print(2)
print(u + vu, vu)
return
print(3)
print(u, vu, vu)
return
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | data = input().rstrip().split()
x, s = int(data[0]), int(data[1])
def main(s, x):
if s == x:
if s == 0:
print(0)
else:
print(1)
print(x)
else:
d = s - x
if d < 0 or d % 2 == 1:
print(-1)
return
a = d // 2
b = x
if a + b == a ^ b:
print(2)
print(str(a) + " " + str(a + b))
else:
print(3)
print(str(a) + " " + str(a) + " " + str(b))
main(s, x) | ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | from sys import stdin
def mp():
return map(int, stdin.readline().split())
def ml():
return list(map(int, stdin.readline().split()))
xor, sm = mp()
if xor > sm:
print(-1)
elif (sm - xor) % 2 == 1:
print(-1)
else:
n1 = xor
n2 = (sm - xor) // 2
if n1 == 0 and n2 == 0:
print(0)
elif n2 == 0:
print(1)
print(n1)
elif n2 + n1 ^ n2 == xor:
print(2)
print(n2 + n1, n2)
elif n2 + n2 ^ n1 == xor:
print(2)
print(n2 + n2, n1)
else:
print(3)
print(n1, n2, n2) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:
The first line should contain one integer, $n$, representing the length of the desired array. The next line should contain $n$ positive integers, the array itself. If there are multiple possible answers, print any.
-----Examples-----
Input
2 4
Output
2
3 1
Input
1 3
Output
3
1 1 1
Input
8 5
Output
-1
Input
0 0
Output
0
-----Note-----
In the first sample, $3\oplus 1 = 2$ and $3 + 1 = 4$. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty. | u, v = list(map(int, input().split()))
mas = []
if v < u - 1:
print(-1)
exit()
if u % 2 != v % 2:
print(-1)
exit()
if u == 0 and v == 0:
print(0)
exit()
if u == v:
print(1)
print(u)
exit()
x = (v - u) // 2
if u & x:
print(3)
print(u, x, x, sep=" ")
exit()
print(2)
print(u + x, x, sep=" ") | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.