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):


import itertools
import collections
import bisect

































def calc(x):
    if x % 2:  
        if x % 4 == 1:
            return 1
        else:
            return 0
    else:
        if x % 4 == 0:
            return x
        else:
            return x ^ 1

def main():
    A, B = map(int, input().split())
    ans = calc(B) ^ calc(max(0, A-1))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def f(n):
    ret = 0
    if n % 4 == 1 or n % 4 == 2:
        ret += 1
        
    for i in range(1, 50):
        t = n % (1<<i+1)
        if t+1 > (1<<i):
            ret += ((t+1)%2) * (1<<i)
    return ret

A, B = map(int, input().split())
A = max(A, 0)
print(f(B)^f(A-1))

Solution (Python):
def f(x,n):
  if n==0:
    return ((x+1)//2)%2
  a=x%(2**(n+1))
  if a<2**n:
    return 0
  return (a-1)%2
A,B=map(int,input().split())
ans=0
for i in range(100):
  ans|=((f(B,i)-f(A-1,i))%2)<<i
print(ans)

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

K=((B-A)//2)%2
if A%2==0 and B%2!=0:
  ans=(K+1)%2
elif A%2==0 and B%2==0:
  ans=K ^ B
elif A%2!=0 and B%2==0:
  ans=K^A^B
else:
  ans=K^A

print(ans)

Solution (Python):
import math

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

A = list()
B = list()

if b == 0:
    B = [0]
elif b == 1:
    B = [1]
else:
    for i in range(1, int(math.log2(b))+2):
        tmp = b // (2 ** i) * 2 ** (i - 1)

        if b % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = b % (2 ** i) - 2 ** (i-1) + 1

        B.append(tmp + plus)

if a == 0:
    A = [0]
elif a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

if b == 0:
    print(0)
else:
    ans = 0
    for i in range(0, int(math.log2(b)) + 1):
        if i >= len(A):
            ans += (B[i]) % 2 * 10 ** i
        else:
            ans += (B[i] - A[i]) % 2 * 10 ** i

    print(int(str(ans), 2))

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


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


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

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

num = len(bin(B)) - 2

ans = 0

for i in range(num):
    j = 2 ** i
    rep = j * 2
    m1 = (A - 1) // rep * j
    m2 = (A - 1) % rep
    if m2 >= j:
        m1 += m2 - j + 1
    n1 = B // rep * j
    n2 = B % rep
    if n2 >= j:
        n1 += n2 - j + 1

    if (n1 - m1) % 2 == 1:
        ans += j

print(ans)

Solution (Python):
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    c+=((y-x)//2+min(j,x-a)+max(0,b-y-j+1))%2*j
print(c)

Solution (Python):
n=50
table=[2**i for i in range(n+1)]
A,B=map(int,input().split())
st=0
for i in range(n+1):
    if table[i]>B:
        st=i
        break
ans=0
for i in range(1,st+1):
    x=0
    if B%(2**i)>=2**(i-1):
        x=B%(2**i)-2**(i-1)+1
    b=((B-B%(2**i))//(2**i))*(2**(i-1))+x
    y=0
    if (A-1)%(2**i)>=2**(i-1):
        y=(A-1)%(2**i)-2**(i-1)+1
    a=(((A-1)-(A-1)%(2**i))//(2**i))*(2**(i-1))+y
    if (b-a)%2==1:
        ans+=1<<(i-1)
print(ans)

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


def f(M):
    digit = len(bin(M)) - 2
    num = M - 2**(digit-1) + 1
    x = 0

    for i in range(digit):
        if i == 0:
            if M % 4 == 1 or M % 4 == 2:
                x += 1
        else:
            if bin(M)[-(i+1)] == '1':
                x += (num % 2) * (2**i)

    return x


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

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

def calcXorSum(a):
    if a % 2 == 1:
        n_ones = int((a + 1) / 2)
        return n_ones % 2
    else:
        n_ones = int(a / 2)
        return n_ones % 2 ^ a

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

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

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

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B=MAP()
A-=1

A2=[0]*50

B2=[0]*50

odd=[0]*50

for i in range(1, 50):
    T=2**i
    
    A2[i]+=A//T*(T//2)
    
    A2[i]+=max(A%T-(T//2-1), 0)
    B2[i]+=B//T*(T//2)
    B2[i]+=max(B%T-(T//2-1), 0)
    
    if (B2[i]-A2[i])%2==1:
        odd[i]=1
ans=0
for i in range(1, 50):
    if odd[i]:
        
        ans+=2**(i-1)
print(ans)

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


def f(x):
    if x % 2 == 1:
        return x ^ ((x//2) % 2) ^ (x-1)
    else:
        return x ^ ((x//2) % 2)


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

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

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

A = A - 1
tmpA = 0
tmpB = 0

if A < 0:
    tmpA = 0
else:
    if A%4 == 0:
        tmpA = A
    elif A%4 == 1:
        tmpA = 1
    elif A%4 == 2:
        tmpA = A + 1
    else:
        tmpA = 0

if B < 0:
    tmpB = 0
else:
    if B%4 == 0:
        tmpB = B
    elif B%4 == 1:
        tmpB = 1
    elif B%4 == 2:
        tmpB = B + 1
    else:
        tmpB = 0


ans = tmpA ^ tmpB
print(ans)

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

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

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

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

def f(x):
    ans = [x,1,x+1,0]
    return ans[x%4]

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

Solution (Python):
def count(X,n):
    l = []
    for i in range(n):
        l.append((X+1)//(2**(i+1))*2**i + max(0,(X+1)%(2**(i+1))-2**i))
    return l

A,B = map(int,input().split())
n = len(bin(B)[2:])
la = count(A-1,n)
lb = count(B,n)

xor = ''
for a,b in zip(la[::-1],lb[::-1]):
    if (b-a)%2 == 0:
        xor += '0'
    else:
        xor += '1'

print(int(xor,2))

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

b = format(B, 'b')
num = len(b)
cnt1 = [0]*num
for i in range(1, num):
    if (B+1)%(2**(i+1)) <= 2**i:
        continue
    else:
        if (B+1)%2 == 1:
            cnt1[i] = 1
if B % 4 == 1 or B % 4 == 2:
    cnt1[0] = 1

c = ''
if A == 0:
    for i in range(num):
        if cnt1[i] == 0:
            c = '0' + c
        else:
            c = '1' + c
    print(int(c, 2))
    sys.exit()

cnt2 = [0]*num
for i in range(1, num):
    if A%(2**(i+1)) <= 2**i:
        continue
    else:
        if A%2 == 1:
            cnt2[i] = 1
if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    cnt2[0] = 1

for i in range(num):
    if cnt1[i] == cnt2[i]:
        c = '0' + c
    else:
        c = '1' + c
print(int(c, 2))

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


def f(n):
    fl = ((n-1)//2) % 2
    if n % 2 == 0:
        return fl ^ n
    else:
        return fl


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

Solution (Python):
def is_odd_by_2(n):
    r = (n+1) // 2
    return r % 2 == 1

def is_odd_by_n(n, d):
    m = n % d
    if m >= (d // 2):
        return m % 2 == 0
    else:
        return False

A, B = [int(v) for v in input().split()]

bin_num = ''
if is_odd_by_2(B) ^ is_odd_by_2(A - 1):
    bin_num += '1'
else:
    bin_num += '0'

div_max = 1
while B >= (2 ** div_max):
    div_max += 1

for i in range(2, div_max + 1):
    d = 2 ** i
    is_odd = is_odd_by_n(B, d)
    if A >= 1:
        is_odd = is_odd ^ is_odd_by_n(A - 1, d)
    if is_odd:
        bin_num = '1' + bin_num
    else:
        bin_num = '0' + bin_num

print(int(bin_num, 2))

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


def xor(n):
    m = 0
    if (n % 4 == 0):
        m = n
    elif (n % 4 == 1):
        m = 1
    elif (n % 4 == 2):
        m = n + 1
    return (m)


A = xor(a - 1)
B = xor(b)
print(A ^ B)

Solution (Python):



g = lambda n: (1 if n & 1 else n) ^ ((n >> 1) & 1)
f = lambda A,B: g(B) ^ g(A) ^ A

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

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

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


def xor(n):
    m = 0
    if n % 4 == 0:
        m = n
    elif n % 4 == 1:
        m = 1
    elif n % 4 == 2:
        m = n + 1
    return m


p = xor(A-1)
q = xor(B)
print(p ^ q)

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

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

def main():
    return get(B) ^ get(A - 1)

print(main())

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
a,b=IL()
import math
if a==0:
    if b==0:
        n=1
    else:
        n=int(math.log(b,2))+1
else:
    if b==0:
        n=int(math.log(a,2))+1
    else:
        n=max(int(math.log(a,2)),int(math.log(b,2)))+1
al=[0 for i in range(n)]
bl=[0 for i in range(n)]
cl=[0 for i in range(n)]
for i in range(1,n):
    k=pow(2,i+1)
    al[i]=a%k
    bl[i]=b%k
    bou=k//2-1
    if al[i]<=bl[i]:
        if al[i]<=bou:
            if bl[i]<=bou:
                cl[i]=0
            else:
                cl[i]=0 if (bl[i]-bou)%2==0 else 1
        else:
            cl[i]=1 if (bl[i]-al[i])%2==0 else 0
    else:
        if bl[i]<=bou:
            if al[i]<=bou:
                cl[i]=0
            else:
                cl[i]=0 if (k-al[i])%2==0 else 1
        else:
            if al[i]<=bou:
                cl[i]=0 if (bl[i]-bou)%2==0 else 1
            else:
                cl[i]=0 if (k-al[i]+bl[i]-bou)%2==0 else 1
if a%2==0:
    if b%2==0:
        cl[0]=0 if ((b-a)//2)%2==0 else 1
    else:
        cl[0]=0 if (((b+1)-a)//2)%2==0 else 1
else:
    if b%2==1:
        cl[0]=1 if ((b-a)//2)%2==0 else 0
    else:
        cl[0]=1 if (((b-1)-a)//2)%2==0 else 0
        
ans=0
for i in range(n):
    ans+=cl[i]*pow(2,i)
print(ans)

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

Solution (Python):
a, b = map(int, input().split())
x = lambda n: (n % 4 in (1, 2)) + (0 if n % 2 else n // 2 * 2)
print(x(max(0, a - 1)) ^ x(b))

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

def calc_xor0(num):
    if num % 2 ==  0:
        if num % 4 == 2:
            ans =  num + 1
        else:
            ans =  num
    else:
        if num % 4 == 1:
            ans =  1
        else:
            ans =  0 
    return ans

def main():
    print(calc_xor0(A-1) ^ calc_xor0(B))    

if __name__ == "__main__":
    main()

Solution (Python):
nums = list(map(int, input().split()))
A, B = nums[0], nums[1]

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

    def up(n, a):
        if a % (2 ** n) <= 2 ** (n-1):
            return 2 ** (n - 1)
        else:
            return (2 ** n) - (a % (2 ** n))

    def down(n, a):
        if a % (2 ** n) < 2 ** (n-1):
            return 0
        else:
            return (a % (2 ** n)) - (2 ** (n-1)) + 1
    n = 2
    while 2 ** (n-1) <= B:
        u = up(n, A)
        d = down(n, B)
        num = (u + d) % 2
        ans += (2**(n-1)) * num
        n += 1

    print(ans)

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

answer = 0

A1_digit = len(bin(A - 1)) - 2
Abit_list = []
Amin_bit = '1' if 1 <= (A - 1) % 4 <= 2 else '0'
Abit_list.append(Amin_bit)

for i in range(2, A1_digit + 1):
    rem = (A - 1) % 2 ** i
    A_bit = '0' if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else '1'
    Abit_list.append(A_bit)

B_digit = len(bin(B)) - 2
Bbit_list = []
Bmin_bit = '1' if 1 <= B % 4 <= 2 else '0'
Bbit_list.append(Bmin_bit)
for i in range(2, B_digit + 1):
    rem = B % 2 ** i
    B_bit = '0' if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else '1'
    Bbit_list.append(B_bit)

Abit_list.reverse()
Bbit_list.reverse()
Axor = int(''.join(Abit_list), 2)
Bxor = int(''.join(Bbit_list), 2)

print(Axor ^ Bxor)

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


def func(n, m):
	return int((n + 1) / (2 ** m)) * 2 ** (m - 1) + max(0, (n + 1) % (2 ** m) - 2 ** (m - 1))

print sum((func(B, i) - func(A-1, i)) % 2 * 2 ** (i - 1) for i in range(1, 64))

Solution (Python):
def xor_a2b(a,b) : 
    flg = a % 2 != 0
    
    if flg: 
        a += 1
    mod = (b - a) % 4
    if mod == 0:
        res = b
    elif mod == 1:
        res =  1
    elif mod == 2:
        res = b + 1
    else:
        res = 0
    if flg:
        return (a-1) ^ res
    else:
        return res
      
a,b = map(int,input().split())

print(xor_a2b(a,b))

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

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

A, B = map(int, input().split(" "))
string = ""
i = 0
a = f(A-1)
b = f(B)
print(a^b)

Solution (Python):
def yabai(a):
    al=''
    a2=a
    amarin=a2%4
    if amarin==0 or amarin==3:
        al='00'
    elif amarin%4==2:
        al='11'
    else:
        al='01'
    
    kaisu_a=0
    while a2>0:
        if a2%2==0:
            
            a2=a2/2
            
        else:
            
            a2=(a2-1)/2
            
        kaisu_a+=1
    
    
    for a_i in range(kaisu_a-2):
        amari=a%(2**(a_i+3))
        if amari>=2**(a_i+2) and amari%2==0:
            al='1'+al
        else:
            al='0'+al
    
    return al

def main():
    list=input().split(' ')
    a=int(list[0])
    b=int(list[1])
    newa=yabai(a-1)
    
    newb=yabai(b)
    for sa in range(len(newb)-len(newa)):
        newa='0'+newa
    
    answer=0
    
    for i in range(len(newa)):
        if (newa[i]=='0' and newb[i]=='1') or (newa[i]=='1' and newb[i]=='0'):
            answer+=(2**(len(newa)-i-1))
    print(answer)

main()

Solution (Python):
a, b = list(map(int, input().split()))
ba = b - a
if a % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if b % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a2 = format(a, "b")
b2 = format(b, "b")
a2 = str(a2[::-1])
b2 = str(b2[::-1])

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 1:
		c2 += 2 ** i

print(c2)

Solution (Python):
a,b = map(int,input().split())
if a % 4 == 0 and b % 4 == 0:
    print(b)
    exit()

c = []
if a % 4 != 0:
    c += list(range(a,a+(4-(a%4))))
c += list(range(b-(b%4),b+1))

e = 0
for i in c:
    d = bin(e ^ i)
    e = int(d,2)
print(e)

Solution (Python):
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    """
    if x>=y:
        t=0
        for p in range(a,b+1):
            t+=p&j>0
    else:
    """
    t=(y-x)//2
    t+=min(j,x-a)
    t+=max(0,b-y-j+1)
    c+=t%2*j
print(c)

Solution (Python):
AB = list(map(int, input().split()))
soto = AB[0] - 1
B = AB[1]
if soto % 4 == 0:
    tmp1 =soto
elif soto % 4 == 1:
    tmp1 = 1
elif soto % 4 == 2:
    tmp1= soto + 1
else :
    tmp1 = 0

if B % 4 == 0:
    tmp2 =B
elif B % 4 == 1:
    tmp2 = 1
elif B % 4 == 2:
    tmp2= B + 1
else :
    tmp2 = 0

ans = tmp1 ^ tmp2
print(ans)

Solution (Python):

"""
Created on Sat Mar  9 20:50:42 2019

@author: Yamazaki Kenichi
"""

A,B = map(int,input().split())
ans = 0
def a(A,B):
    if (B-A) % 4 <= 1:
        return 0
    else:
        return 1

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

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



def R (D):
    bins=""
    for i in range(1,50):
        d = 2**i
        ans = False
        if i == 1:
            if(D%4==1 or D%4==2):
                ans = True
        if i > 1:
            if(D%d>=d//2 and D%d%2==0):
                ans = True
        bins = str(int(ans)) + bins
    return int(bins,2)

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

Solution (Python):
a,b=map(int,input().split())
s=[2**i for i in range(42)]
d=[0]*42
i=1
if ((b+1)//2-a//2)%2==1:
    d[0]+=1
while i<42:
    if s[i]>b:
        break
    elif s[i]>a: 
        a=s[i]
    p,q=a%s[i],a//s[i]
    o,t=b%s[i],b//s[i]
    if q==t:
        if q%2==1:
            if (b-a+1)%2==1:
                d[i]=1
    else:
        h=0
        if q%2==1:
            h+=(q+1)*s[i]-a  
        if t%2==1:
            h+=b-t*s[i]+1
        if h%2==1:
            d[i]=1
    i+=1
ans=0
for i in range(42):
    ans+=d[i]*s[i]
print(ans)

Solution (Python):
A,B = map(int, input().split())
ans = 0
if A==B: 
    print(A)
    exit()
for keta in range(1,50):
    beki = 2**(keta-1)
    if beki>A and beki>B: break
    ra,qa = A%beki,A//beki
    rb,qb = B%beki,B//beki

    if keta>1:
        tmp = 0
        if qa%2==1:  tmp+=beki-ra
        if qb%2==1:  tmp+=rb+1
        if tmp%2==1: ans += beki
    else: 
        ra,qa = A%2,A//2
        rb,qb = B%2,B//2


        if qb-qa>0:
            tmp = qb-qa-1 
    
            tmp += 1
            if rb==1: tmp+=1
            if tmp%2==1: ans += 1
        else:
            ans += 1
        

print(ans)

Solution (Python):
A, B = map(int, input().split())
tmp = [A, A^B, A-1, (A^B)-1]
tmp2 = [B, 1, B+1, 0]




ans = 0
r = abs(A-B) % 4

if A % 2 == 1:
    
    ans = tmp[r]
else:
    
    ans = tmp2[r]



print(ans)

Solution (Python):
n, m= map(int, input().split())
if n==m:
    print(n)
else:

    A=[2**i for i in range(50)]
    
    tmp1=""
    tmp2=""
    
    for num,i in enumerate(A):
        if num==0:
            if (n)//2%2==0:
                tmp1="1"
            else:
                tmp1="0"
            if (m+1)//2%2==0:
                tmp2="1"
            else:
                tmp2="0"
            continue
        
        a1=(n-1)//i
        b1=(n-1)%i
        a2=m//i
        b2=m%i
        if a1%2==1 and b1%2==0:
            tmp1="1"+tmp1
        else:
            tmp1="0"+tmp1

        if a2%2==1 and b2%2==0:
            tmp2="1"+tmp2
        else:
            tmp2="0"+tmp2

    
    
    tmp1=int(tmp1, 2)
    tmp2=int(tmp2, 2)
    
    print(tmp1 ^ tmp2)

Solution (Python):
def compute_xor(n: int)->int:
    if n % 4 == 0:
        return n
    if n % 4 == 1:
        return 1
    if n % 4 == 2:
        return n + 1
    return 0


def xor_world(A: int, B: int)->int:
    return compute_xor(B) ^ compute_xor(A-1)


if __name__ == "__main__":
    A, B = map(int, input().split())
    ans = xor_world(A, B)
    print(ans)

Solution (Python):
from math import log2
a, b = map(int, input().split())
p, q = a, b
a -= 1
if a > 0:
    n = int(log2(a))
else:
    n = -1
if b > 0:
    m = int(log2(b))
else:
    print(0)
    exit()
a_cnt = [0]*(m+1)
b_cnt = [0]*(m+1)
for i in range(m, 0, -1):
    if i <= n:
        if a >= 2**i:
            a_cnt[i] = a-2**i+1
            a -= 2**i
    if b >= 2**i:
        b_cnt[i] = b-2**i+1
        b -= 2**i

ans = [0]*(m+1)
for i in range(m+1):
    ans[i] = (b_cnt[i]-a_cnt[i])%2

tmp = 0
for i in range(1, m+1):
    if ans[i]:
        tmp += 2**i

tmp += ((q+1)//2-p//2)%2
print(tmp)

Solution (Python):



import sys
import math





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

ret = 0

if (((1+b)//2) - ((a)//2))%2 == 1:
    ret += 1


for i in range(1,41):
    nextone = 1 << (i + 1)
    wa = 0
    if (a >> i) % 2 == 1:
        wa += nextone - (a % nextone)
    if (b >> i) % 2 == 1:
        wa += 1 + b % nextone
    
    

    if wa % 2 == 1:
        ret += 1 << i

print(ret)

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

def g(x):
  if x == 0:
    return 0
  elif x == 1:
    return 1
  elif x == 2:
    return 3
  elif x == 3:
    return 0
  k = len(bin(x))-3
  cnt = x - 2 ** k + 1
  bit = cnt % 2
  return (2 ** k * bit) ^ g(x - 2 ** k)

print(g(B) ^ g(max(0, A-1)))

Solution (Python):
import math

def f(n):
  s = ""
  if n <= 0:
    return 0
  for i in reversed(range(int(math.log2(n))+1)):
    if i == 0:
      s += "1" if ((n-1)//2)%2 == 0 else "0"
    else:
      s += "1" if (n//(2**i))%2 + (n+1)%2 == 2 else "0"
  return int(s,2)

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

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

if b > 3:
    if a <= 1:
        s_c = 1
    else:
        s_c = 0

    a_keta = len(str(bin(a))) - 2
    b_keta = len(str(bin(b))) - 2
    m_a = (2 ** a_keta - a) % 4
    m_b = (b - (2 ** (b_keta-1)) + 1) % 4
    
    

    if m_a == 0:
        s_a = 0
    elif m_a == 1:
        s_a = a
    elif m_a == 2:
        s_a = 1
    elif m_a == 3:
        s_a = a - 1

    if m_b == 0:
        s_b = 0
    elif m_b == 1:
        s_b = b
    elif m_b == 2:
        s_b = 1
    elif m_b == 3:
        s_b = b + 1
    print(s_a ^ s_b ^ s_c)
else:
    if a == 0 and b == 0:
        print(0)
    if a == 0 and b == 1:
        print(1)
    if a == 0 and b == 2:
        print(3)
    if a == 0 and b == 3:
        print(0)
    if a == 1 and b == 1:
        print(1)
    if a == 1 and b == 2:
        print(3)
    if a == 1 and b == 3:
        print(0)
    if a == 2 and b == 2:
        print(2)
    if a == 2 and b == 3:
        print(1)
    if a == 3 and b == 3:
        print(3)

Solution (Python):
a,b = (int(i) for i in input().split())
ans = 0
if a % 2 == 0:
  temp = (b - a + 1) % 4 
  for i in range(b-temp+1,b+1):
    ans ^= i
else:
  temp = (b - a) % 4 
  ans ^= a
  for i in range(b-temp+1,b+1):
    ans ^= i
print(ans)

Solution (Python):
import sys

l = raw_input().split()
A = int(l[0])
B = int(l[1])

sum = 0
if A % 2 == 1:
    sum = A

if A % 2 == 1 and B % 2 == 1:
    ones = int((B - A)/2)
elif A % 2 == 1 and B % 2 == 0:
    ones = int((B - A)/2)
elif A % 2 == 0 and B % 2 == 1:
    ones = int((B - A + 1)/2)
else:
    ones = int((B - A)/2)

if B % 2 == 1:
    sum ^= (ones % 2)
else:
    sum ^= (B ^ (ones % 2))

print(sum)

Solution (Python):
def f(n):
    ret = 0
    for i in range(40):
        mod = 2**(i+1)

        num = n//mod
        rem = n%mod

        ct = num*(mod//2)
        ct += max(0, rem - mod//2 + 1)
        if ct%2 == 1:
            ret |= (1<<i)

    return ret

def main():
    a,b = map(int,input().split())
    if a > 0:
        a -= 1
    return f(b)^f(a)

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

Solution (Python):
A, B = map(int, input().split())
res = B - A
res = res % 4
if A % 2 == 0:
    ans = B
    for i in range(1, res+1):
        ans = ans ^ (B - i)
    print(ans)
    exit()
else:
    ans = A
    for i in range(0, res):
        ans = ans ^ (B - i)
    print(ans)
    exit()

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

ans = ''
for i in range(100):
    if b == 0:
        ans = '0'
        break
    if b == 1:
        if a == 0:
            ans = '1'
            break
        if a == 1:
            ans = '0'
            break
            
    n = 2 ** i
    if n > b:
        break

    if n == 1:
        num_1 = (a+1) // 2
        if (a+1) % 2 == 0 and a != 0:
            num_1 -= 1
        num_2 = (b+1) // 2
        if (num_2 - num_1) % 2 ==  0:
            ans += '0'
        else:
            ans += '1'
        continue
        
    r = (b + 1) % (2*n)
    if r == 0:
        num_1 = n
    elif r > n:
        num_1 = r - n
    else:
        num_1 = 0
    
    r = (a + 1) % (2*n)
    if r == 0:
        num_2 = 1
    elif r > n:
        num_2 = (2*n - r +1)
    else:
        num_2 = n

    if (num_1 + num_2) % 2 == 0:
        ans += '0'
    else:
        ans += '1'

print(int(ans[::-1], 2))

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

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


def count(x, k):
    return 2**(k - 1) * (x // 2**k) + max([x % 2**k - 2**(k - 1) + 1, 0])


ans = 0
for k in range(1, 50):
    ans += 2**(k - 1) * ((count(B, k) - count(A - 1, k)) % 2)
print(ans)

Solution (Python):
a,b=map(int,input().split())
a-=1
la,lb=[a%2**i for i in range(41)],[b%2**i for i in range(41)]
ans=0
for i in range(2,41):
    na,nb=max(la[i]-2**(i-1)+1,0),max(lb[i]-2**(i-1)+1,0)
    if (max(na,nb)-min(na,nb))%2==1:
        ans+=2**(i-1)
c=lb[2]-la[2] if lb[2]-la[2]>=0 else lb[2]-la[2]+4
if la[1]==0 and (c==1 or c==2):
    ans+=1
elif la[1]==1 and (c==2 or c==3):
    ans+=1
print(ans)

Solution (Python):
def readln():
    return list(map(int, input().split()))


A, B = readln()


A_isodd = []  
B_isodd = []  

tmp = (A) % 4
if (tmp == 2)or(tmp == 3):
    A_isodd.append(1)
else:
    A_isodd.append(0)
tmp = (B+1) % 4
if (tmp == 2)or(tmp == 3):
    B_isodd.append(1)
else:
    B_isodd.append(0)


for i in range(1, 40):  
    tmp = (A) % 2 ** (i + 1)
    if (tmp > 2 ** (i)) and (tmp % 2 == 1):
        A_isodd.append(1)
    else:
        A_isodd.append(0)
    tmp = (B + 1) % 2 ** (i + 1)
    if (tmp > 2 ** (i)) and (tmp % 2 == 1):
        B_isodd.append(1)
    else:
        B_isodd.append(0)




ans = []
for a, b in zip(A_isodd, B_isodd):
    if a == b:
        ans.append(0)
    else:
        ans.append(1)

ans_print = 0
for i, a in enumerate(ans):
    ans_print += 2 ** i if a == 1 else 0

print(ans_print)

Solution (Python):









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

answer = 0

A1_digit = len(bin(A - 1)) - 2
Abit_list = []
Amin_bit = 1 if 1 <= (A - 1) % 4 <= 2 else 0
Abit_list.append(Amin_bit)

for i in range(2, A1_digit + 1):
    rem = (A - 1) % 2 ** i
    A_bit = 0 if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else 1
    Abit_list.append(A_bit)

B_digit = len(bin(B)) - 2
Bbit_list = []
Bmin_bit = 1 if 1 <= B % 4 <= 2 else 0
Bbit_list.append(Bmin_bit)
for i in range(2, B_digit + 1):
    rem = B % 2 ** i
    B_bit = 0 if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else 1
    Bbit_list.append(B_bit)

Abit_list.reverse()
Bbit_list.reverse()


Axor = 0
for v in Abit_list:
    Axor = Axor << 1
    if v == 1:
        Axor = Axor + 1

Bxor = 0
for v in Bbit_list:
    Bxor = Bxor << 1
    if v == 1:
        Bxor = Bxor + 1



print(Axor ^ Bxor)

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

mod4diff = (B+1-A)%4
if mod4diff == 0:
    ans = 0
elif mod4diff == 1:
    ans = A%2
elif mod4diff == 2:
    ans = 1
else:
    ans = (A+1)%2

for k in range(1,40):
    am = A % (2**(k+1))
    bm = B % (2**(k+1))
    a = am // (2**k)
    b = bm // (2**k)
    if a and b:
        ans += (2**k) * ((A+B+1)%2)
    elif a:
        ans += (2**k) * (A%2)
    elif b:
        ans += (2**k) * ((B+1)%2)
print(ans)

Solution (Python):
def g(x):
    return [x,1,x+1,0][x%4]
a,b=map(int,input().split())
print(g(b)^g(a-1))

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

diff = B - A 
if A % 2 == 0:
    if diff % 4 == 0:
        tp = 0 ^ B
    if diff % 4 == 1:
        tp = 1
    if diff % 4 == 2:
        tp = 1 ^ B
    if diff % 4 == 3:
        tp = 0
else:
    if diff % 4 == 0:
        tp = A
    if diff % 4 == 1:
        tp = A ^ B
    if diff % 4 == 2:
        tp = A - 1
    if diff % 4 == 3:
        tp = A - 1 ^ B

print(tp)

Solution (Python):
import math

A, B = [int(i) for i in input().split()]
diff = B - A

str_B = format(B, 'b')

A = A - 1
result = ""
for i in range(0, len(str_B)):
    keta = len(str_B) - i
    num = math.pow(2, keta)
    
    one_in_A = int(A / num) * (num / 2)
    one_in_B = int(B / num) * (num / 2)

    if A % num >= int(num / 2):
        one_in_A += A % num - int(num / 2) + 1
    if B % num >= int(num / 2):
        one_in_B += B % num - int(num / 2) + 1

    if one_in_A < 0:
        one_in_A = 0
    
    if A >= 0:
        if (one_in_B - one_in_A) % 2 == 1:
            result += "1"
        else:
            result += "0"
    else:
        if one_in_B % 2 == 1:
            result += "1"
        else:
            result += "0"

print(int(result, 2))

Solution (Python):
A,B = map(int,input().split(" "))
DIF = B - A
if (A % 4 == 0 and B % 4 == 0) or DIF == 0:
    print(B)
else:
    list = []
    for i in range(A,A+4):
        if i % 4 != 0:
            list.append(i)
        elif i % 4 == 0:
            break
    flag = 0
    for i in range(B-3,B+1):
        if i % 4 != 0 and flag == 0:
            pass
        elif i % 4 == 0:
            list.append(i)
            flag = 1
        elif i % 4 != 0 and flag == 1:
            list.append(i)
    
    total = 0
    for i in range(len(list)):
        num = list[i]
        
        total = total ^ num 
    print(total)