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):
def g(n):
    if n % 4 == 0:
        return n
    if n % 4 == 1:
        return 1
    if n % 4 == 2:
        return n+1
    return 0


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


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

Solution (Python):
a,b=map(int,input().split())
x=0
while a%4:x^=a;a+=1
while b%4<3:x^=b;b-=1
print(x)

Solution (Python):
A,B=map(int,input().split())
A-=1
def func1(X):
    xa=(X//4)*4+1
    xb=X%4
    sum=int(bin(0)[2:])
    if xb==3:
        return sum
    if xb==0:
        return int(bin(X)[2:])
    if xb==1:
        return int(bin(X-1)[2:])^int(bin(X)[2:])
    if xb==2:
        return int(bin(X-2)[2:])^int(bin(X-1)[2:])^int(bin(X)[2:])
A_=str(func1(A)).zfill(50)
B_=str(func1(B)).zfill(50)
c=""

for i in range(50):
    if A_[i]=="0" and B_[i]=="0":
        c+="0"
    if A_[i]=="0" and B_[i]=="1":
        c+="1"
    if A_[i]=="1" and B_[i]=="1":
        c+="0"
    if A_[i]=="1" and B_[i]=="0":
        c+="1"
print(int(c,2))

Solution (Python):

def num2list(x):
    ret = [0]*40
    for i in range(40):
        ret[i] = x % 2
        x = x // 2
    return ret
def list2num(l):
    ret = 0
    for i,x in enumerate(l):
        ret += x * (2**i)
    return ret
def num2sum(x):
    ret = [0] * 40
    for i in range(40):
        if(i==0):
            amari = x % 4
            if(amari == 1 or amari == 2):
                ret[i] = 1
            else:
                ret[i] = 0
        else:
            pow2 = 2**i
            amari = x % (pow2*2)
            if(amari < (pow2)):
                ret[i] = 0
            else:
                if(amari % 2 == 0):
                    ret[i] = 1
                else:
                    ret[i] = 0
    return ret
def sublist(xl,yl):
    ret = [0]*40
    for i in range(40):
        x = xl[i]
        y = yl[i]
        if((x==0 and y==0) or (x==1 and y==1)):
            ret[i] = 0
        else:
            ret[i] = 1
        
    return ret


A, B = map(int, input().split())
Al = num2sum(A-1)
Bl = num2sum(B) 



ret = list2num(sublist(Al,Bl))

print(ret)

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

C=[0]*50
for i in range(1,50):
    T=2**i
    acnt=bcnt=0
    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:
        C[i]=1
ans=0
for i in range(1,50):
    if C[i]:
        ans+=2**(i-1)
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


A, B = LI()



if B % 4 == 0:
    
    pass
elif B % 4 == 1:
    
    B = B^(B-1)
elif B % 4 == 2:
    
    B = B^(B-1)^(B-2)
elif B%4 == 3:
    
    B = 0
    
A = A - 1
if A % 4 == 0:
    pass
elif A % 4 == 1:
    A = A ^ (A-1)
elif A % 4 == 2:
    A = A ^ (A - 1) ^ (A - 2)
else:
    
    A = 0


print(A^B)

Solution (Python):
import math
o, b = map(int, input().split())
def pi(a):
    s= 0
    a+=1
    p = math.log2(a)
    p = int(p)
    qq=1
    q = 2
    ans =0
    t = 0
    t = a//2
    ans += t%2

    for i in range(1,p+1):
        qq = q

        q*=2
        t = a%(q)
        ans += qq*(max(0,t-qq)%2)
    return ans
print((pi(b)^pi(o))^o)

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

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

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

a = a-1

X=[]
Y=[]
for i in range(1,42):
    if a%(2**(i+1))<(2**i):
        X.append('0')
    else:
        if a%2==1:
            X.append('0')
        else:
            X.append('1')
            
for i in range(1,42):
    if b%(2**(i+1))<(2**i):
        Y.append('0')
    else:
        if b%2==1:
            Y.append('0')
        else:
            Y.append('1')

if a%4==1 or a%4 ==2:
    X.insert(0,'1')
else:
    X.insert(0, '0')

if b%4==1 or b%4 ==2:
    Y.insert(0,'1')
else:
    Y.insert(0, '0')

X.reverse()
Y.reverse()

A = ' '
for x in X:
    A += x
B = ' '
for x in Y:
    B += x

print(int(A,2)^int(B,2))

Solution (Python):
import math
A,B = list(map(int,input().split()))
s =""
if B == 0:
    print(0)
else:
    for i in range(int(math.log2(B))+1):
        if i == 0:
            a =0
            for j in range(A,4*(divmod(A,4)[0]+1)):
                
                a += divmod(j,2)[1]
            for j in range(4*(divmod(B,4)[0]),B+1):
                
                a += divmod(j,2)[1]
            s = str(divmod(a,2)[1])
        else:
            
            s = str(divmod((2**i-divmod(A,2**i)[1]) * int(divmod(A/2**i ,2)[1])+(divmod(B,2**i)[1]+1) * int(divmod(B/2**i ,2)[1]),2)[1]) + s
    print(int(s,2))

Solution (Python):
A, B = [int(i) for i in input().split()]
str_A = bin(A)[2:]
str_B = bin(B)[2:]
max_len = max(len(str_A), len(str_B))
A += 1
B += 1
result = ""
"""
a = A % 4
b = B % 4
if a % 2 == 0:
    if a == b:
        result += "1"
    else:
        result += "0"
else:
    if max(a,b) - min(a,b) == 3:
        result += "0"
    else:
        result += "1"
"""
if (B // 2 - (A-1) // 2) % 2 == 0:
    result += "0"
else:
    result += "1"
"""
for i in range(2,max_len+1):
    a = A % 2 ** i
    b = B % 2 ** i
    if a < 2 ** (i - 1):
        a = 2
    else:
        a = 2 ** i - a + 1
    if b < 2 ** (i - 1):
        b = 2
    else:
        b = b - 2 ** (i - 1)
    if (a + b) % 2 == 0:
        result += "0"
    else:
        result += "1"
"""
for i in range(2, max_len+1):
    a = (A-1) % 2 ** i
    a = 0 if a < 2 ** (i - 1) else 2 ** i - a
    b = B % 2 ** i
    b = 0 if b < 2 ** (i - 1) else b - 2 ** (i - 1)
    if (b + a) % 2 == 0:
        result += "0"
    else:
        result += "1"
print(int(result[::-1],2))

Solution (Python):
def findn(m):
    n = 0
    if m % 4 in (1, 2):
        n += 1
    for i in range(1, len(bin(m)) - 2):
        bit = 2 ** i
        nextbit = 2 * bit
        if m % nextbit >= bit and (m % nextbit - bit) % 2 == 0:
            n += bit
    return n


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

Solution (Python):
import numpy as np
A,B=(int(x) for x in input().split())
st=A%2
en=B%2
AA=0
BB=0
if st!=0:
  AA=A
  A=A+st
if en!=1:
  BB=B
  B=B-en
bit=((B-A+1)//2)%2  
result=BB^AA^bit
print(result)

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

def f(X):
    ans = (X&1)^((X>>1)&1)
    for i in range(1,48):
        if (X&1==0) and (X&(1<<i)!=0):
            ans += 1<<i
    return(ans)
     
print(f(max(A-1,0))^f(B))

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

Solution (Python):



def one_check(left, right, div):
    if(left == right):
        if(left % div >= div/2):
            return 1;
        else:
            return 0;
    else:
        if(left < div/2):
            if(right < div/2):
                return 0;
            elif(div/2 <= right and right < div):
                return right+1 - div/2;
            else:
                return div/2;
        else:
            if(right < div):
                return right+1-left;
            elif(div <= right and right < div*3/2):
                return div-left;
            else:
                return right+1-left - div/2;


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

answer = 0;

if(A==B):
    answer = A;
else:
    div = 2;
    while(div/2<=B):
        if(div==2):
            remainSets = ((B-A+1) // div);
            oneNum = remainSets%2;
            if((B-A)%2 == 0):
                Arem = A % div;
                Brem = B % div;
                if(Arem > Brem):
                    Brem += div;
                oneNum += one_check(Arem, Brem, div);
        else:
            oneNum = 0;
            Arem = A % div;
            Brem = B % div;
            if(Arem > Brem):
                Brem += div;
            oneNum += one_check(Arem, Brem, div);
        if(oneNum%2 == 1):
            answer += div/2;
        div*=2;



print(int(answer));

Solution (Python):
import sys

input = sys.stdin.readline
a, b = map(int, input().split())
n = 1000
if (int((b+1)/2)-int(a/2))%2 == 0:
    ans = '0'
else:
    ans = '1'
num = 2
for i in range(1, n):
    if num > b:
        break
    tmp = 0
    if int(a/num)%2 == 1:
        tmp += a % num
    if int(b/num)%2 == 1:
        tmp += (b+1) % num
    if tmp%2 == 0:
        ans += '0'
    else:
        ans += '1'
    num = num * 2
print(int(ans[::-1], 2))

Solution (Python):

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


def f(a):
    """
    xor [0,a]
    """
    l = []
    d = 2
    while (a+1)//d > 0:
        t = (a+1)//d*(d//2)+max((a+1) % d-d//2, 0)
        l.append(t % 2)
        d *= 2
    l.append(((a+1)-d) % 2)
    return l


def solve2(a, b):
    rb = f(b)
    ra = f(a-1)
    for i in range(len(ra)):
        rb[i] ^= ra[i]
    ans = "".join(map(str, reversed(rb)))
    print(int(ans, 2))


A, B = map(int, input().split())
if A == 0 and B == 0:
    print(0)
else:
    solve2(A, B)

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

result=""
AS=bin(A)[2:]
BS=bin(B)[2:]
def calc(ST1,ST2):
    rt=""
    lg=max(len(ST1),len(ST2))
    ST1=("0"*lg+ST1)[-lg:]
    ST2=("0"*lg+ST2)[-lg:]
    for i in range(lg):
        if ST1[i]==ST2[i]:
            rt+="0"
        else:
            rt+="1"
    return rt


if AS[-1]=="0":
    if BS[-1]=="1":
        print(int(N/2)%2)
    else:
        print(int(calc(BS,str(int((N-1)/2)%2)),2)) 
else:
    if BS[-1]=="1":
        print(int(calc(AS,str(int((N-1)/2)%2)),2))
    else:
        print(int(calc(calc(AS,str(int((N-1)/2)%2)),BS),2))

Solution (Python):
a,b=map(int,input().split())
if a==b:
    print(a)
else:
    s=4-a%4
    t=(1+b%4)
    ans=0
    for j in range(a,a+s):
        ans=ans^j
    for j in range(b+1-t,b+1):
        ans=ans^j
    print(ans)

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


def one_of(k,n):
    s=math.pow(2,k)
    matomari = ((n+1) // (s*2))*s

    amari = (n+1) % (s*2)
    if amari > s:
        amaribun=amari - s
    else:
        amaribun = 0

    return int(matomari + amaribun)






ans = 0
for i in range(40):
    pality=0
    one_of_A=0 
    one_of_B=0 
    

    


    

    pality=(one_of(i,b)-one_of(i,a-1))%2
    if pality == 1:
        ans += int(math.pow(2,i))
print(ans)

Solution (Python):
import math

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


def f(num):
    n_max = math.ceil(math.log2(num+1))
    result = 0
    for n in range(n_max):
        if n == 0:
            r = num % 4
            if r == 1 or r == 2:
                result += 1
            continue
        r = (num+1) % 2**(n+1)
        if r <= 2**n:
            continue
        else:
            r -= 2**n

        if r % 2 == 1:
            result += 2**n

    return result


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

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

ans = 0
for i in range(40):
    T = 2 ** i
    cnt = 0

    loop = (B + 1) // (2 * T)
    rest = (B + 1) % (2 * T)
    cnt += T * loop
    cnt += max(0, rest - T)

    loop = A // (2 * T)
    rest = A % (2 * T)
    cnt -= T * loop
    cnt -= max(0, rest - T)

    if cnt % 2 == 1:
        ans += T

print(ans)

Solution (Python):
A,B = map(int,input().split())
if A == 0:
    A = 1
Blist = bin(B)[2:]
Alist = bin(A-1)[2:]

def sumxor(P):
    ans = 0
    L = len(P)
    for i in range(L):
        ans *= 2
        if i < L-1:
            if P[i] == '1' and P[-1] == '0':
                ans += 1
        else:
            k = int(P[-2:],2)
            if k == 1 or k == 2:
                ans += 1
    return ans

print(sumxor(Alist) ^ sumxor(Blist))

Solution (Python):
a, b = list(map(int, input().split()))
num = b - a + 1
a_odd = (a % 2 == 1)
num_odd = (num % 2 == 1)


if a_odd:
    if num_odd:
        if ((num-1)/2) % 2 == 1:
            ans = a ^ 1
        else:
            ans = a
    else:
        if ((num-2)/2) % 2 == 1:
            ans = a ^ b ^ 1
        else:
            ans = a ^ b
else:
    if num_odd:
        if ((num-1)/2) % 2 == 1:
            ans = b ^ 1
        else:
            ans = b
    else:
        if (num/2) % 2 == 1:
            ans = 1
        else:
            ans = 0
print(ans)

Solution (Python):
A, B = map(int, input().split())
if A == 0:
    print(0^B)
elif A == 1:
    print(1^B)
elif A == B:
    print(A)
else:
    A = A-1
    Ab = format(A, 'b')
    Bb = format(B, 'b')
    an = len(Ab)
    
    bn = len(Bb)
    
    sa = ''
    sb = ''
    for i in range(1,bn+1):
        if i == 1:
            if (B+1) // 2 % 2 == 1:
                sb = '0' + sb
            else:
                sb = '1' + sb
            continue
        if B % (2**i) >= 2**(i-1) and (B % (2**i)) % 2 == 0:
            sb = '1' + sb
        else:
            sb = '0' + sb

    for j in range(1,an+1):
        if j == 1:
            if (A+1) // 2 % 2 == 1:
                sa = '0' + sa
            else:
                sa = '1' + sa
            continue
        if A % (2**j) >= 2**(j-1) and (A % (2**j)) % 2 == 0:
            sa = '1' + sa
        else:
            sa = '0' + sa
    
    sa = int(sa,2)
    sb = int(sb,2)
    
    ans = sa^sb

    print(ans)

Solution (Python):
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
_a,_b=map(int,input().split())
b=str(bin(_b))[2:]
a=str(bin(_a))[2:].zfill(len(b))
l=[2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776]
l2=[0]*len(b)
_b+=1
for i in range(len(b)):
  x=_a//l[i]
  x_amr=_a%l[i]
  y=_b//l[i]
  y_amr=_b%l[i]
  z_a=(y*l[i]//2+max(0,y_amr-l[i]//2))-(x*l[i]//2+max(0,x_amr-l[i]//2))
  z_b=(y*l[i]//2+min(y_amr,l[i]//2))-(x*l[i]//2+min(x_amr,l[i]//2))
  l2[i]=struct(z_a,z_b)
l2.reverse()
s=''
for i in l2:
  s+=str(i.a%2)
print(int(s,2))

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

Solution (Python):
def solve(a,b):
    l = []
    count = (b - a + 1)
    r = 0
    if (a % 2 != 0):
        l.append(a)
        r += 1
    if (b % 2 == 0):
        l.append(b)
        r += 1
    if ((count - r) / 2) % 2 != 0:
        l.append(1)

    ans = 0
    for n in l:
        ans = ans ^ n
    print(ans)

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

Solution (Python):
import math

def get_nearest_bin(x):
	if x <= 1:
		return x
	y = x
	i=0
	while y !=0:
		y = y >> 1
		i += 1
	return (x >> (i-1) ) << (i-1)

def func(x):
	if x <= 3:
		return {0:0,1:1,2:3,3:0}[x]
	
	nearest_bin = get_nearest_bin(x)

	if ((x-nearest_bin + 1) %2) == 0:
		ans = 0
	else:
		ans = nearest_bin

	return ans ^ func(x - nearest_bin)


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

if A == B:
	print(A)

elif A == 0:
	print(func(B))
else:
	print(func(A-1)^func(B))

Solution (Python):
from functools import reduce

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


def xor(a, b):
    return a ^ b


def solve(a, b):
    return reduce(xor, range(a, b+1))


def f(a):
    """
    xor [0,a]
    """
    ans = 0
    l = []
    d = 2
    while (a+1)//d > 0:
        t = (a+1)//d*(d//2)+max((a+1) % d-d//2, 0)
        ans += (t % 2)*(d//2)
        l.append(t % 2)
        d *= 2
    ans += (((a+1)-d) % 2)*(d//2)
    l.append(((a+1)-d) % 2)
    return l


def solve2(a, b):
    rb = f(b)
    ra = f(a-1)
    for i in range(len(ra)):
        rb[i] ^= ra[i]
    ans = "".join(map(str, reversed(rb)))
    print(int(ans, 2))


A, B = map(int, input().split())
if A == 0 and B == 0:
    print(0)
else:
    solve2(A, B)

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

def f(n):
    ret=[]
    for i in range(1,49):
        a = 2**i
        b = (n+a//2)//a
        if a>(n+a//2):
            break
        c = (b-1)*(2**(i-1)) + min((n+a//2)-a*b+1, a//2)
        ret.append(c)
    return ret

l1 = f(B)
l2 = f(A-1) if A>0 else []
l2 += [0]*(len(l1)-len(l2))
l3 = []
for i in range(len(l1)):
    l3.append((l1[i]-l2[i])%2)

ans = 0

for i in range(len(l3)):
    ans += (2**i)*l3[i]

print(ans)

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

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

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

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

def f(x):
    if x<=0:
        return [0]
    k=2
    l = []
    while True:
        mul = k>>1
        if mul>x:
            fin = mul>>1
            l[-1]=x-fin+1
            break
        fin = mul>>1
        l.append(x//k*mul+max(x%k+1-k//2,0))
        k = k<<1
    l = l[::-1]
    return l
l1 = f(b)
l2 = f(a-1)
k=1
ans=0
while not l1==[]:
    if l2==[]:
        t = l1.pop()
        if t%2==1:
            ans+=k
    else:
        t = l1.pop()-l2.pop()
        if t%2==1:
            ans+=k
    k = k<<1
print(ans)

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

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

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

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


_beki = [None] * 50
def ni_beki(n):
    return 2 ** n



def f(x, n):
     a, b = divmod(x, ni_beki(n+1))
     p = ni_beki(n)
     return a * p + max(b - (p - 1), 0)


def g(n):
    c = 0
    while True:
        if ni_beki(c) >= n + 1:
            return c
        c += 1

keta = g(B)

d = []
for i in range(keta):
    p = f(B, i)
    q = f(A-1, i)
    d.append(p - q)


d.reverse()


e = list(map(lambda x: str(x % 2), d))


e = ''.join(e)

if e == '':
    e = "0"
print(int(e, 2))

Solution (Python):
a,b=map(int,input().split())
ad=[]
bd=[]
cd=[]
ifa=a
ifb=b
for i in range(40):
    ad+=[a%2]
    a=a//2
for i in range(40):
    bd+=[b%2]
    b=b//2
a=ifa
b=ifb
z=1
for i in range(40):
    z=z*2
    ak=0
    bk=0
    if(ad[i]!=0):
        ak=z-a%z
    if(bd[i]!=0):
        bk=b%z+1-z//2
    cd+=[(ak+bk)%2]
if((a-b+1)%2==0):
    cd[0]=((b-a+1)//2)%2
else:
    cd[0]=(((b-a+1)//2)%2+ad[0])%2
ans=0
z=1
for i in range(40):
    ans+=cd[i]*z
    z=z*2
print(ans)

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

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

x = bin(b)[2:]
l = len(x)

if a > 0: a = a - 1

aa = a%4
if aa == 1 or aa == 2: axor = "1"
else: axor = "0"
bb = b%4
if bb == 1 or bb == 2: bxor = "1"
else: bxor = "0"

for x in range(1,l):
  q = 2**(x+1)
  
  
  ll = a % q
  if ll < (q/2): axor = "0" + axor
  else: 
    if a % 2 == 0: axor = "1" + axor
    else: axor = "0" + axor

  
  
  ll = b % q
  if ll < (q/2): bxor = "0" + bxor
  else: 
    if b % 2 == 0: bxor = "1" + bxor
    else: bxor = "0" + bxor

if a == -1:
  print int(bxor,2)
else: 
  print int(axor,2) ^ int(bxor,2)

Solution (Python):



def f(n):
    if n & 1:
        return 1 ^ ((n >> 1) & 1)
    else:
        return n ^ ((n >> 1) & 1)

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

print(f(B) ^ A ^ f(A))

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

ans = [0]*40

def f(n):
    ret = [0]*40
    if n%4 == 1 or n%4 == 2:
        ret[0] = 1
    else:
        ret[0] = 0
    
    for i in range(1,40):
        m = i+1
        tmp = (n+1)%(2**m)
        if tmp<=2**(m-1):
            ret[i] = 0
        else:
            ret[i] = (tmp-2**(m-1))%2
    return ret

fa = f(a-1)
fb = f(b)
ans = 0
for i in range(40):
    if (fb[i]-fa[i])%2==1:
       ans += 2**i
print(ans)

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
for bit in range(40):
  if bit==0:
    if a%2==1 and b%2==1:
      ans+=((b-a+2)//2%2)
    elif a%2==0 and b%2==0:
      ans+=(b-a)//2%2
    else:
      ans+=((b-a+1)//2%2)
    continue
  cnt=0
  d=2**bit
  if a&d:
    cnt+=d-a%d
  if b&d:
    cnt+=b%d-d+1
  if cnt%2==1:
    ans+=d

print(ans)

Solution (Python):
A, B = map(int, input().split())
num_sum = (B - A) + 1
b_bin = format(B, 'b')
a_minus1_bin = format(A - 1, 'b').zfill(len(b_bin))

a_bin = a_minus1_bin[::-1]
b_bin = b_bin[::-1]

def cal(keta, maxi):
    q, mod = divmod(maxi, 2 ** keta)
    num_ones = q * (2 ** (keta - 1))

    s = mod - 2 ** (keta - 1)
    if s > 0:
        num_ones += s
    return num_ones

def cal_ones(keta):
    num_ones_b = cal(keta, B + 1)
    num_ones_a = cal(keta, A)
    return (num_ones_b - num_ones_a) % 2



str_ans = ""
for keta, (_a, _b) in enumerate(zip(a_bin, b_bin)):
    cur_str = cal_ones(keta + 1)
    str_ans += "{}".format(cur_str)

str_ans = str_ans[::-1]
print(int(str_ans, 2))

Solution (Python):
a,b=map(int,input().split())
a1=a//4+1
b1=b//4
sum=a
k=a+1
while k<a1*4:
    sum=sum^k
    k+=1
k=b1*4
while k<=b:
    sum=sum^k
    k+=1
print(sum)

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

bit=[0 for i in range(50)]

if int(bin(A)[-1])==0:
    if int(bin(B)[-1])==0:
        if (B-A)%4==2:
            bit[1]+=1
    else:
        if (B-A+1)%4==2:
            bit[1]+=1
else:
    if int(bin(B)[-1])==0:
        if (B-A+1)%4==2:
            bit[1]+=1
    else:
        if (B-A)%4==0:
            bit[1]+=1

for i in range(2,50):
    if len(bin(A))-2>=i:
        if int(bin(A)[-i])!=0:
            if A%2!=0:
                bit[i]+=1

    if len(bin(B))-2>=i:
        if int(bin(B)[-i])!=0:
            if B%2==0:
                bit[i]+=1
            

ans=0
for i in range(1,50):
    
    ans+=(bit[i]%2)*(2**(i-1))

print(ans)

Solution (Python):

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

K=1000

L=[0 for i in range(K+1)]

for k in range(K,-1,-1):
	cnt=0
	sho=(B+1)/(2**(k+1))	
	amari=(B+1)%(2**(k+1))	
	cnt=sho*(2**k)+max(0,amari-2**k)	

	L[k]+=cnt

for k in range(K,-1,-1):
	cnt=0
	sho=A/(2**(k+1))	
	amari=A%(2**(k+1))	
	cnt=sho*(2**k)+max(0,amari-2**k)	

	L[k]-=cnt

ans=0
for i in range(K+1):
	ans+=2**i*(L[i]%2)

print ans

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

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

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

result = sum_A ^ sum_B

print(result)

Solution (Python):
def f(x, y):
  return g(x-1) ^ g(y)

def g(x):
  if x < 0:
    return 0
  res = 0
  res ^= ((x+1)>>1) & 0b1
  i = 0b10
  while i <= x:
    if (x&i)!=0 and (x&1)==0:
      res ^= i
    i <<= 1
  return res

a, b = [int(x) for x in input().split()]
print(f(a,b))

Solution (Python):
A, B = map(int, input().split())
a0 = A % 2
b0 = B % 2
b0i = b0 ^ 1
A //= 2
B //= 2
f = (A % 2) ^ ((B % 2) ^ b0)
i = 1
while B > 0:
  a = (A % 2) & a0
  A //= 2
  b = ((B % 2) & b0i) ^ a
  B //= 2
  f += b * (2 ** i)
  i += 1
print(f)

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

for i in range(50):
    if pow(2, i) >= max(A, B):
        maxk = i
        break
lisA = [-1] * (maxk + 1)
lisB = [-1]*(maxk+1)

for i in range(maxk+1):
    lisA[i] = A % pow(2, i+1)
    
    
    lisB[i] = B % pow(2, i+1)
    
    



ans = [-1] * (maxk + 1)

for i in range(1, maxk + 1):
    if lisA[i] >= pow(2, i) and lisB[i] >= pow(2, i):
        ans[i] = (abs(lisA[i] - lisB[i]) + 1) % 2
    elif lisA[i] >= pow(2, i) and lisB[i] < pow(2, i):
        ans[i] = (pow(2, i+1)-lisA[i]) % 2
    elif lisB[i] >= pow(2, i) and lisA[i] < pow(2, i):
        ans[i] = (lisB[i] - pow(2, i)+1) % 2
    else:
        ans[i] = 0
if A % 2 == 0:
    if (B - A) % 4 == 0 or (B - A) % 4 == 3:
        ans[0] = 0
    else:
        ans[0] = 1
else:
    if (B - A) % 4 == 1 or (B - A) % 4 == 0:
        ans[0] = 1
    else:
        ans[0] = 0



ans2 = 0
for i in range(maxk+1):
    ans2 += pow(2, i)*ans[i]
print(ans2)

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

A -= 1
num = 0
n = 1
while n <= B:
    count = 0
    m = n * 2
    a1 = 0
    b1 = 0
    if A >= n:
        a1 = (A // m) * n
        r = A % m
        if r >= n:
            a1 += r - n + 1
    if B >= n:
        b1 = (B // m) * n
        r = B % m
        if r >= n:
            b1 += r - n + 1
    num += ((b1 - a1) % 2) * n

    n = n * 2
print(num)

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

A=max(A-1,0)
LA=[]
LB=[]
if A%4==1 or A%4==2:
    LA.append(1)
else:
    LA.append(0)
if B%4==1 or B%4==2:
    LB.append(1)
else:
    LB.append(0)
    
for i in range(2,41):
    if (A%(2**i))%2==1:
        LA.append(0)
    else:
        if (A%(2**i))>=(2**(i-1)):
            LA.append(1)
        else:
            LA.append(0)
    if (B%(2**i))%2==1:
        LB.append(0)
    else:
        if (B%(2**i))>=(2**(i-1)):
            LB.append(1)
        else:
            LB.append(0)
Lans=[]
for i in range(len(LA)):
    Lans.append((LA[i]+LB[i])%2)

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

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

c = 0

for i in range(2, 41):
    a_mod = A % (2 ** i)
    b_mod = B % (2 ** i)
    if (a_mod <= (2 ** (i-1))-1) and (b_mod <= (2 ** (i-1))-1):
        c += 0
    if (a_mod <= (2 ** (i-1))-1) and (b_mod > (2 ** (i-1))-1):
        c += (2 ** i) * ((b_mod+1) % 2)
    if (a_mod > (2 ** (i-1))-1) and (b_mod <= (2 ** (i-1))-1):
        c += (2 ** i) * ((a_mod) % 2)
    if (a_mod > (2 ** (i - 1))-1) and (b_mod > (2 ** (i - 1))-1):
        c += (2 ** i) * ((a_mod+b_mod+1) % 2)

c = int(c/2)

if A % 2 == 0:
    if ((B-A) % 4 == 1) or ((B-A) % 4 == 2):
        c += 1
    else:
        c += 0
if A % 2 == 1:
    if ((B - A) % 4 == 0) or ((B - A) % 4 == 1):
        c += 1
    else:
        c += 0
print(c)

Solution (Python):
a = list(map(int, input().split()))
res = 0
x = a[0] % 4
if x != 0:
    for i in range(4-x):
        res = res ^ (a[0] + i)
    a[0] = a[0] + 4 - x
        
m = (a[1] - a[0]) % 4 + 1
if m != 0:
    for i in range(m):
        res = res ^ (a[1] - i)
    
print(res)

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

def f0(n):
    l = len(bin(n)) - 2
    v = 0
    for i in range(l):
        if i >= 1:
            m = n % (1 << i + 1)
            if m >= (1 << i):
                v += ((m + 1) % 2 << i)
        else:
            v += ((n + 1) % 4) // 2
    return v

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

Solution (Python):
a,b=map(int,input().split())
x=0
while a%4>0:x^=a;a+=1
while b%4<3:x^=b;b-=1
print(x)

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

def unko(x):
    ans = 0
    po = 1
    for i in range(64):
        a = x % (po << 1)
        if (a >= po and a % 2 == 0) or (po == 1 and ((x + 1) // 2) % 2 == 1):
            ans = ans | po
        po = po << 1
    return ans

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

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




















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

def func(c):
	if c%2==1:
		if c%4==1:
			return 1
		else:
			return 0
	else:
		if (c-1)%4==1:
			return 1^c
		else:
			return 0^c
print(func(A-1)^func(B))

Solution (Python):
def xor(x, y):
    return (x | y) - (x & y)

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

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

    res_A = get_res(A - 1) if A > 0 else 0
    res_B = get_res(B)
    print(xor(res_A, res_B))    

if __name__ == '__main__':
    main()

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

Ans = (B // 2 + B % 2 - ((A - 1) // 2 + (A - 1) % 2)) % 2
cnt = 1
while True:
  p = pow(2, cnt)
  if p > B:
    break
  ma = (A - 1) % (p * 2)
  a = max(0, 1 + ma - p)

  mb = B % (p * 2)
  b = max(0, 1 + mb - p)

  t = abs(b - a)
  if t % 2 == 1:
    Ans += p
  cnt += 1
print(Ans)

Solution (Python):
import sys
DBG =  not True
ex = 42

def h(x,i):
    y = x % (2**(i+1))
    if i == 0:
        y = x % 4
        ret = 1 if y==1 or y==2 else 0
    elif y < 2**i:
        ret = 0
    else:
        ret = 1 - (y - 2**i)%2
    if DBG:
        print("h x {} i {} y {} ret {}".format(x,i,y,ret))
    return ret

def g(x):
    if x < 0:
        return 0
    sum = 0
    for i in range(ex):
        sum += h(x,i) << i
    if DBG:
        print("g x {} ret {}".format(x,sum))
    return sum

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

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    a, b = LI()

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

    return func(b) ^ func(a - 1)


print(main())

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

xor_sum = 0

for i in range(a, a+5): 
  if i % 4 == 0:
    break
  else:
    xor_sum = xor_sum ^ i

for i in range((b-b%4),b+1):
  xor_sum = xor_sum ^ i
  
  
print(xor_sum)