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())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def f_bit_count(A, bit):
    if A <= 0:
        return 0
    C = A + 1
    if C < 2 ** bit:
        return 0
    b = 2L**(bit + 1)
    count = (C/b) * (2L ** bit)
    if C % b != 0 and C % b > (2L ** bit):
        count += (2L ** bit) - (b - C % b)

    return count

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B] = [long(input_raw[0]), long(input_raw[1])]

    ans  = 0L
    for bit in range(42):
        B_count = f_bit_count(B, bit)
        A_count = f_bit_count(A - 1, bit)
        if (B_count - A_count) % 2 == 1:
            ans += 1 << bit;
    print ans



if __name__ == '__main__':
    main()

Solution (Python):
A,B = map(int,input().split())
S = 0
if B-A <= 20:
  for i in range(A,B+1):
    S ^= i
  print(S)
else:
  if A%4 == 1:
    S ^= A
    S ^= A+1
    S ^= A+2
    S ^= A+3
    S ^= A+4
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i]%4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  elif A%4 == 2:
    S ^= A
    S ^= A+1
    S ^= A+2
    S ^= A+3
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  elif A%4 == 3:
    S ^= A
    S ^= A+1
    S ^= A+2
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  else:
    S ^= A
    S ^= A+1
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)

Solution (Python):
a,b=[int(s) for s in input().split()]
n=b-a+1
def odd(x):
    return x&1 == 1
def even(x):
    return not odd(x)
