Problem:
 Score : 400 points    Problem Statement Let f(A, B) be the exclusive OR of A, A+1, ..., B . Find f(A, B) .   What is exclusive OR?  The bitwise exclusive OR of integers c_1, c_2, ..., c_n (let us call it y ) is defined as follows:   When y is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if, the number of integers among c_1, c_2, ...c_m whose binary representations have 1 in the 2^k 's place, is odd, and 0 if that count is even.   For example, the exclusive OR of 3 and 5 is 6 . (When written in base two: the exclusive OR of 011 and 101 is 110 .)

Solution (Python):
A, B = [int(i) for i in input().split()]


def xor(a,b):
    sum=0
    i=0
    while(a>0 or b>0):
        sum += (2**i) * ((a%2 + b%2)%2)
        a = a//2
        b = b//2
        i += 1
    return sum



def f(n):
    m=(n+1)//2
    if n%2==0:
        if m%2==0:
            return n
        else:
            return n+1
    else:
        if m%2==0:
            return 0
        else:
            return 1

if A==0:
    print(f(B))
else:
    print(xor(f(A-1), f(B)))

Solution (Python):
A, B = [int(i) for i in input().split()]


def xor(a,b):
    sum=0
    i=0
    while(b>0):
        sum += (2**i) * ((a%2 + b%2)%2)
        a = a//2
        b = b//2
        i += 1
    return sum



def f(n):
    m=(n+1)//2
    if n%2==0:
        if m%2==0:
            return n
        else:
            return n+1
    else:
        if m%2==0:
            return 0
        else:
            return 1

if A==0:
    print(f(B))
else:
    print(f(A-1) ^ f(B))

Solution (Python):
A, B = map(int, input().split())


def get(x):
    return [x, 1, x + 1, 0][x % 4]


print(get(B) ^ get(A-1))

Solution (Python):
def func(a):
    if(0 == a % 4):
        return(a)
    if(1 == a % 4):
        return(1)
    if(2 == a % 4):
        return(a + 1)
    if(3 == a % 4):
        return(0)

A, B = list(map(int, input().split()))

print(func(A - 1) ^ func(B))

