Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?


-----Input-----

The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and bitwise xor of the pair of positive integers, respectively.


-----Output-----

Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.


-----Examples-----
Input
9 5

Output
4

Input
3 3

Output
2

Input
5 2

Output
0



-----Note-----

In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).

In the second sample, the only solutions are (1, 2) and (2, 1).

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Mathematics


Solutions:
(s, x) = map(int, input().split())
b = s - x
b = list(bin(s - x))
b = b[2:]
a = list(bin(x))
a = a[2:]
al = len(a)
bl = len(b)
c = []
if bl > al:
	for i in range(bl - al):
		c.append('0')
	c.extend(a)
	a = c
else:
	for i in range(al - bl):
		c.append('0')
	c.extend(b)
	b = c
p = 0
bl = len(b)
for i in range(bl - 1):
	if b[i] == '1':
		if a[i + 1] == '1':
			p = 1
bl = len(b)
if b[bl - 1] == '1':
	p = 1
if x > s:
	print('0')
elif p == 1:
	print('0')
elif s == x:
	print(2 ** a.count('1') - 2)
elif x == 0:
	print('1')
else:
	print(2 ** a.count('1'))


(a, b) = [int(x) for x in input().split()]
c = (a - b) / 2
if c < 0 or not c.is_integer() or int(c) & b:
	print(0)
	exit(0)
t = 0
while b:
	t += b & 1
	b >>= 1
t = 1 << t
if c == 0:
	t -= 2
print(t)


import sys
import io
stream_enable = 0
inpstream = '\n9 5\n'
if stream_enable:
	sys.stdin = io.StringIO(inpstream)
	input()

def inpmap():
	return list(map(int, input().split()))
(a, b) = inpmap()
if b > a:
	print(0)
	return
flag = a == b
b = '0' * (len(bin(a)) - len(bin(b))) + bin(b)[2:]
res = 1
p = 2 ** (len(b) - 1)
for x in b:
	if x == '1':
		res *= 2
		a -= p
	elif a >= p * 4 - 1:
		print(0)
		return
	elif a >= p * 2:
		a -= p * 2
	p //= 2
if a:
	print(0)
	return
if flag:
	res -= 2
print(res)


for _ in range(1):
	(add, xor_n) = map(int, input().split())
	if add < xor_n:
		print(0)
		continue
	d = add - xor_n
	if d % 2 == 1:
		print(0)
		continue
	d //= 2
	xor = bin(xor_n).replace('0b', '')
	sub = 0
	if xor_n & d == 0:
		if add == xor_n:
			sub = 2
		print(2 ** xor.count('1') - sub)
	else:
		print(0)


'__author__' == 'deepak Singh Mehta(learning brute force)) '