if odd(a) and odd(b) and odd((n-1)//2):
    print(a^1)
if odd(a) and odd(b) and even((n-1)//2):
    print(a)
if odd(a) and even(b) and odd((n-1)//2):
    print((a^b)^1)
if odd(a) and even(b) and even((n-1)//2):
    print(a^b)
if even(a) and odd(b) and odd((n-1)//2):
    print(0)
if even(a) and odd(b) and even((n-1)//2):
    print(1)
if even(a) and even(b) and odd((n-1)//2):
    print(b^1)
if even(a) and even(b) and even((n-1)//2):
    print(b)

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

base = 2
ans = ''
if a == 0 and b == 0:
  print(0)
else:
  while base // 2 <= b:
    nb = (b // base) * (base // 2)
    na = (a // base) * (base // 2)
    if b % base != 0:
      nb += max(0, b % base - (base // 2) + 1)
    if a % base != 0:
      na += max(0, (a - 1) % base - (base // 2) + 1)
    if (nb - na) % 2 == 1:
      ans += '1'
    else:
      ans += '0'
    base *= 2
  print(int(ans[::-1], 2))

Solution (Python):
def xorsum(n):
	return (1 if n & 1 else n) ^ ((n >> 1) & 1)

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

if 0 < A:
	print(xorsum(B) ^ xorsum(A-1))
else:
	print(xorsum(B))

Solution (Python):


def calc_bin(bin_data):
    sum_bin = ''
    for i in range(len(bin_data)):
        now_data = bin_data[i]
        if now_data == '0':
            if i == len(bin_data) - 1:
                if len(bin_data) == 1:
                    add_data = '0'
                else:
                    if bin_data[-2] == '0':
                        add_data = '0'
                    else:
                        add_data = '1'
            else:
                add_data = '0'
        else:
            if i == len(bin_data) - 1:
                if len(bin_data) == 1:
                    add_data = '1'
                else:
                    if bin_data[-2] == '0':
                        add_data = '1'
                    else:
                        add_data = '0'
            elif bin_data[-1] == '0':
                add_data = '1'
            else:
                add_data = '0'
        sum_bin += add_data
    return sum_bin

def calc_ans(a_sun_bin, b_sum_bin):
    a_sun_bin_rev = a_sun_bin[::-1]
    b_sun_bin_rev = b_sum_bin[::-1]
    ans = ''
    for i in range(len(b_sun_bin_rev)):
        if i >= len(a_sun_bin_rev):
            a_data = '0'
        else:
            a_data = a_sun_bin_rev[i]
        b_data = b_sun_bin_rev[i]
        if a_data == b_data:
            add_ans = '0'
        else:
            add_ans = '1'
        ans += add_ans
    ans = ans[::-1]
    return ans


def main():
    a, b = map(int, input().split())
    a_bin = bin(a - 1)[2:]
    b_bin = bin(b)[2:]
    
    
    

    a_sun_bin = calc_bin(a_bin)
    b_sun_bin = calc_bin(b_bin)
    
    
    ans_bin = calc_ans(a_sun_bin, b_sun_bin)
    
    print(int(ans_bin, 2))



if __name__ == '__main__':
    main()

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

array = []
bin_B = bin(B)[2:]
digit_B = len(bin_B)

if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    if B % 4 == 1 or B % 4 == 2:
        array.append('0')
    else:
        array.append('1')
else:
    if B % 4 == 1 or B % 4 == 2:
        array.append('1')
    else:
        array.append('0')

for i in range(2, digit_B+1):
    num = 2 ** i
    if (A-1) % num < (num // 2) or ((A-1) % num) % 2 == 1:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('0')
        else:
            array.append('1')
    else:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('1')
        else:
            array.append('0')

array.reverse()
result = ''
for i in array:
    result += i

print(int(result, 2))

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

c = []
if a%2 == 0:
    if b%2 == 0:
        
        c = [int(((b - 1 - a + 1)/2)%2), b]
    else:
        
        c = [int(((b - a + 1)/2)%2)]
else:
    if b%2 == 0:
        
        c = [a, (int((b - a)/2)%2), b]
    else:
        
        c = [a, int(((b + 1 - a)/2)%2)]

d = 0
for cc in c:

    d += int(bin(cc)[2:])
    d = str(d)
    d = d.replace('2', '0')
    d = int(d)
    
print(int(str(d), 2))

Solution (Python):
import sys

def f(a):
    A = [0] * 40
    for i in range(40):
        if a >= 2**i:
            b = a // 2**(i+1) * 2**i
            c = max(0, a % 2**(i+1) - 2**i + 1)

            if (b+c) % 2 == 1:
                A[i] = 1
        else:
            break
    return A



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

    X = f(A-1)
    Y = f(B)
    ans = 0
    for i in range(40):
        if X[i] == 0 and Y[i] == 0:
            continue
        if X[i] * Y[i] == 0:
            ans += 2**i

    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
stride = 2
fcnt = 0
a,b = A,B
if b % 2 ==  1:
  fcnt += 1
  b -= 1
if a % 2 == 1:
  fcnt += 1
  a += 1
fcnt += (b-a+1)//2
if fcnt % 2 == 1:
  ans |= 1




for i in range(50):
  stride <<= 1
  
  a,b = A,B
  cnt = 0
  
  
  if a%stride >= stride // 2: 
    
    cnt += stride - (a%stride)
    a   += stride - (a%stride)
    
  else: 
    a -= (a%stride)
  
  if b % stride >= stride // 2: 
    
    cnt += ((b%stride))+1
    b += stride - (b%stride)
  else:
    b -= b %stride
  
  
  if cnt % 2 == 1:
    ans |= stride//2 
  
print(ans)

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

def xor_sum(N):
    mod4 = N % 4
    if mod4 == 0:
        return N
    elif mod4 == 1:
        return 1
    elif mod4 == 2:
        return N + 1
    else: 
        return 0

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

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

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

ans = 0
a = 0
b = 0
for i in range(41):
    j = 40-i
    if (A-1)&(1<<j):
        a = j
        break

for i in range(41):
    j = 40-i
    if B&(1<<j):
        b = j
        break

def bit(N,n,bi):
    if bi==0:
        return (N+1)//2
    if N==-1 or (n<bi):
        return 0
    num = 0
    c = 0
    for i in range(bi+1):
        if N&(1<<i):
            num += (1<<i)
    c += max(num-((1<<bi)-1),0)
    c += (n-bi)*((1<<(bi)))
 
    return c


for i in range(b+1):
    j = b-i
    c = 0
    c = bit(B,b,j)-bit(A-1,a,j)
    if c%2==1:
        ans += (1<<j)
print(ans)

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






ans = []

if a%2 ==1:
  if (b-a+1)%4 ==1:
    ans.append("1") 
  elif (b-a+1)%4 ==2:
    ans.append("1") 
  elif (b-a+1)%4 ==3:
    ans.append("0") 
  elif (b-a+1)%4 ==0:
    ans.append("0") 
else:
  if (b-a+1)%4 ==1:
    ans.append("0") 
  elif (b-a+1)%4 ==2:
    ans.append("1") 
  elif (b-a+1)%4 ==3:
    ans.append("1") 
  elif (b-a+1)%4 ==0:
    ans.append("0") 
    
for i in range(1,100):
    cnt_a=a-(a//(2**i))*(2**i)
    cnt_b=b-(b//(2**i))*(2**i)+1
    
    if (((a//(2**i))*(2**i))//(2**i))%2 ==1 and (((b//(2**i))*(2**i))//(2**i))%2 ==1:
      ans.append(str((cnt_a+cnt_b)%2))

    elif (((a//(2**i))*(2**i))//(2**i))%2 ==0 and (((b//(2**i))*(2**i))//(2**i))%2 ==0:
      ans.append("0") 

    elif (((a//(2**i))*(2**i))//(2**i))%2 ==0 and (((b//(2**i))*(2**i))//(2**i))%2 ==1:
      ans.append(str((cnt_b)%2))

    else:
      ans.append(str((cnt_a)%2))

     
res = 0

for i in range(len(ans)):
  if ans[i]=="1":
    res = res + 2**i
print(res)

Solution (Python):
a,b = map(int,input().split())
def h(a,b,n):
  k = 2**n
  x = a%k
  y = b%k
  l = 2**(n-1)
  if x<l and y<l:
    return(0)
  elif x < l and y >= l:
    z = y%2
    return(-z+1)
  elif x >= l and y < l:
    z = x%2
    return(z)
  else:
    z = (y-x)%2
    return(-z+1)
ll = len(bin(b)[2:])
res = []
if b%2 == 1:
  if (b-a+1)%4 in [0,3]:
    res.append(0)
  else:
    res.append(1)
else:
  if (b-a+1)%4 in [0,1]:
    res.append(0)
  else:
    res.append(1)
for i in range(1,ll):
  res.append(h(a,b,i+1))
ans = 0
for j in range(ll):
  ans += res[j]*(2**j)
print(ans)

Solution (Python):
def count_bit(k, upto):
  
  if k == 0:
    if upto % 4 in [0,3]:
      return 0
    else:
      return 1
  base = 2 ** k
  
  upto = upto % (base * 2)
  
  if upto  < base:
    return 0
  upto -= (base-1)
  
  return upto % 2

def solve(a, b):
  k = 0
  kk = 2 ** k
  val = 0
  while b >= kk:
    ak = count_bit(k, a-1)
    bk = count_bit(k, b)
    
    val += 2 ** k * (ak ^ bk)
    k += 1
    kk = 2 ** k
  return val

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

ans = solve(a, b)
print(ans)

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

Bit = [0] * 40
ai, aj, bi, bj = A//2, A%2, B//2, B%2
one = (bi - ai) + bj
Bit[0] = one % 2

for i in range(1, 40):
    two = 2 ** i
    ai, aj = A // two, A % two
    bi, bj = B // two, B % two
    if ai == bi and ai % 2 == 1: Total = bj - aj + 1
    else:
        Total = 0
        if ai % 2 == 1:
            Total +=  two - aj
        if bi % 2 == 1:
            Total +=  bj + 1
    if Total % 2 == 1: Bit[i] = 1
Ans = 0
for i in range(40):
    if Bit[i] == 1: Ans += 2 ** i
print(Ans)

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


def judge(x, phase):
    if x < phase // 2 or (x - phase // 2) % 2 == 1:
        return 0
    else:
        return 1


result = []

if (B // 2 + B % 2 - ((A - 1) // 2 + (A - 1) % 2)) % 2 == 0:
    result.append("0")
else:
    result.append("1")

for i in range(2, len(bin(B)[2:]) + 1):
    phase = 2**i
    b = B % phase
    a = (A - 1) % phase
    if judge(a, phase) == judge(b, phase):
        result.append("0")
    else:
        result.append("1")

result.reverse()
print(int("".join(result), 2))

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

def mark(x, v):
    if x%4 in [1,2]:
        v[0] = 1
    for i in range(1,40):
        p = 2**(i+1)
        if x%p >= p/2 and (x%p - p/2-1)%2 == 1:
            v[i] = 1

a = [0] * 40
if A >= 2:
    mark(A-1, a)

b = [0] * 40
mark(B, b)

ans = 0
for i in range(40):
    if a[i]^b[i]:
        ans += 2**i

print(ans)

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

if A == B:
    print(A)

elif A % 2 == 0:
    if B % 2 == 0:
        if ((B - 1) - A + 1)/2 % 2 == 0:
            print(B)
        else:
            print(B^1)
    else:
        if (B - A + 1)/2 % 2 == 0:
            print(0)
        else:
            print(1)

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

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

def f(a):
    res = [a,1,a+1,0]
    return res[a%4]

def getXor(a, b):
    print(f(b)^f(a-1))

getXor(A, B)

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


def count1(n, bit):
    r = (n+1) % (2*bit)
    cnt = (n+1-r) // 2
    if r <= bit:
        return cnt
    else:
        return cnt + r - bit

res = ''
bits = [2**i for i in range(40)][::-1]
for bit in bits:
    diff = count1(B, bit) - count1(A-1, bit)
    if diff%2 == 0:
        res += '0'
    else:
        res += '1'
print(int(res, 2))

Solution (Python):

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

Alis = []
Blis = []

for n in range(1,41) :
    temp = (A // 2**n)*(2**(n-1))
    t2 = A%(2**n)
    if t2 >= 2**(n-1):
        t2 %= 2**(n-1)
        t2 += 1
        temp += t2
    Alis.append(temp)

for n in range(1,41) :
    temp = (B // 2**n)*(2**(n-1))
    t2 = B%(2**n)
    if t2 >= 2**(n-1):
        t2 %= 2**(n-1)
        t2 += 1
        temp += t2
    Blis.append(temp)

res = 0
for n in range(len(Alis)) :
    res += (2**n)*((Blis[n] - Alis[n])%2)
print(res)

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

Solution (Python):
from collections import defaultdict
import math


def f(n, k):
    base = 2 ** k
    syou = n // base
    amari = n % base
    q = max(0, amari - (base // 2) + 1)
    res1 = syou * (base // 2) + q
    return res1 % 2


def g(n):  
    if n <= 0:
        return "0"
    keta = int(math.log2(n) + 1)
    s = ""
    for i in range(keta):
        s = str(f(n, i + 1)) + s
    return s


def xor(a, b):
    max_len = max(len(a), len(b))
    a = (("0" * max_len) + a)[-max_len:]
    b = (("0" * max_len) + b)[-max_len:]

    s = ""
    for i in range(max_len):
        if a[i] != b[i]:
            s += "1"
        else:
            s += "0"
    return s


def to10(s):
    res = 0
    for c in s:
        res *= 2
        if c == "1":
            res += 1
    return res


def main():
    n, m = [int(q) for q in input().split()]
    A = g(n - 1)
    B = g(m)
    res = xor(A, B)
    print(to10(res))


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import math

import array
import bisect
import collections
from collections import Counter, defaultdict
import fractions
import heapq
import re

sys.setrecursionlimit(1000000)


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

def argsort(l, reverse=False):
    return sorted(range(len(l)), key=lambda i: l[i], reverse=reverse)

def argmin(l):
    return l.index(min(l))

def YESNO(ans, yes="YES", no="NO"):
    print([no, yes][ans])

II = lambda: int(input())
MI = lambda: map(int, input().split())
MIL = lambda: list(MI())
MIS = lambda: input().split()


def prev_multi(num, multi):
    return math.floor(num / multi) * multi

def next_multi(num, multi):
    return math.ceil(num / multi) * multi


def main():
    A, B = MI()
    if B == 0: return 0
    ans = (math.ceil(B/2) - math.floor(A/2)) % 2
    for i in range(1, math.ceil(math.log2(B)) + 1):
        p = 2**i

        na = next_multi(A, p)
        if (na > B):
            d = 0 if (na / p) % 2 else B - A + 1
        else:
            da = 0 if (na / p) % 2 else na - A
            pb = prev_multi(B, p)
            db = 0 if (pb / p) % 2 == 0 else B - pb + 1
            d = da + db
        ans += d % 2 * p

    return ans

if __name__ == "__main__":
    print(main())

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



def f0_n(B,n):
    if n==1:
        return  ((B+1)//2)%2


    B=(B+1)%(2**n)
    if B<=2**(n-1):
        return 0
    else:
        B-=2**(n-1)
        return B%2



def f0(B):
    retval=""
    for n in range(1,len(bin(B).replace("b",""))+10):
        retval+=str(f0_n(B,n))
    retval=retval[::-1]
    return int(retval,2)


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

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    a,b = map(int, input().split())
    if b == 0:
        print(0)
        exit()
    if a == 0:
        a = 1
    a -= 1
    bb = format(b, 'b')
    ba = format(a, 'b')
    def bin_sum(a):
        empty = []
        bottom = a[-1]
        try:
            two = (int(a[-2])+int(a[-1]))%2
        except IndexError:
            two = int(a[-1])%2
        for i in a:
            if bottom == '0' and i == '1':
                empty.append('1')
            else:
                empty.append('0')
        empty[-1] = str(two)
        return empty
    sum_bb = bin_sum(bb)
    sum_ba = bin_sum(ba)
    sum_ba = ['0']*(len(sum_bb)-len(sum_ba)) + sum_ba
    sum_all = []
    for i,j in zip(sum_ba, sum_bb):
        if i == j:
            sum_all.append('0')
        else:
            sum_all.append('1')
    str_sum_all = ''.join(sum_all)
    print(int(str_sum_all,2))

Solution (Python):




def main():
  a, b = map(int, input().split())
  x = a

  if b - a > 4:
    for y in range(a + 1, a + 5):
      x ^= y
      a += 1

      if x == 0:
        break

    a += ((b - a) // 4) * 4

  for y in range(a + 1, b + 1):
    x ^= y

  print(x, flush=True)


if __name__ == '__main__':
  main()

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

A,B=rl()
A -= 1

a2 = format(A,'b')
al = len(a2)
b2 = format(B,'b')
bl = len(b2)


bc = [0]*bl
bc[0] += (B+1)//2
bc[0] -= (A+1)//2
for i in range(1,bl):
    bc[i] += (B+1)//(2**(i+1))*(2**i) + max(0, (B%(2**(i+1)) - (2**i-1)))
    bc[i] -= (A+1)//(2**(i+1))*(2**i) + max(0, (A%(2**(i+1)) - (2**i-1)))

ans = 0
for i in range(bl):
    if bc[i]%2==1:
        ans += 2**i

print(ans)

Solution (Python):
A,B=map(int,input().split())
two=[2**i for i in range(2,41)]

def func(C):
	ret=''
	for t in two[::-1]:
		if (C%t)>=t//2 and (C%t)%2==0:
			ret+='1'
		else:
			ret+='0'
	if (C%4)==1 or (C%4)==2:
		ret+='1'
	else:
		ret+='0'
	return ret
print(int(func(A-1),2)^(int(func(B),2)))

Solution (Python):
a, b = list(map(int, input().split()))
bin_b = bin(b)[2:]
bin_a = bin(a)[2:].zfill(len(bin_b))
ans = []
for i in range(len(bin_b)):
    cnt = b-a+1
    d = {-1:0,1:0}
    ai = bin_a[-(i+1)]
    if ai == "0":
        ai = -1
    else:
        ai = 1
    if i == 0:
        hoge = 0
        if ai == 1:
            hoge = (cnt+1)//2
        else:
            hoge = cnt//2
        if hoge%2:
            ans.append(1)
        else:
            ans.append(0)
        continue
    ai_1 = int(bin_a[-i:],2) if i >0 else 0
    start = 2**i - ai_1
    if start >= cnt:
        d[ai] += cnt
        cnt = 0
    else:
        d[ai] += start
        cnt -= start
    ai *= -1
    hoge = cnt//(2**i)
    fuga = cnt % (2**i)
    if hoge%2:
        ai *= -1
    d[ai] += fuga
    if d[1]%2:
        ans.append(1)
    else:
        ans.append(0)
e = int("".join(map(str,ans[::-1])), 2)
print(e)

Solution (Python):
def xorsum(n):
	if n & 1:
		return 1 - ((n >> 1) & 1)
	return n | ((n >> 1) & 1)

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

if 0 < A:
	print(xorsum(B) ^ xorsum(A-1))
else:
	print(xorsum(B))

Solution (Python):
a, b = [int(i) for i in input().split()]
ans = ""
for i in range(1,41)[::-1]:
    if a == 0:
        ans += str(((b- b%(2**i))//2 + max(b%(2**i)- 2**(i-1)+ 1,0))%2)
    else:
        ans += str((((b- b%(2**i))//2 + max(b%(2**i)- 2**(i-1)+ 1,0)) - (((a-1)- (a-1)%(2**i))//2 + max((a-1)%(2**i)- 2**(i-1)+1,0)))%2)
print(int(ans,2))

Solution (Python):
A, B = map(int, input().split())
digits = len(format(B, 'b'))
A -= 1
ans = 0
for k in range(digits):
    na = (A // (2 << k)) * (1 << k) + max(0, A % (2 << k) - (1 << k) + 1)
    nb = (B // (2 << k)) * (1 << k) + max(0, B % (2 << k) - (1 << k) + 1)
    x = (nb - na) % 2
    ans += x << k

print(ans)

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

if B-A==0:
    ans = A
elif B-A==1:
    ans = A ^ B
elif B-A==2:
    ans = A ^ (A+1) ^ B
elif B-A==3:
    ans = A ^ (A+1) ^ (A+2) ^ B
else:
    if A%4==0:
        mod = (B-A+1)%4
        if mod==0:
            ans=0
        elif mod==1:
            ans=B
        elif mod==2:
            ans=B^(B-1)
        elif mod==3:
            ans=B^(B-1)^(B-2)
    elif A%4==1:
        ans = A^(A+1)^(A+2)
        mod = ((B-A+1)-3)%4
        if mod==0:
            ans = ans
        elif mod==1:
            ans = ans ^ B
        elif mod==2:
            ans = ans ^ B ^ (B-1)
        elif mod==3:
            ans = ans ^ B ^ (B-1) ^ (B-2)
    elif A%4==2:
        ans = A^(A+1)
        mod = ((B-A+1)-2)%4
        if mod==0:
            ans = ans
        elif mod==1:
            ans = ans ^ B
        elif mod==2:
            ans = ans ^ B ^ (B-1)
        elif mod==3:
            ans = ans ^ B ^ (B-1) ^ (B-2)
    elif A%4==3:
        ans = A
        mod = ((B-A+1)-1)%4
        if mod==0:
            ans = ans
        elif mod==1:
            ans = ans ^ B
        elif mod==2:
            ans = ans ^ B ^ (B-1)
        elif mod==3:
            ans = ans ^ B ^ (B-1) ^ (B-2)
            
print(ans)

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


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

if a == b:
    print(a)
elif a == 0:
    print(xo(b))
else:
    print(xo(a-1) ^ xo(b))

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

def f(num):
    memo = [0] * 41
    if num % 4 == 1 or num % 4 == 2:
        memo[0] = 1
    for k in reversed(range(1, 41)):
        if (num >> k) & 1 == 1:
            num -= (1 << k)
            memo[k] = (num + 1) % 2
    return memo

memo1 = f(b)
memo2 = f(a-1)

ans = 0
for i in range(41):
    if (memo1[i] - memo2[i]) % 2 == 1:
        ans += (1 << i)

print(ans)

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

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

xor_of_a = xor(a - 1)
xor_of_b = xor(b)

ans = xor_of_a ^ xor_of_b

print(ans)

Solution (Python):
a, b = map(int, input().split())
b += 1
ret = 0
for k in range(40):
    ar = a % 2 ** (k+2)
    br = b % 2 ** (k+2)
    if ar & (2 ** (k+1)):
        ar = ar - 2**(k+1)
    else:
        ar = 0
    if br & (2 ** (k+1)):
        br = br - 2**(k+1)
    else:
        br = 0
    if (ar - br) % 2:
        ret += 2**(k+1)
def f(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    if x == 2:
        return 1
    if x == 3:
        return 1
print(ret + ((f(a % 4) + f(b % 4)) % 2))

Solution (Python):
def f(x):
    res = [x, 1, x+1, 0]
    return res[x%4]
a, b = [int(i) for i in input().split()]
print(f(a-1)^f(b))

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


"""
h,w = LI()
y,x = LI()
print(h*w-h*x-w*y+y*x)
"""


"""
n,m,c = LI()
b = LI()
a = LIR(n)
ans = 0
for i in range(n):
    d = c
    for k in range(m):
        d += b[k]*a[i][k]
    if d > 0:
        ans += 1
print(ans)
"""




"""
n,m = LI()
v = LIR(n)
v.sort(key = lambda x:x[0])
ans = 0
k = 0
for a,b in v:
    if k+b >= m:
        ans += (m-k)*a
        print(ans)
        quit()
    ans += b*a
    k += b
"""

a,b = LI()
k = list(bin(b)[2::])
l = len(k)
ans = [0 for i in range(l)]
po = [2]
for i in range(l):
    po.append(po[-1]*2)
for i in range(l):
    o = a//po[i]
    r = b//po[i]
    c = a%po[i]
    d = b%po[i]
    if o == r:
        key = max(0,d+1-max(c,po[i]//2))
    else:
        key = (r-o)*po[i]//2
        if c > po[i]//2:
            key -= c-po[i]//2
        if d >= po[i]//2:
            key += d-po[i]//2-1
    ans[i] = key%2
po.insert(0,1)
d = 0
for i in range(l):
    d += ans[i]*po[i]
print(d)

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

A, B = [int(s) for s in input().split(' ')]
if A == B:
    print(A)
else:
    print(XOR(A-1) ^ XOR(B))

Solution (Python):
rr = lambda: input().strip()
rrm = lambda: list(map(int, rr().split()))


def query(X):
    
    r = X%4
    if r == 0: return X
    if r == 1: return 1
    if r == 2: return X+1
    return 0

def solve(A, B):
    if A == B:
        return A
    elif A == 0:
        return query(B)
    else:
        return query(B) ^ query(A-1)
    
print(solve(*rrm()))

Solution (Python):
aa, bb = map(int,input().split())
aa -= 1
ans = 0
a1=0
b1=0
if 1<=aa%4<=2 :
    a1=1
if 1<=bb%4<=2 :
    b1=1
ans += (b1-a1)%2


mod = 2
mod2 = 4

for i in range(1,45) :
    bketa = 0
    b = bb % mod2
    if b >= mod :
        bketa = (b - mod + 1) % 2
        

    aketa = 0
    a = aa % mod2
    if a >= mod :
        aketa = (a - mod + 1) % 2
        

    ans += (bketa-aketa)%2 * mod

    mod *= 2
    mod2 *= 2

print(ans)

Solution (Python):
A,B=map(int,input().split());print([0,A-1,1,A][A%4]^[B,1,B+1,0][B%4])

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

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

Solution (Python):
A,B=map(int,input().split());A-=1;print([A,1,A+1,0][A%4]^[B,1,B+1,0][B%4])

Solution (Python):

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

def count_cumbit(x, i):
    if i == 0:
        d, m = divmod(x, 4)
        return int((m == 1) | (m == 2))
    else:
        d, m = divmod(x, 2**(i+1))
        return int((m >= 2**i) & (m%2==0))

A, B = inpl()
ans = 0
for i in range(41):
    ans += (2**i * (count_cumbit(A-1, i) ^ count_cumbit(B, i)))
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def count1(n: int):
    ret = [0]*40
    for mask in range(40):
        if mask == 0 and n&1:
            ret[0] += 1
        
        elif n & (1<<mask):
            ret[mask] += (n & ((1<<(mask+1))-1)) - ((1<<mask)-1)
            for m in range(mask):
                ret[m] += (1<<(mask-1))
                
    return ret

a,b = li()
onea = count1(a-1)
oneb = count1(b)

ans = 0
for i, (oneai, onebi) in enumerate(zip(onea, oneb)):
    ans += ((onebi-oneai)%2) * 2**i
    
print(ans)

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

result = 0
if a % 2 == 1:
    result ^= a
if b % 2 == 0:
    result ^= b

if (b + b % 2) - (a + a % 2) > 0:
    result ^= ((b + b % 2) - (a + a % 2)) // 2 % 2

print(result)

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


def f(x):
    res = 1 if 1 <= x % 4 <= 2 else 0
    for i in range(1, x.bit_length()):
        res += 1 << i if ((x >> i) & 1) and (x % 2 == 0) else 0
    return res


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

Solution (Python):
import sys

def calc(n):
    n2 = n & ~3
    for i in range(n2+1, n+1):
        n2 ^= i
    return n2

def solve(A,B):
    if A == 0:
        return calc(B)
    else:
        return calc(B) ^ calc(A-1)

def solve2(A,B):
    ans=A
    for i in range(A+1,B+1):
        ans ^= i
    return ans

A,B=map(int,sys.stdin.readline().rstrip().split())
print(solve(A,B))

Solution (Python):

import sys

def g(n):
    ret = 0
    ret += 1 if (n+1)//2%2==1 else 0
    for i in range(2, 41):
        m = 2**i
        if n%m>=m//2:
            ret += (n%m-m//2+1)%2 * m//2
    return ret

def solve(A: int, B: int):
    print(g(A-1)^g(B))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    solve(A, B)

if __name__ == '__main__':
    main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

a,b = getNM()
od_a, od_b = [((a)%4) // 2], [((b+1)%4) // 2]
a,b = bin(a-1)[2:], bin(b)[2:]


def checkod(binary, is_od):
    lower = binary[-1]
    for d in binary[::-1][1:]:
        if d == "0":
            is_od.append(0)
        else:
            if lower == "1":
                is_od.append(0)
            else:
                is_od.append(1)

checkod(a, od_a)
checkod(b, od_b)
lenb = len(od_b)
lena = len(od_a)
od_a = od_a + [0] * (lenb-lena)


od_f = []
for x,y in zip(od_a,od_b):
    if x^y == 0:
        od_f.append("0")
    else:
        od_f.append("1")


bin_str = "".join(od_f[::-1])

print(int(bin_str, 2))