Solution (Python):
def f(n):
    rtn = ((n + 1) // 2) % 2
    for i in range(1, 40):
        if (n >> i) & 1 != 0:
            rtn |= ((n % (1 << i) + 1) % 2) << i
    return rtn


a, b = map(int, input().split())
ans = f(b)
if 0 < a:
    ans ^= f(a - 1)
print(ans)

Solution (Python):
A,B=[int(_) for _ in input().split()]
def fxor(a,b):
    return a^b

def fxorA2B(a,b,iD):
    def calcFD(g,b):
        return (g -1) //2 % 2 if b else g//2 % 2
    if a < b:
        if a == 2**iD :
            sB = bin(b)[2:][::-1]
            i2 = 2**iD -1
            bB = (b - i2)%2
            iC = 0
            for i in range(iD+1):
                iB = int(sB[i])
                if i == 0 and calcFD(b-i2,bB):
                    iC += 1
                elif iB and bB:
                    iC += 2**i
        else:
            a -= 1
            sA = bin(a)[2:][::-1]
            sB = bin(b)[2:][::-1]
            i2 = 2**iD -1
            bA = (a - i2)%2
            bB = (b - i2)%2
            iC = 0
            for i in range(iD+1):
                iA = int(sA[i])
                iB = int(sB[i])
                if i == 0 and calcFD(a-i2,bA) ^ calcFD(b-i2,bB):
                    iC += 1
                elif (iA and bA) ^ (iB and bB):
                    iC += 2**i
        return iC
    else:
        return a
def lenbin(X):
    return len(bin(X)) - 3
iA = lenbin(A)
iB = lenbin(B)
if iA == iB:
    print(fxorA2B(A,B,iA))
else:
    if iA == 0 :
        print(fxorA2B(2**iB,B,iB))
    else:
        print(fxorA2B(A,(2**(iA+1) - 1),iA)^fxorA2B(2**iB,B,iB))

Solution (Python):
A,B=map(int,input().split())

def solve(n):
    if n % 2 == 0:
        if n//2 %2 == 0:
            return n
        else:
            return n^1
    else:
        if (n+1) // 2 %2 == 0:
            return 0
        else:
            return 1

print(solve(A-1)^solve(B))

Solution (Python):
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:
    ans = xor_sum(a-1) ^ xor_sum(b)
    print(ans)

Solution (Python):
A, B = map(int, input().split())

def f(n):
    m = n % 4
    if m == 0:
        return n
    if m == 2:
        return n ^ 1
    if m == 1:
        return 1
    return 0

print(f(B) ^ f(A - 1))

Solution (Python):
import sys

[A,B] = list(map(int, input().split()))

if A == B:
    print(A)
    sys.exit(0)

ans = 0

if A % 2 == 0:
    if (B-A+1) % 4 in [2,3]:
        ans +=1
else:
    if (B-A+1) % 4 in [1,2]:
        ans += 1

for i in range(1, 64):

    a_k = (A >> i) & 1
    b_k = (B >> i) & 1

    a_index = A & ( (1 << i) - 1)
    b_index = B & ( (1 << i) - 1)

    count_bit = 0

    if B-A+1 <= (1 << i) - a_index:
        count_bit = a_k*(B-A+1)
    else:
        count_bit += a_k*( (1 << i) - a_index) 
        count_bit += b_k*(b_index+1)

    if count_bit % 2 == 1:
        ans |= (1 << i)

print(ans)

Solution (Python):
A, B = map(int, input().split())

def xor(n):
  if n % 2 == 0:
    if int(n / 2) % 2 == 0:
      return n
    else:
      return n ^ 1
  else:
    if int((n + 1) / 2) % 2 == 0:
      return 0
    else:
      return 1

if A == B:
  print(A)
else:
  print(xor(A - 1) ^ xor(B))

Solution (Python):
A, B = [int(x) for x in input().split()]

ans = A

for i in range(A + 1, 4 * (1 + A // 4)):
    ans = ans ^ i

for i in range(4 * (B // 4), B + 1):
    ans = ans ^ i

print(ans)

Solution (Python):
input=input()
num = input.split()
a=int(num[0])
b=int(num[1])
 
remainder=4-a%4
rva=a
rvb=0
dst=a+remainder-1
end=0;
if (dst >= b):
    dst=b
    end=1
 
for t in range(a, dst):
    rva = rva^(t+1)
 
if (end==0):
    remainder=b%4
    rvb=b-remainder
 
    for t in range(b-remainder, b):
        rvb = rvb^(t+1)
 
print(rva^rvb)

Solution (Python):
def f(a):
    if a%4 == 0:
        return a
    elif a%4 == 1:
        return 1
    elif a%4 == 2:
        return a^1
    elif a%4 == 3:
        return 0
A, B = list(map(int, input().split()))
print(f(A-1)^f(B))

Solution (Python):
A, B = map(int, input().split())
def f(x):
    if x % 4 == 0: return x
    elif x % 4 == 1: return 1
    elif x % 4 == 2: return x ^ 1
    elif x % 4 == 3: return 0
print(f(A - 1) ^ f(B))

Solution (Python):
import sys
from math import log, ceil, floor

fin = sys.stdin.readline
A, B = [int(elem) for elem in fin().split()]

def official_solution(A, B):
    def partial_f(n):
        if n == 0:
            return 0
        return ((n + 1) >> 1) & 1 if n & 1 else n | ((n >> 1) & 1)

    return partial_f(A - 1) ^ partial_f(B)


def naive_solution(A, B):
    def calc_num_bits(num):
        num_bits = 0
        while num:
            num_bits += 1
            num >>= 1
        return num_bits
    
    def partial_f(num):
        if num <= 0: return 0
        num_bits = calc_num_bits(num)
        result = ((num >> 1) + (num & 1)) % 2
        for d in range(1, num_bits):
            base = 1 << d
            rem = num % (base << 1)
            parity = max(0, rem - base + 1) & 1
            if parity:
                result |= base
        return result

    return partial_f(A - 1) ^ partial_f(B)

print(naive_solution(A, B))

Solution (Python):
def f(n):
    if (n+1) % 4 == 0:
        return 0
    if (n+1) % 4 == 1:
        return n
    if (n+1) % 4 == 2:
        return 1
    if (n+1) % 4 == 3:
        return n +1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Solution (Python):
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n +1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Solution (Python):
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())
ans = f(a-1) ^ f(b)
print(ans)

Solution (Python):
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())

print(f(a-1) ^ f(b))

Solution (Python):
import sys
from math import log, ceil, floor

fin = sys.stdin.readline
A, B = [int(elem) for elem in fin().split()]

def partial_f(n):
    if n == 0:
        return 0
    return ((n + 1) >> 1) & 1 if n & 1 else n | ((n >> 1) & 1)


print(partial_f(A - 1) ^ partial_f(B))

Solution (Python):
A, B = map(int, input().split())
 
def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0
print(f(B) ^ f(A-1))

Solution (Python):
A, B = map(int, input().split())

def f(x):
    if x % 4 <= 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0
print(f(B) ^ f(A-1))

Solution (Python):
A, B = map(int, input().split())

def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0
if A == B:
    print(A)
elif A == 0:
    print(f(B))
else:
    print(f(B) ^ f(A-1))

Solution (Python):
a, b = map(int, input().split())
def xor(p):
    if p % 4 == 0:
        return p
    elif p % 4 == 1:
        return 1
    elif p % 4 == 2:
        return p + 1
    elif p % 4 == 3:
        return 0
print(xor(a - 1) ^ xor(b))

Solution (Python):
p=[0]*42
q=[0]*42
x=1
a,b=map(int,input().split())
if a==b:
    print(a)
    exit()

a-=1
for i in range(42):
    if b//x<1: break
    if x==1:
        q[0]=((b+1)//2)%2
    else:
        q[i]=[0,((b+1)%x)%2][(b//x)%2]
    x*=2
x=1
for i in range(42):
    if a//x<1: break
    if x==1:
        p[0]=((a+1)//2)%2
    else:
        p[i]=[0,((a+1)%x)%2][(a//x)%2]
    x*=2
x=1
ans=0
for i in range(42):
    ans+=(p[i]^q[i])*x
    x*=2
print(ans)

Solution (Python):

A, B = map(int, input().split())



def g(a):
    m = a % 4
    return (
        a if m == 0 else
        1 if m == 1 else
        a + 1 if m == 2 else
        0
    )



ans = g(B) ^ g(A - 1) if A > 0 else g(B)


print(ans)

Solution (Python):
a,b = [int(i) for i in input().split()]
if a > 0:
  a=a-1
  if a%4==0:
    pass
  elif a%4==1:
    a=1
  elif a%4==2:
    a=a+1
  else:
    a=0
    
  if b%4==0:
    pass
  elif b%4==1:
    b=1
  elif b%4==2:
    b=b+1
  else:
    b=0

  print(a^b)

else:
  print(a^b)

Solution (Python):
A, B = map(int, input().split())

def main():
    d = B-A
    if d==0:
        return A
    elif d==1:
        return A^B
    elif A%2==1:
        if B%2==1:
            if d%4==0:
                return A
            else:
                return A^1
        else:
            if d%4==1:
                return A^B
            else:
                return A^1^B
    else:
        if B%2==1:
            if d%4==1:
                return 1
            else:
                return 0
        else:
            if d%4==0:
                return B
            else:
                return 1^B

print(main())

Solution (Python):
from functools import reduce


def exclusve_sum(x, y):
    return x^y

def calc_exclusive(a, b):
    """aは偶数であるとする"""
    if b - a <= 4:
        return reduce(exclusve_sum, [x for x in range(a, b + 1)])

    q, r = divmod(b - a, 4)
    rest = [a + 4 * q + r1 for r1 in range(0, r + 1)]
    ans = reduce(exclusve_sum, rest)
    return ans


if __name__ == "__main__":
    a, b = list(map(int, input().split(" ")))
    calc_exclusive(a, b)

    if a % 2 == 0:
        ans = calc_exclusive(a, b)
        print(ans)
    else:
        ans = a ^ calc_exclusive(a + 1, b)
        print(ans)

Solution (Python):
from functools import reduce
A, B =  map(int, (input().split(' ')))

def xor_sum(A,B):
        
    if A%2 == 0:
        if B%2 == 1:
            if (B - A + 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1) // 2 % 2 == 1:
                hoge = 1
            print(hoge)
        else:
            if (B - A + 1 - 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 1) // 2 % 2 == 1:
                hoge = 1
            print(hoge ^ B)
    else:
        if B%2 == 0:
            if (B - A + 1 - 2) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 2) // 2 % 2 == 1:
                hoge = 1
            print((A ^ hoge) ^ B)
        else:
            if (B - A + 1 - 1) // 2 % 2 == 0:
                hoge = 0
            if (B - A + 1 - 1) // 2 % 2 == 1:
                hoge = 1
            print(A ^ hoge)
            
xor_sum(A, B)

Solution (Python):
import numpy as np

A,B = map(int,input().split())

x = B - A + 1
A_ = bin(A)
B_ = bin(B)


A -= 1
digitsA = []
digitsB = []
for i in range(1,41):
    div = 2 ** i
    
    
    
    
    
    if(i == 1):
        if(A % 4 == 1 or A % 4 == 2):
            digitA = 1
        else:
            digitA = 0
        if(B % 4 == 1 or B % 4 == 2):
            digitB = 1
        else:
            digitB = 0
        
        digitsA.append(digitA)
        
        digitsB.append(digitB)
    else:
        itA = int(A / div)
        amariA = A % div
        itB = int(B / div)
        amariB=  B % div
        border = div / 2
        if(amariA >= border and (amariA % 2 == 0)):
            digitA = 1
        else:
            digitA = 0
        digitsA.append(digitA)
        if(amariB >= border and (amariB % 2 == 0)):
            digitB = 1
        else:
            digitB = 0
        digitsB.append(digitB)

num = 0
numA = 0
numB = 0


for i in range(40):
    num += np.logical_xor(digitsA[i],digitsB[i]) * (2 ** i)
    
    

print(num)
'''
while(1):
    div = 2 ** i 
    if(div > B):
        break
    A_ = int(A/div)
    B_ = int(B/div)
    a = (B_ - A_ + 1) % 2
    print(a)
    x.append(a)
    
    i += 1

num = 0
for i in range(len(x)):
    num += x[i] * (2 ** i)

print(num)
'''

Solution (Python):
if __name__ == '__main__':
    A, B = map(int, input().split())

    if A == B:
        print(A)
        exit()

    lower_4 = (A // 4 + 1) * 4
    upper_4 = (B + 1) // 4 * 4 - 1

    ans = 0
    for i in range(A, lower_4):
        ans ^= i

    for i in range(upper_4 + 1, B + 1):
        ans ^= i

    print(ans)

Solution (Python):
A, B = map(int, input().split())


def f(x):
    n = x % 4
    if n == 0:
        return x
    elif n == 1:
        return 1
    elif n == 2:
        return x + 1
    elif n == 3:
        return 0


print(f(A-1) ^ f(B))

Solution (Python):
A, B = map(int, input().split())
sa = B-A
if (A%2==0 and B%2 ==1):
    if(sa%4==1):
        ans = 1
    else:
        ans = 0
elif(A%2==0 and B%2==0):
    if(sa%4==2):
        ans = B+1
    else:
        ans = B
elif(A%2==1 and B%2 ==1):
    if(sa%4==2):
        ans = A-1
    else:
        ans = A
elif(A%2==1 and B%2 ==0):
    if(sa%4==1):
        ans = A^0^B
    else:
        ans = A^1^B
print(ans)

Solution (Python):
def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0

a, b = map(int, input().split())
print(f(a-1) ^ f(b))

Solution (Python):
a,b=map(int,input().split())

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=max(xor(b),xor(a-1))
  t=min(xor(a-1),xor(b))
  data=[]
  while s>0:
    data.append(s%2)
    s=s//2
  for i in range(len(data)):
    if (data[i] == t%2):
      data[i] = 0
    else:
      data[i] = 1
    t = t//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)

Solution (Python):
a,b = (int(i) for i in input().split())

def solve(n):
  if n%4 == 3:
    return 0
  elif n%4 == 1:
    return 1
  elif n%4 == 2:
    return 1 ^ n
  elif n%4 == 0:
    if n == 0: return 0
    else:
      return n
    

print(solve(b)^solve(a-1))

Solution (Python):

import sys

def main():
	A, B = map(int, input().split(" "))
	
	B0 = 0
	if B % 2 == 1:
		tmp = (B + 1) // 2
		if tmp % 2 == 1: B0 = 1
		else: B0 = 0
	else:
		tmp = B // 2
		if tmp % 2 == 1: B0 = 1
		else: B0 = 0
		B0 = B0 ^ B
		
	A0 = 0
	if (A-1) % 2 == 1:
		tmp = A // 2
		if tmp % 2 == 1: A0 = 1
		else: A0 = 0
	else:
		tmp = (A-1) // 2
		if tmp % 2 == 1: A0 = 1
		else: A0 = 0
		A0 = A0 ^ (A-1)
		
	print(B0 ^ A0)
		
if __name__ == "__main__":
	main()

Solution (Python):
a, b = map(int, input().split())
def f(i):
    if i == 0:
        return 1^(b-a-(1-a&1))//2%2
    x = a>>i
    y = b>>i
    return (x&1)*(a-x+1)%2^(y&1)*(b-y)%2
if a == b:
    print(a)
else:
    print(int(''.join(map(str, map(f, range(len(bin(b))-2))))[::-1], 2))

Solution (Python):
a, b = map(int, input().split())

if a == b:
    print(a)
elif b - a < 5:
    ans = a
    for i in range(b - a):
        ans = ans ^ (a + 1 + i)
    print(ans)
else:
    c = b - a + 1
    if a % 2 == 1:
        ans = a
        c -= 1
    else:
        ans = 0
    if b % 2 == 0:
        ans = ans ^ b
        c -= 1
    c //= 2
    ans = ans ^ (c % 2)
    print(ans)

Solution (Python):
a,b = map(int,input().split())

def f(x):
    i = 0
    res = 0 
    while (x>>i)>0:
        r = 1<<i
        if i == 0:
            if x%4 == 1 or x%4 == 2:
                res |= 1
            else:
                res |= 0
        else:
            d = x % (r<<1)
            if d >= r:
                res |= ((d-1)%2)<<i
        i += 1      
    return res

print(f(b)^f(a)^a)

Solution (Python):
def f(n):
    return [n, 1, n + 1, 0][n % 4]

def main():
    a, b = map(int, input().split())
    print(f(b) ^ f(max(0, a - 1)))

if __name__ == '__main__':
    main()

Solution (Python):
A, B = map(int, input().split())

def F(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return 1 ^ n
    else:
        return 0

print(F(A - 1) ^ F(B))

Solution (Python):
A, B = map(int, input().split())

def F(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n + 1
    else:
        return 0

print(F(A - 1) ^ F(B))

Solution (Python):

a,b = map(int, input().split())

def g(x):
    if x%2==1:
        return ((x+1)//2)%2
    else:
        return ((x//2)%2)^x

def f(a,b):
    return g(b) ^ g(a-1)

print(f(a,b))

Solution (Python):
def XOR_sum(n):
    m = n + 1
    if m % 4 == 0:
        return 0
    elif m % 4 == 1:
        return n
    elif m % 4 == 2:
        return 1
    else:
        return 1 ^ n
        

A, B = map(int, input().split())

a = XOR_sum(A - 1)
b = XOR_sum(B)

print(a ^ b)

Solution (Python):

A,B=map(int,input().split())
ruijo=[]
now=1
for j in range(51):
    ruijo.append(now)
    now*=2
if A==B:print(A)
else:
    if A>0:A-=1
    from collections import defaultdict
    data=defaultdict(int)
    one=[[0,1,1,0],[0,0,1,1]]
    data[1]=one[int(bin(A)[-1])][(B-A)%4]
    for i in range(2,1+len(bin(B)[2:])):
        Aidx=A%ruijo[i]
        Bidx=B%ruijo[i]
        if Aidx==Bidx:data[i]=0
        elif Aidx<Bidx:
            data[i]=(max(Bidx,ruijo[i-1]-1)-max(Aidx,ruijo[i-1]-1))%2
        elif Bidx<Aidx:
            data[i]=(max(ruijo[i-1]-1,Bidx)-(ruijo[i-1]-1)+ruijo[i]-1-max(ruijo[i-1]-1,Aidx))%2
    ans=0
    for x,y in data.items():
        ans+=ruijo[x-1]*y
    print(ans)

Solution (Python):
def xor(A,B):
    ruijo=[]
    now=1
    for j in range(51):
        ruijo.append(now)
        now*=2
    Astr=bin(A)[2:]
    Bstr=bin(B)[2:]
    Astr='0'*(max(len(Astr),len(Bstr))-len(Astr))+Astr
    Bstr='0'*(max(len(Astr),len(Bstr))-len(Bstr))+Bstr
    ans=0
    for i in range(1,len(Astr)+1):
        if Astr[-1*i]!=Bstr[-1*i]:
            ans+=ruijo[i-1]
    return ans
def fun(x):
    if x%2==0:res=x+1
    elif x%2==1:res=x-1
    ans=[x,1,res,0]
    return ans[x%4]
A,B=map(int,input().split())
if A==B:print(A)
elif A==0:print(fun(B))
else:
    print(xor(fun(A-1),fun(B)))

Solution (Python):
def xor(a,b):
    c=a-b+1
    flg1= a%2!=0
    flg2= b%2!=0
    flg3= int((c/2))%2!=0
    if a==b:
        return 1

    if not flg1 and flg2:
        if not flg3:
            return 0
        else:
            return 1
    elif not flg1 and not flg2:
        if not flg3:
            return b
        else:
            return 1^b
    elif flg1 and flg2:
        if not flg3:
            return a
        else:
            return a^1

    elif flg1 and not flg2:
        if not flg3:
            return b
        else:
            return 1^b




a,b = map(int, input().split())
print(xor(0,a-1)^xor(0,b))

Solution (Python):



def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0


A, B = map(int, input().split())
print(f(A) ^ f(B) ^ A)

Solution (Python):
def f(n):
    ans = 0
    if ((n%2)== 0) & ((n%4)==0):
        ans = n
    elif ((n%2)==0) & ((n%4)!=0):
        ans = 1+n
    elif ((n%2)!=0) & ((n%4)==1):
        ans = 1
    elif ((n%2)!=0) & ((n%4)==3):
        ans = 0
    return ans



A,B = map(int,input().split())
final_ans = 0

if A<0:
    print('a')
    print(f(B))
else:
    final_ans = f(A-1) ^ f(B)
    print(final_ans)

Solution (Python):



MX_KETA = 40
Bn = [0] * 40

def xor(n):
  As = [0] * 40
  if n % 4 in [1,2]:
    As[0] = 1
  for i in range(39):
    rem = (n+1)%(4*2**i)
    As[i+1] = max(0, rem-2*2**i) % 2
  return As

def solve(a,b):
  ans = 0
  for i in range(40):
    ans += (a[i]^b[i]) * 2**i
  return ans

A,B = map(int, input().split())
Ab = xor(A-1)
Bb = xor(B)
print(solve(Ab, Bb))

Solution (Python):
import itertools
import collections
import bisect


def calc(x, b):
    if b == 0:
        return x // 2 + x % 2
    base = 2 ** b
    if x < base:
        return 0

    
    if (x // base) % 2:
        if x // base == 1:
            return x % base + 1
        else:
            return base * ((x // base) // 2) + x % base + 1
    else:
        return base * (x // base) // 2


def main():
    A, B = map(int, input().split())

    bits = []
    for i in range(41):
        a = calc(max(0, A-1), i)
        b = calc(max(0, B), i)
        bits.append(abs(b - a) % 2)

    
    
    

    
    ans = 0
    for i in range(len(bits)):
        ans += bits[i] * (2 ** i)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
a, b = map(int, input().split())

def xor(n):
    if n % 4 == 0:
        return 0 ^ n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return 1 ^ n
    else:
        return 0
fa = xor(a - 1)
fb = xor(b)
print(fa ^ fb)

Solution (Python):
A, B = [int(_) for _ in input().split()]

if B - A < 4:
    y = A - 1
    x = 0
else:
    y = B - 4 - B % 4 + A % 4
    x = A if A % 2 else y
for i in range(y + 1, B + 1):
    x ^= i
print(x)

Solution (Python):
a,b=map(int,input().split())
if (a-1)%2==1:
  if a%4==0:x=0
  else:x=1
else:
  if (a-1)%4==0:x=a-1
  else:x=a
if b%2==1:
  if (b+1)%4==0:y=0
  else:y=1
else:
  if b%4==0:y=b
  else:y=b+1
print(x^y)

Solution (Python):
def G(x):
  ret = 0
  for i in range(x-x%4,x+1):
    ret ^= i
  return ret

A, B = map(int, input().split())
print(G(B)^G(A-1))

Solution (Python):
a,b=map(int,input().split())
r=0
if a%2==1:
    r=a
    a+=1
if a<=b:
    x,y=divmod(b-a+1,2)
    r^=x%2^b*y
print(r)

Solution (Python):
a, b = (int(i) for i in input().split())  

def f(a, b):
    num_len = b-a+1

    if num_len == 1:
        return b

    one_check = num_len if a % 2 == 0 else num_len-1

    x = (one_check // 2) % 2
    y = b if one_check % 2 == 1 else 0
    z = 0 if a % 2 == 0 else a
    return x^y^z

print(f(a,b))

Solution (Python):
A, B = map(int, input().split())







B_ans = 0
for i in range(B % 4+1):
    B_ans = B_ans ^ (B - i)
    
A_ans = 0
for i in range((A - 1) % 4 + 1):
    
    A_ans = A_ans ^ (A-1 - i)

print(A_ans ^ B_ans)

Solution (Python):
def binary(n):
    l = [0] * 40
    for i in range(39,-1,-1):
        if n >= 2 ** i:
            l[i] = 1
            n = n - 2 ** i
        else:
            l[i] = 0
    
    return l

def xor_plus(l1,l2):
    l = [0] * 40
    for i in range(0,40):
        if l1[i] == l2[i]:
            l[i] = 0
        else:
            l[i] = 1
    return l

def xor_sum(n):
    result = [0] * 40
    if n % 4 == 1:
        result[0] = 1
    elif n % 4 == 0:
        result = binary(n)
    elif n % 4 == 2:
        result = xor_plus(binary(1),binary(n))
        
    return result

a, b = map(int, input().split())

fa = xor_sum(a-1)
fb = xor_sum(b)

fab = xor_plus(fa,fb)

x = 0

for i in range(0,40):
    x = x + fab[i] * (2 ** i)
    
print(x)

Solution (Python):
A,B=map(int,input().split())
A=max(0,A-1)
P=[2**i for i in range(41)]
i=0
ans=0
while P[i]<=B:
  q=((B+1)//P[i])
  r=(B+1)%P[i]
  Q=((A+1)//P[i])
  R=(A+1)%P[i]
  coB=(q//2)*P[i]+[0,r][q%2]
  coA=(Q//2)*P[i]+[0,R][Q%2]
  if (coB-coA)%2==1:
    ans+=P[i]
  i+=1
print(ans)

Solution (Python):
def f(n):
  if n%4 == 0: return n
  if n%4 == 1: return 1
  if n%4 == 2: return n+1
  return 0

a, b = map(int, input().split())
print(f(a-1)^f(b))

Solution (Python):
A, B = map(int, input().split())
if A % 2 == 0:
    num = B - A
    result = 0
else:
    num = (B - (A + 1))
    result = A
if num // 2 % 2 == 0:
    result ^= 0
else:
    result ^= 1
if num % 2 == 1:
    result ^= (B-1)
result ^= B
print(result)

Solution (Python):
import numpy as np

def calc(i,x):
    if i ==0:
        return int((x % 4 == 1) or (x % 4 == 2))
    else:
        return int((x % (2**(i+1)) >= 2**i) and (x % 2 == 0))

def main():
    A,B = map(int, input().split())
    
    
    ans = 0
    for i in range(41):
        ans += 2**i*(calc(i,A-1)^calc(i,B))
    print(ans)
    
main()

Solution (Python):
A, B = map(int, input().split())

def f(x):
    
    xi = (x >> 2) << 2
    xlsb2 = x & 0x3

    if xlsb2 == 0:
        return(xi)
    elif xlsb2 == 1:
        return(1)
    elif xlsb2 == 2:
        return(xi + 3)
    else:
        return(0)

print(f(A-1) ^ f(B))

Solution (Python):
(a,b) = map(int, input().split())
xs = []
if a % 2 == 1:
    xs.append(a)
    a = a+1
if b % 2 == 0:
    xs.append(b)
    b = b-1

if (b-a+1)//2 % 2 == 1:
    xs.append(1)

ans = 0
for x in xs:
    ans = ans ^ x

print(ans)

Solution (Python):
A, B = map( int, input().split())
A -= 1
TA = [0]*41
TB = [0]*41
if A%4 == 1 or A%4 == 2:
    TA[0] = 1
if B%4 == 1 or B%4 == 2:
    TB[0] = 1
for i in range(40,0,-1):
    if 2**i <= A:
        TA[i] = (A - 2**i +1)%2
        A -= 2**i
    if 2**i <= B:
        TB[i] = (B - 2**i + 1)%2
        B -= 2**i
a = 0
b = 0
for i in range(41):
    a += TA[i]*(2**i)
    b += TB[i]*(2**i)
print(a^b)

Solution (Python):
A,B = map(int, input().split())
if A != 0:
    A = A-1

def ruiseki_XOR(N):
    if (N+1) % 2 == 0:
        if ((N+1)//2) % 2 == 0:
            return 0
        else:
            return 1
    else:
        if ((N+1)//2) % 2 == 0:
            return N
        else:
            return 1^N


a = ruiseki_XOR(A)
b = ruiseki_XOR(B)

print(a^b)

Solution (Python):
A, B = map(int, input().split())

xor = [0, 1, 3]

def cal(n, flag=False):
    if n == 0:
        return 0
    else:
        if flag:
            n -= 1
        if n  < 3:
            return xor[n]
        else:
            amari = (n - 3) % 4
            if amari == 0:
                return 0
            elif amari == 1:
                return n
            elif amari == 2:
                return 1
            elif amari == 3:
                return n ^ 1
        
print(cal(A, flag=True) ^ cal(B))

Solution (Python):
from collections import Counter
import numpy as np

A,B = map(int, input().split())
if A != 0:
    A = A-1

def ruiseki_XOR(N):
    if (N+1) % 2 == 0:
        if ((N+1)//2) % 2 == 0:
            return 0
        else:
            return 1
    else:
        if ((N+1)//2) % 2 == 0:
            return N
        else:
            return 1^N


a = ruiseki_XOR(A)
b = ruiseki_XOR(B)

print(a^b)

Solution (Python):
def get(A):
    return [A, 1, 1 ^ A, 0][A % 4]


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


A, B = inpl()

print(get(A - 1) ^ get(B))

Solution (Python):

import copy
import numpy as np
import random

a,b = map(int,input().split())

def function(n):
    if n==0 or n==1:
        return n
    else:
        if n%4==0:
            return n
        elif n%4==1:
            return 1
        elif n%4==2:
            return n+1
        else:
            return 0

if a==0:
    print(function(b))
    exit()

else:
    print(function(a-1)^function(b))





'''

def F(n):
    if n==0:
        tmp_ans = 0
    else:
        true_count = (n+1)//2
        if (n+1)%2==0:
            if true_count%2==0:
                tmp_ans = 0
            else:
                tmp_ans = 1
        else:
            if true_count%2==0:
                tmp_ans = n
            else:
                if n%2==0:
                    tmp_ans = n+1
                else:
                    tmp_ans = n-1

    return tmp_ans

max_digit = 0
num = b
while num > 0:
    max_digit += 1
    num = num//2

a_digits= []
b_digits = []
digits = []

A = F(a-1)
B = F(b)

for i in range(max_digit):
    a_digits.append(A%2)
    b_digits.append(B%2)
    A = A//2
    B = B//2

for i in range(max_digit):
    if (a_digits[i] == 1 and b_digits[i] == 1) or (a_digits[i] == 0 and b_digits[i]==0):
        digits.append(0)
    else:
        digits.append(1)

ans = 0
for i in range(max_digit):
    ans += digits[i]*2**i

print(ans)
'''
'''
if a == b:
    print(a)
    exit()

def xor_0(a,b):
    if((b-a+1)//2)%2 == 0:
        if (b-a+1)%2==0:
            digit = 0
        else:
            if a%2==0:
                
                digit = 1
            else:
                
                digit = 1
    else:
        if (b-a+1)%2==0:
            digit = 1
        else:
            if a%2==0:
                
                digit = 1
            else:
                
                digit = 0

    return digit

max_digit = 0
num = b
while num > 0:
    max_digit += 1
    num = num//2

def digit_xor(a,b,i):
    if i == 0:
        return xor_0(a,b)
    else:
        count = 0
        posi_a = a%(2**(i+1))
        if posi_a>2**i:
            count += 2**i-a+1
        elif posi_a==0:
            pass
        else:
            count += 2**i

        posi_b = b%(2**(i+1))
        if posi_b > 2**i:
            count += 2**i
        else:
            count += posi_b

    if count%2==0:
        return 0
    else:
        return 1


digits = []
for i in range(max_digit):
    digits.append(digit_xor(a,b,i))

ans = 0
print(digits)
for i in range(len(digits)):
    ans += digits[i]*2**i

print(ans)
'''

Solution (Python):



A, B = map(int, input().rstrip().split(' '))

if A == B:
    print(A)
    
else:
    max_bit = 0
    copied_B = B
    while copied_B > 0:
        copied_B = copied_B // 2
        max_bit += 1
    
    count = 0
    for digit in range(max_bit):
        period = 2 ** (digit + 1)
        pos_A = A % period
        pos_B = B % period
        
        num_one = 0
        if pos_A >= period // 2:
            num_one += period - pos_A
        else:
            num_one += period // 2
         
        if pos_B >= period // 2:
            num_one += pos_B - period // 2 + 1
            
        if digit == 0:
            num_one = 0
            num_one += B % 2
            num_one += A % 2
            if B % 2 == 1 and A % 2 == 1:
                num_one += (B - A - 1) // 2
            else:
                num_one += (B - A) // 2
            
        if num_one % 2 != 0:
            count += 2 ** digit
         
    print(count)