def __starting_point():
	(s, x) = list(map(int, input().split(' ')))
	if (s - x) % 2 or s < x:
		print(0)
	else:
		c = bin((s - x) // 2)[2:][::-1]
		t = bin(x)[2:][::-1]
		for i in range(len(t)):
			if t[i] == '1' and i < len(c) and (c[i] == '1'):
				print(0)
				return
		print(pow(2, bin(x)[2:].count('1')) - (2 if s == x else 0))
__starting_point()


(s, x) = map(int, input().split())
andi = (s - x) / 2
if s < x or andi != int(andi) or int(andi) & x:
	print(0)
elif x == 0:
	print(1)
elif x == 1 and andi == 0:
	print(2)
elif x == 1 and andi == 1:
	print(0)
else:
	print(2 ** bin(x).count('1') - 2 * (1 if andi == 0 else 0))


(s, x) = list(map(int, input().split(' ')))
if (s - x) % 2 or s < x:
	print(0)
else:
	c = bin((s - x) // 2)[2:][::-1]
	t = bin(x)[2:][::-1]
	for i in range(len(t)):
		if t[i] == '1' and i < len(c) and (c[i] == '1'):
			print(0)
			return
	print(pow(2, bin(x)[2:].count('1')) - (2 if s == x else 0))


(s, x) = map(int, input().split())
if s < x:
	print(0)
	exit(0)
f = x
if (s - x) % 2 == 1:
	print(0)
	exit(0)
x = bin(x)[2:]
y = (s - f) // 2
y = bin(y)
y = y[2:]
if len(x) > len(y):
	y = '0' * (len(x) - len(y)) + y
else:
	x = '0' * (len(y) - len(x)) + x
k = 0
for i in range(len(x)):
	if x[i] == '1':
		k += 1
	if int(x[i]) + int(y[i]) == 2:
		print(0)
		exit(0)
if s == f:
	print(2 ** k - 2)
	exit(0)
print(2 ** k)


def func(s, x):
	if x == 0 and s % 2 == 0:
		return 1
	if s == 0:
		return 0
	if s % 2 == 1 and x % 2 == 1:
		return 2 * func(s // 2, x // 2)
	if s % 2 == 1 and x % 2 == 0:
		return 0
	if s % 2 == 0 and x % 2 == 1:
		return 0
	if s % 2 == 0 and x % 2 == 0:
		return func(s // 2 - 1, x // 2) + func(s // 2, x // 2)
(s, x) = list(map(int, input().split()))
cnt = func(s, x)
if s ^ 0 == x:
	cnt = cnt - 2
print(cnt)


R = lambda : map(int, input().split())
(s, x) = R()
if s < x or s - x & 1:
	print(0)
	return
(u, d) = ((s - x) // 2, x)
res = 1
while u or d:
	(uu, dd) = (u & 1, d & 1)
	if uu and dd:
		res *= 0
	elif uu == 0 and dd == 1:
		res *= 2
	(u, d) = (u >> 1, d >> 1)
if s == x:
	res = max(0, res - 2)
print(res)


def main():
	(s, x) = list(map(int, input().split()))
	if s < x:
		print(0)
		return
	(s, x) = ([c == '1' for c in bin(int(_))[2:]] for _ in (s, x))
	x = [False] * (len(s) - len(x)) + x
	(a, b) = ([False] * len(s), [False] * len(s))

	def deeper(idx, carry):
		if idx:
			idx -= 1
			if carry:
				if s[idx] == x[idx]:
					return
				if s[idx]:
					deeper(idx, False)
					a[idx] = True
					b[idx] = True
					deeper(idx, True)
					a[idx] = False
					b[idx] = False
				else:
					b[idx] = True
					deeper(idx, True)
					b[idx] = False
			else:
				if s[idx] != x[idx]:
					return
				if s[idx]:
					b[idx] = True
					deeper(idx, False)
					b[idx] = False
				else:
					a[idx] = True
					b[idx] = True
					deeper(idx, True)
					a[idx] = False
					b[idx] = False
					deeper(idx, False)
		else:
			raise TabError
	try:
		deeper(len(s), False)
	except TabError:
		print((1 << sum(b) - sum(a)) - (0 if any(a) else 2))
	else:
		print(0)

def __starting_point():
	main()
__starting_point()


(s, x) = map(int, input().split())
print(0 if s < x or s - x & 2 * x + 1 else 2 ** bin(x).count('1') - 2 * (s == x))


(s, x) = list(map(int, input().split()))
rem = int(s == x) * 2
(p, t, cur) = ([], 0, 1)
for i in range(64):
	if x % 2:
		t += 1
		s -= cur
	else:
		p.append(cur * 2)
	cur *= 2
	x //= 2
for i in p[::-1]:
	if s >= i:
		s -= i
ans = 0 if s else 2 ** t - rem
print(ans)


(s, x) = map(int, input().split())
minus = 0
if s == x:
	minus = -2
if (s - x) % 2 == 1 or s < x:
	print(0)
else:
	a = s - x >> 1
	p = 0
	bsdk = False
	while a or x:
		if x & 1 and (not a & 1):
			p += 1
		elif x & 1 and a & 1:
			bsdk = True
		a >>= 1
		x >>= 1
	if bsdk:
		print(0)
	else:
		print(pow(2, p) + minus)


def main():
	(s, x) = map(int, input().split())
	if s < x or (s - x) % 2:
		print(0)
		return
	an = (s - x) // 2
	ans = 1
	for i in range(41):
		if 1 << i & x:
			if 1 << i & an:
				ans = 0
			else:
				ans *= 2
	if an == 0:
		ans -= 2
	print(ans)
	return
main()


(s, x) = list(map(int, input().split()))
jj = 1 if s >= x and (s - x) / 2 == (s - x) // 2 else 0
xx = bin(x)[2:]
aa = bin((s - x) // 2)[2:]
if len(xx) < len(aa):
	xx = (len(aa) - len(xx)) * '0' + xx
else:
	aa = (len(xx) - len(aa)) * '0' + aa
for i in range(len(xx)):
	if xx[i] == '0':
		continue
	elif xx[i] == '1':
		if aa[i] == '0':
			jj *= 2
		else:
			jj = 0
if (s - x) // 2 == 0 and jj >= 2:
	jj -= 2
print(jj)


(s, xx) = map(int, input().split())
if s - xx & 1 or s < xx:
	exit(print(0))
y = bin(s - xx)[2:-1]
x = bin(xx)[2:]
ans = 1
if len(y) < len(x):
	y = '0' * (len(x) - len(y)) + y
else:
	x = '0' * (len(y) - len(x)) + x
for i in range(len(x)):
	if x[i] == '1' and y[i] == '1':
		exit(print(0))
	if x[i] == '1' and y[i] == '0':
		ans <<= 1
print(ans - 2 * (s == xx))


(suma, xor) = list(map(int, input().split()))
mitad = round((suma - xor) / 2)
if mitad < 0 or mitad * 2 + xor != suma or mitad & xor != 0:
	print(0)
else:
	print(2 ** bin(xor).count('1') - 2 * (suma == xor))


from sys import stdout, stdin, setrecursionlimit
from bisect import insort, bisect_right, bisect_left
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def primeNums():
	N = 10 ** 5
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(s, x) = zzz()

def solve(s, x):
	ab = s - x
	if x << 1 & ab or ab % 2 or ab < 0:
		return 0
	return 2 ** bin(x).count('1') - (0 if ab else 2)
print(solve(s, x))


def digits(n):
	d = []
	while n:
		d.append(n % 2)
		n //= 2
	return d
(s, x) = map(int, input().split())
flag = True
if s - x < 0 or (s - x) % 2 == 1:
	print(0)
else:
	a = s - x >> 1
	AND = digits(a)
	XOR = digits(x)
	for i in range(max(len(AND), len(XOR))):
		if i < len(XOR):
			xi = XOR[i]
		else:
			xi = 0
		if i < len(AND):
			ai = AND[i]
		else:
			ai = 0
		if xi == 1 and ai != 0:
			print(0)
			flag = False
			break
	if flag:
		data = XOR.count(1)
		ans = 2 ** data
		if a == 0:
			ans -= 2
		print(ans)


(s, x) = list(map(int, input().split()))
print((s - x & x + x + 1 == 0 and x <= s) * (2 ** bin(x).count('1') - 2 * (s == x)))


def func(S, X):
	if S - X < 0:
		return 0
	elif (S - X) % 2:
		return 0
	nd = (S - X) // 2
	c = 0
	while X:
		if X & 1:
			if nd & 1:
				return 0
			c += 1
		X >>= 1
		nd >>= 1
	return 2 ** c
(S, X) = map(int, input().split())
print(func(S, X) - 2 * (S == X))


(s, x) = map(int, input().split())
(a, b) = (1, 0)
for i in range(50):
	(c, d) = (s & 1 << i, x & 1 << i)
	if c == d:
		if c:
			(a, b) = (2 * a, 0)
		else:
			(a, b) = (a, a)
	elif c:
		(a, b) = (b, b)
	else:
		(a, b) = (0, 2 * b)
if s == x:
	a -= 2
print(a)


def codechef(s, x):
	flag = 0
	a = (s - x) // 2
	if (s - x) / 2 != a:
		print(0)
		return
	if s == x:
		flag = 1
	if a < 0:
		print(0)
		return
	a = str(bin(a))
	x = str(bin(x))
	a = a[2:]
	x = x[2:]
	l = len(a) - len(x)
	if l > 0:
		x = '0' * l + x
	else:
		a = '0' * -l + a
	res = 1
	for i in range(len(a)):
		if x[i] == '1' and a[i] == '0':
			res *= 2
		elif x[i] == '1' and a[i] == '1':
			print(0)
			return
	if flag:
		res -= 2
	print(res)

def __starting_point():
	(s, x) = list(map(int, input().split()))
	codechef(s, x)
__starting_point()


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	(s, x) = li()
	andval = (s - x) / 2
	if andval != int(andval) or s < x or int(andval) & x:
		print(0)
	else:
		w = andval
		andval = int(andval)
		andval = list(bin(andval)[2:])
		x = list(bin(x)[2:])
		s = andval[:]
		if len(x) > len(s):
			s = ['0'] * (len(x) - len(s)) + s
		else:
			x = ['0'] * (len(s) - len(x)) + x
		andval = s[:]
		ans = 0
		for i in range(len(s) - 1, -1, -1):
			if x[i] == '1':
				ans += 1
		ans = 2 ** ans
		if w == 0:
			ans -= 2
		print(ans)
t = 1
for _ in range(t):
	solve()


from sys import stdin, stdout
(r, w) = (stdin.readline, stdout.write)
(s, x) = map(int, r().split())
andShft = s - x
w('%i\n' % (0 if andShft & 1 or s < x or x & andShft >> 1 else 2 ** f'{x:b}'.count('1') - (2 if s == x else 0)))


(s, x) = list(map(int, input().split()))
f = 0
if s == x:
	f = -2
aa = s - x
if aa % 2 == 1 or aa < 0:
	print(0)
else:
	a = aa // 2
	out = 1
	for i in range(64):
		xx = x % 2
		aa = a % 2
		if xx == 1:
			out *= 2
			if aa == 1:
				out = 0
		x //= 2
		a //= 2
	print(out + f)


def o(s, x):
	d = s - x
	if x << 1 & d or d % 2 or d < 0:
		return 0
	return 2 ** bin(x).count('1') - (0 if d else 2)
(s, x) = map(int, input().split())
print(o(s, x))


def solutionB(s, x):
	if s == x <= 2 or s < x:
		return 0
	x_binary = bin(x)[2:]
	s_binary = bin(s)[2:]
	length_x = len(x_binary)
	length_s = len(s_binary)
	n = x_binary.count('1')
	num1 = list(x_binary)
	for i in range(length_s - len(num1)):
		num1.insert(0, '0')
	num2 = ['0' for c in range(len(num1))]
	found = False
	for i in range(length_s):
		if not int(num1[i]):
			num1[i] = '1'
			num2[i] = '1'
		sum_num = int(''.join(num1), 2) + int(''.join(num2), 2)
		if sum_num > s:
			num1[i] = '0'
			num2[i] = '0'
		elif sum_num == s:
			found = True
			break
	if found:
		if x != s:
			return 2 ** n
		else:
			return 2 ** n - 2
	else:
		return 0
(s, x) = input().split()
print(solutionB(int(s), int(x)))


import math
from collections import deque
import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(s, x) = mp()
if x > s:
	pr(0)
else:
	a = s - x
	if a & 1:
		pr(0)
	else:
		b = 0
		a //= 2
		if x & a != 0:
			pr(0)
		else:
			while x:
				b += x & 1
				x //= 2
			ans = pow(2, b)
			if a == 0:
				ans -= 2
			pr(ans)