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=map(int,input().split())

l=[]
temp=2
while True:
    l.append(temp)
    temp*=2
    if temp>B:
        break

ans=0

judge=((B//2+B%2)-(A//2+A%2))
if A%2==1:
    judge+=1
if judge%2==1:
    ans+=1

for i in range(len(l)):
    temp=0
    if (A%(2*l[i]))>=l[i]:
        if (A%l[i])%2 == 1:
            temp^=1
        
    if (B%(2*l[i]))>=l[i]:
        if (B%l[i])%2 == 0:
            temp^=1
    else:
        
        pass
        
    if temp==1:
        ans+=l[i]

print(ans)

"""
1 4つの内2で割れるところが何個あるか
01010101
2 4つの内であまりが2以上で何個あるか
00110011
4 8つの内であまりが4以上で何個あるか
0000111100001111
"""

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

a1 = 0
b1 = 0
l = []
if a % 2 != 0:
   a1 = 1
if b % 2 == 0:
   b1 = 1
if a1 == 1:
   l.append(a)
one = b - a + 1 - a1 -b1
if one // 2 % 2 == 0:
   l.append(0)
if one // 2 % 2 == 1:
   l.append(1)
if b1 == 1:
   l.append(b)

if len(l) == 1:
   print(l[0])
if len(l) == 2:
   print(l[0]^l[1])
if len(l) == 3:
   print(l[0]^l[1]^l[2])

Solution (Python):
a,b=map(int,input().split())
a=max(0,a-1)

if a%4==0:
    a=a
elif a%4==1:
    a=1
elif a%2==0:
    a=a+1
else:
    a=0
if b%4==0:
    b=b
elif b%4==1:
    b=1
elif b%2==0:
    b=b+1
else:
    b=0
print(a^b)

Solution (Python):
A, B = map(int, input().split())
N = len(bin(10**12)[2:])
ans = 0
A = max(0, A - 1)
for i in range(N):
    k = 1 << i
    k2 = k * 2
    a = A // k2 * k + max(0, A % k2 - k + 1)
    b = B // k2 * k + max(0, B % k2 - k + 1)
    ans += (b - a) % 2 * k
print(ans)

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

def func(a):
    if a%4==0:
        a = a
    elif a%4==1:
        a = 1
    elif a%4==2:
        a = 4*(a//4) + 3
    else:
        a = 0
    return a

x,y = func(a-1), func(b)
print(x^y)

Solution (Python):
import math
l,r=map(int,input().split())

t=r
c=0
while(t!=0):
    c+=1
    t//=2
LIST=[0]*c

if(c==0):
    print(0)
    exit()

l=l-1

t1=math.ceil(l/2)
t2=math.ceil(r/2)
LIST[-1]=((t2-t1)%2)*(2**(0))

for i in range(2,c+1):
    k=(l-(l//2**i)*(2**i))+1
    t1=max(k-((2**i)//2),0)

    k=(r-(r//2**i)*(2**i))+1
    t2=max(k-((2**i)//2),0)
 
    LIST[-i]=((t2-t1)%2)*(2**(i-1))

print(sum(LIST))

Solution (Python):
A, B = map(int, input().split())
LA, LB = [], []
i = 1
if A == 0:
  A += 1
while (A-1) // i != 0 or B // i != 0:
  if (A-1)%(2*i) >= i:
    LA.append(i*((A-1)//(2*i)) + (A-1) % (2*i) - i + 1)
  else:
    LA.append(i*((A-1)//(2*i)))
  if B%(2*i) >= i:
    LB.append(i*(B//(2*i)) + B % (2*i) - i + 1)
  else:
    LB.append(i*(B//(2*i)))
  i *= 2
S = 0
m = 1
for i in range(len(LA)):
  S += m * ((LB[i] - LA[i]) % 2)
  m *= 2
print(S)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])

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

def main():
    a,b = inpm()
    a -= 1
    print(f(a)^f(b))

if __name__ == "__main__":
    main()

Solution (Python):
a, b = map(int, input().split())
def ruiseki_xor(n):
    res = []
    x = 2
    while n*2 >= x:
        
        res.append((n//x * x//2 + max(0, n%x - (x//2-1)))%2)
        x *= 2
    res.reverse()
    if n <= 0:
        return "0"
    return "".join(map(str, res))



print(int(ruiseki_xor(a-1), 2)^int(ruiseki_xor(b), 2))

Solution (Python):
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



A, B = list(map(int, sys.stdin.buffer.readline().split()))


c = int(math.ceil(B / 2) * 2) - int(math.ceil(A / 2) * 2)
if c % 4 == 0:
    
    ret = 0
elif c % 2 == 0:
    
    ret = 1
else:
    assert False

if A % 2 == 1:
    ret ^= A
if B % 2 == 0:
    ret ^= B
print(ret)

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

if a%2 == 0 and b%2 == 0:
    ans = b^((b-a)//2)%2
elif a%2 == 0 and b%2 != 0:
    ans = ((b-a+1)//2)%2
elif a%2 != 0 and b%2 == 0:
    ans = a^b^((b-1-a)//2)%2
else:
    ans = a^((b-a)//2)%2

print(ans)

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

def calc(x): 
    if x == 0: return 0
    res = 0
    x += 1
    for i in range(64):
        length = 2**i
        cycle = 2**(i+1)
        num = (x // cycle) * length
        if (x % cycle) > length: num += x % cycle - length
        if num%2: res += 2**i
    return res
'''
def calc2(x):
    res = 0
    for i in range(x+1): res ^= i
    return res

for i in range(100):
    a, b = calc(i), calc2(i)
    assert a == b ,f'i={i}, a={a}, b={b}'
'''

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

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


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


if __name__ == '__main__':
    solve()

Solution (Python):




from functools import reduce

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

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


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

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

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

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

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

Solution (Python):
A,B=map(int,input().split())
k=len(bin(B))-2
ans=0
for i in range(k):
  diff=(B- max(2**i,A))
  t=2**(i+1)
  l=2**i
  tmp=((diff+1)//t)*l
 
  C=max(A,l)+tmp*t - 1
  if B%t >= C%t:
    tmp+= max(0,(B%t -(l-1)) - max(0,(C%t-(l-1))))
  else:
    tmp+= max(0,B%t-(l-1)) +(min(l,t-1-C%t))
  if tmp%2==1:
    ans+=2**i
print(ans)

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 RT(num):
  if num%4 == 0:
    ans = num
  elif num%4 == 1:
    ans = 1
  elif num%4 == 2:
    ans = 1 ^ num
  elif num%4 == 3:
    ans = 0
  return ans
A,B=map(int,input().split())
print(RT(B)^RT(A-1))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

def xor(x):
  if x <= 0:
    return 0
  if x == 1:
    return 1
  if x == 2:
    return 3
  if x == 3:
    return 0
  t = 2 ** (len(bin(x))-3)
  if x==t:
    return t
  return t*((x-t)%2^1) + xor(x-t)
a, b = map(int, input().split())
print(xor(b) ^ xor(a-1))

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

def g(x):
  y = x % 4
  if y == 0: return x
  if y == 1: return 1
  if y == 2: return x ^ 1
  if y == 3: return 0
  
print(g(a-1) ^ g(b))

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

def f(n, k):
    if n < 0:
        return 0
    if n // 2**k == 0:
        if n >= 2**(k-1):
            return n - 2**(k-1) + 1
        else:
            return 0
    else:
        return int((n // 2**k) * (2**(k-1))) + f(n-(n // 2**k)*(2**k), k)

ans = []
for k in range(1, len(bin(10**12))-1):
    b = f(B, k)
    a = f(A-1, k)
    one = b-a
    if one % 2 == 0:
        ans += '0'
    else:
        ans += '1'

ans.reverse()
print(int(''.join(ans), 2))

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

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

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

Solution (Python):
def func(x):
    x += 1
    res = 0
    for d in range(50):
        loop = 2 ** (d + 1)
        cnt = (x // loop) * (2 ** d)

        if (x % loop) - (2 ** d) > 0:
            cnt += (x % loop) - (2 ** d)

        if cnt % 2 != 0:
            res += 2 ** d
    return res


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

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


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b = inpl()
x = y = z = 0
if a%2:
    x = a
    a += 1
if b%2 == 0:
    y = b
    b -= 1
if (b-a+1) % 4:
    z = 1
print(x^y^z)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b = inpl()

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

def cal(a,c):
    block_count = a // (c*2)
    tmp = a % (c*2)
    if tmp < c:
        tmp = 0
    else:
        tmp -= c-1
    return block_count * c + tmp
res = 0
ln = len(bin(b)) - 2 
for i in range(ln):
    c = pow(2,i)
    if (cal(b,c) - cal(a-1,c)) % 2:
        res += c
    

print(res)

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

def xor(n):
    ret=0
    i=1
    while True:
        div,mod=divmod(n,i)
        flg=i*(div//2)
        if div%2==1:
            flg+=(mod+1)
        if flg%2==1:
            ret+=i
        i*=2
        if i>n:
            break
    return ret
print(xor(a-1)^xor(b))

Solution (Python):
f = lambda a: (((a + 1) // 2) % 2) if a % 2 else ((a // 2) % 2) ^ a
g = lambda a, b: f(a - 1) ^ f(b)

print(g(*map(int, input().split())))

Solution (Python):

import sys
input = sys.stdin.readline

a,b = list(map(int,input().split()))
if a==0 and b==0:
    ret = 0
else:
    if a==0:
        a = 1

def bid_cnt(n):
    bid_list = [0 for i in range(40)]
    bid_list[0] = n//2+n%2
    i = 1
    two_i = 2**i
    while two_i <= n:
        if (n//two_i)%2==0:
            bid_list[i]==0
        else:
            bid_list[i] = (n//two_i)%2+(n%two_i)
        i+=1
        two_i = 2**i
    return bid_list

a_bid_cnt = bid_cnt(a-1)
b_bid_cnt = bid_cnt(b)
ab_bid_cnt_dif = [(i-j)%2 for i,j in zip(b_bid_cnt,a_bid_cnt)]
print(sum([v*2**i for i,v in enumerate(ab_bid_cnt_dif)] ))

Solution (Python):
A,B=map(int,input().split())
a=A%2>0
b=B%2<1
print(A*a^((B-b-(A-1^a))//2%2)^B*b)

Solution (Python):
A,B=map(int,input().split())
a=A%2>0
b=B%2<1
print((A*a)^(((B-b)-(A-1^a))//2%2)^(B*b))

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




cnt1=0
restA=(A%2==1)
restB=(B%2==0)
cnt1=((B-(restB))-(A-(not restA)))//2

print((A*restA)^(cnt1%2)^(B*restB))

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


def f(b):
    l=[]
    n=0
    while not 2**n<=b<2**(n+1):
        n+=1

    for i in range(n):
        if (b-2**n)>(2**i-1):
            if ((b-2**n-(2**i-1))//2**i)//2==((b-2**n-(2**i-1))//2**i)/2:
                l.append((((b-2**n-(2**i-1))//2**i)//2)*(2**i)+((b-2**n-(2**i-1))%(2**i)))

            else:
                l.append(((((b-2**n-(2**i-1))//2**i)//2)+1)*(2**i))

        else:
            l.append(0)
            
    l.append((b-2**n)+1)
    for i in range(n):
        l[i]=l[i]+2**(n-1)

    return (l)

l=[]
m=0
if a>0 and b>0:
    c=f(a-1)
    d=f(b)
    for i in range(len(d)-len(c)):
        c.append(0)

    for i in range(len(d)):
        l.append(d[i]-c[i])
elif a==0 and b>0:
    l=f(b)
else:
    l=[]
    m=0


    
for i in range(len(l)):
    if not l[i]//2==l[i]/2:
        m+=2**i
print(m)

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

keta=0
b=B
while b:
  keta+=1
  b>>=1
  
d=[0]*keta

for i in range(keta):
  paircnt=2**(i+1)
  BpairBit=(B+1)//paircnt*(paircnt//2)
  
  rest=(B+1)%paircnt
  if rest>paircnt//2:
    BpairBit+=(rest-paircnt//2)
    
  ApairBit=A//paircnt*(paircnt//2)
  restA=A%paircnt
  if restA>paircnt//2:
    ApairBit+=(restA-paircnt//2)
    
  d[i]=(BpairBit-ApairBit)%2
  
ans=0
for i in range(len(d)):
  ans+=d[i]*(2**i)

print(ans)

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

keta=0
b=B
while b:
  keta+=1
  b>>=1
  
d=[0]*keta

for i in range(keta):
  
  paircnt=2**(i+1)
  
  Bpair=(B+1)//paircnt
  
  BpairBit=Bpair*(paircnt//2)
  
  rest=(B+1)%paircnt
  if rest>paircnt//2:
    BpairBit+=(rest-paircnt//2)
    
  Apair=A//paircnt
  ApairBit=Apair*(paircnt//2)
  restA=A%paircnt
  if restA>paircnt//2:
    ApairBit+=(restA-paircnt//2)
    
  bitCnt=BpairBit-ApairBit
  d[i]=bitCnt%2
  
ans=0
for i in range(len(d)):
  ans+=d[i]*(2**i)

print(ans)

Solution (Python):


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

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

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

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

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

Solution (Python):
a,b = map(int, input().split(' '))
binA = format(a,"b")
binB = format(b,"b")
ans = 0
for i in range(1,50):
    if b<2**(i-1):
        break
    nm1 = b//(2**i)*(2**(i-1))-(a+2**i-1)//(2**i)*(2**(i-1))
    if b%(2**i) != 0:
        nm1 += max(0, b%(2**i)-2**(i-1)+1)
    if a%(2**i) != 0:
        nm1 += min(2**(i-1), 2**i - a%(2**i))
    if nm1 % 2 == 1:
        ans += 2**(i-1)
print(ans)

Solution (Python):
def p_d():
    L, R = map(int, input().split())

    def f(x):
        tmp = 0
        if not (x & 1):
            tmp = x
            x -= 1
        x = 0 if (x - 3) % 4 == 0 else 1
        return x + tmp

    print(f(L - 1) ^ f(R))


if __name__ == '__main__':
    p_d()

Solution (Python):
a,b = map(int,input().split())
if a==b:
  print(a)
else:
  ans = a
  if b-a<10**7:
    for i in range(a+1,b+1):
      ans = ans^i
    print(ans)
  else:
    if a%2==0:
      if (b-a)%4==1:
        print(1)
      elif (b-a)%4==2:
        print(b+1)
      elif (b-a)%4==3:
        print(0)
      else:
        print(b)
    else:
      if (b-a)%4==1:
        print(a^b)
      elif (b-a)%4==2:
        print(a-1)
      elif (b-a)%4==3:
        print((a-1)^b)
      else:
        print(a)

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



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

Solution (Python):


import sys

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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B = MAP()

if A % 2 == 1:
    a = A
    A += 1
else:
    a = 0

seg = B - A + 1
if seg % 4 == 0:
    b = 0
elif seg % 4 == 1:
    b = B
elif seg % 4 == 2:
    b = 1
else:
    b = 1 ^ B

print(a ^ b)

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



def g(n):
    one = (n + 1) // 2
    ret = one % 2

    if n % 2 == 0:
        ret ^= n

    return ret

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

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

Solution (Python):






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





def func(A):
    ret = []
    if A % 4 == 1 or A % 4 == 2:
        ret.append(1)
    else:
        ret.append(0)

    m = 4
    while True:
        if A % m  < m // 2:
            ret.append(0)
        elif A % 2 == 0:
            ret.append(1)
        else:
            ret.append(0)
        
        if m > A:
            break
        m *= 2
        
    return ret





a = func(A - 1)
b = func(B)
a += [0] * (len(b) - len(a))





ans = ''
for i in range(len(a)):
    ans = str(a[i]^b[i]) + ans





a, b, ans





print(int(ans, 2))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()

input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    a=sorted([-1*random.randint(1,5) for _ in range(n)])[::-1]
    return n,a

show_flg=False
show_flg=True

x,y=MI()
n=64
a=0
def f(x):
    if x%4==0:
        r=x
    elif x%4==1:
        r=1
    elif x%4==2:
        r=x+1
    else:
        r=0
    return r
    
print(f(x-1)^f(y))

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

while d <= 10**12:
    d2 = d * 2
    asum = a//d2 * d + max(0, a % d2 + 1 - d)
    bsum = b//d2 * d + max(0, b % d2 + 1 - d)
    ans += (bsum - asum) % 2 * d
    d *= 2

print(ans)

Solution (Python):
from sys import stdin
A, B = [int(x) for x in stdin.readline().rstrip().split()]
def binary_(A):
    A += 1
    n = 0
    ans = 0
    while 2 ** n <= A:
        a = 2 ** n
        a_ = a * 2
        b = A // a_
        b = b * a
        c = A % a_
        if c > a:
            d = (b + c - a) % 2
            ans += a * d
        elif c == 0:
            d = b % 2
            ans += a * d
        else:
            d = b % 2
            ans += a * d
        n += 1
    return ans
print(binary_(A-1) ^ binary_(B))

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


def f_0(b):
    
    if b == 0:
        return 0
    if b % 2 == 1:
        res = 1 if (b // 2) % 2 == 0 else 0
        return res
    else:
        res = f_0(b - 1) ^ b
        return res


if a == b:
    ans = a
else:
    fa = f_0(a-1)
    fb = f_0(b)
    ans = fa ^ fb
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def calc(x):
    if x == 0:
        return 0
    r = x % 4
    if r == 0:
        return x
    elif r == 1:
        return 1
    elif r == 2:
        return 1 ^ x
    else:
        return 0
def print_ans(A, B):
    """Test Case
    >>> print_ans(2, 4)
    5
    >>> print_ans(123, 456)
    435
    >>> print_ans(123456789012, 123456789012)
    123456789012
    """
    tmp = calc(A -1)
    tmp2 = calc(B)
    print(tmp ^ tmp2)

    

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

Solution (Python):
def f(x):
    """[0,x]の排他的論理和"""
    if x < 0:
        return 0  
    r = x % 4
    if r == 0:
        return x
    elif r == 1:
        return 1
    elif r == 2:
        return x ^ 1
    else:
        
        return 0


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

Solution (Python):
a,b=map(int,input().split())
print([[b,1,1^b,0],[a,a^b,a^1,a^b^1]][a%2][(b-a)%4])

Solution (Python):
a, b = map(int, input().split())
mod = (b-a) % 4

if a % 2 == 0:
    if mod == 0:
        c = b
    elif mod == 1:
        c = 1
    elif mod == 2:
        c = 1 ^ b
    else:
        c = 0

else:
    if mod == 0:
        c = a
    elif mod == 1:
        c = a ^ b
    elif mod == 2:
        c = a ^ 1
    else:
        c = a ^ b ^ 1

print(c)

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

def s(x):
    xbin = bin(x)[2:]
    l = len(xbin)
    tmp = 0
    for i in range(l):
        if i != l - 1:
            rem = x % (2 ** (l - i))
            rem2 = rem - (2 ** (l - i - 1))
            
            if rem2 >= 0 and rem2 % 2 == 0:
                tmp += 2 ** (l - i - 1)
        else:
            rem = x % 4
            if rem in [1, 2]:
                tmp += 1
    return tmp

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

Solution (Python):

a,b = map(int,input().split())
a -= 1
c = [a,b]
ans = 0
for x in c:
  if x % 4 == 0:
    ans ^= x
  elif x % 4 == 1:
    ans ^= 1
  elif x % 4 == 2:
    ans ^= x + 1
print(ans)

Solution (Python):
import math


def bits(n, max_bits):
    return [int(x) for x in format(n, '0{}b'.format(max_bits))]


def my(A, B):
    max_bits = len(bin(B)[2:])
    c = [0] * max_bits
    ans = -1

    
    
    
    
    

    
    
    
    

    
    

    
    
    
    pair = []
    for C in [A-1, B]:
        cur = 1
        bit_list = []
        for i in range(0, max_bits):
            a = C // (cur * 2)
            b = C % (cur * 2)
            
            bit_list.append((a * cur) + max((b - cur) + 1, 0))
            
            cur *= 2
        
        pair.append(bit_list)

    pair[0] = pair[0][::-1]
    pair[1] = pair[1][::-1]
    for i in range(max_bits):
        c[i] = pair[1][i] - pair[0][i]

    ans = ''
    for i in range(max_bits):
        if c[i] % 2 == 0:
            ans += '0'
        else:
            ans += '1'

    print(int(ans, 2))
    


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


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

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


if __name__ == '__main__':
    main()

Solution (Python):
import math


def bits(n, max_bits):
    return [int(x) for x in format(n, '0{}b'.format(max_bits))]


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

    max_bits = len(bin(B)[2:])
    c = [0] * max_bits
    ans = -1

    
    
    
    
    

    
    
    
    

    
    

    
    
    
    pair = []
    for C in [A-1, B]:
        cur = 1
        bit_list = []
        for i in range(0, max_bits):
            a = C // (cur * 2)
            b = C % (cur * 2)
            
            bit_list.append((a * cur) + max((b - cur) + 1, 0))
            
            cur *= 2
        
        pair.append(bit_list)

    pair[0] = pair[0][::-1]
    pair[1] = pair[1][::-1]
    for i in range(max_bits):
        c[i] = pair[1][i] - pair[0][i]

    ans = ''
    for i in range(max_bits):
        if c[i] % 2 == 0:
            ans += '0'
        else:
            ans += '1'

    print(int(ans, 2))
    


if __name__ == '__main__':
    main()

Solution (Python):
A,B = [int(i) for i in input().split()]
if A==B:
    print(A)
elif A%2==0:
    A = A+((B-A-1)//4)*4
    ans = 0
    for i in range(A,B+1):
        ans = ans^i
    print(ans)
else:
    buff = A
    A = A+1
    A = A+((B-A-1)//4)*4
    ans = 0
    for i in range(A,B+1):
        ans = ans^i
    print(ans^buff)

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

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

Solution (Python):
def F(x, t, ans):
    if t != 0:
        if x < 2**t:
            ans += '0'
            t -= 1
            return F(x, t, ans)
        else:
            x_n = x - 2**t + 1
            if x_n % 2 == 1:
                ans += '1'
                t -= 1
                return F(x_n - 1, t, ans)
            else:
                ans += '0'
                t -= 1
                return F(x_n - 1, t, ans)
    else:
        return ans

a,b = [int(_) for _ in input().split()]
t1 = F(a-1, 39, '')
ex = (a-1) % 4
if ex == 0:
    t1 += '0'
elif ex == 1:
    t1 += '1'
elif ex == 2:
    t1 += '1'
elif ex == 3:
    t1 += '0'
t2 = F(b, 39, '')
ex = b % 4
if ex == 0:
    t2 += '0'
elif ex == 1:
    t2 += '1'
elif ex == 2:
    t2 += '1'
elif ex == 3:
    t2 += '0'
print(int(t1, 2) ^ int(t2, 2))

Solution (Python):
def F(x):
    ex = x % 4
    if ex == 0:
        return 0 ^ x
    elif ex == 1:
        return 1
    elif ex == 2:
        return 1 ^ x
    elif ex == 3:
        return 0

a,b = [int(_) for _ in input().split()]
ans = F(a-1) ^ F(b)
print(ans)

Solution (Python):
a, b = map(int, input().split())
if a%2 == 0:
    if b%2 == 0:
        if ((b-a)//2) % 2 == 0:
            ans = list(map(int, list(format(b, "b"))))
        else:
            b_bin = list(format(b, "b"))
            l = len(b_bin)
            b_bin[l-1] = str((int(b_bin[l-1])+1)%2)
            ans = list(map(int, b_bin))
        answer = 0
        l_ans = len(ans)
        for i in range(l_ans):
            answer += (2**i)*ans[l_ans-i-1]
    else:
        b_len = len(list(format(b, "b")))
        if ((b+1-a)//2) % 2 == 0:
            answer = 0
        else:
            answer = 1
else:
    if b%2 == 1:
        if ((b-a)//2) % 2 == 0:
            ans = list(map(int, list(format(a, "b"))))
        else:
            a_bin = list(format(a, "b"))
            l = len(a_bin)
            a_bin[l-1] = str((int(a_bin[l-1])+1)%2)
            ans = list(map(int, a_bin))
        answer = 0
        l_ans = len(ans)
        for i in range(l_ans):
            answer += (2 ** i) * ans[l_ans - i - 1]
    else:
        if ((b-a-1)//2)%2 == 0:
            flag = 0
        else:
            flag = 1
        answer = b^a
        if flag:
            answer ^= 1

print(answer)

Solution (Python):

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


if A % 2 == 0:
    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    for i in range(b, B+1):
        ans ^= i

    
    
    print(ans)
else:
    a = A
    A += 1

    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    ans ^= a
    for i in range(b, B+1):
        ans ^= i

    
    
    print(ans)

Solution (Python):

import sys

def sum_xor(X: int):
    untilb = 0
    if X%4==3:
        untilb = 0
    elif X%4==1:
        untilb = 1
    else:
        if (X+1)%4==3:
            untilb = 0^(X+1)
        elif (X+1)%4==1:
            untilb = 1^(X+1)

    return untilb

def solve(A: int, B: int):
    print(sum_xor(B)^sum_xor(A-1))
    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):

import sys

def sum_xor(X: int):
    untilb = 0
    if X%4==3:
        untilb = 0
    elif X%4==1:
        untilb = 1
    else:
        if (X+1)%4==3:
            untilb = 0^(X+1)
        elif (X+1)%4==1:
            untilb = 1^(X+1)

    return untilb

def solve(A: int, B: int):
    print(sum_xor(B)^sum_xor(A-1))
    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):
a,b=[int(i) for i in input().split()]

def odd(x):
    ones = (x+1)//2
    if(ones%2):
        return 1
    return 0

def even(x):
    ones = x//2

    if(ones%2):
        return (1^x)
    else:
        return x

if(b%2):
    fir = odd(b)
else:
    fir = even(b)
if((a-1)%2):
    sec = odd(a-1)
else:
    sec = even(a-1)

print((fir)^(sec))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    
    
    
    
    
    

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

    if(B%4==0):
        SB=B
    elif(B%4==1):
        SB=1
    elif(B%4==2):
        SB=B+1
    else:
        SB=0

    A-=1
    if(A<0):
        SA=0
    elif(A%4==0):
        SA=A
    elif(A%4==1):
        SA=1
    elif(A%4==2):
        SA=A+1
    else:
        SA=0

    print(SA^SB)
resolve()

Solution (Python):
s,t=map(int, input().split())
def g(x):
  u=((x-1)//2)%2
  if x%2==0:
    return x^u
  return u
def f(x,y):
  return g(s-1)^g(t)
print(f(s,t))

Solution (Python):
def g(A):
    t = ((A + 1) // 2) % 2
    if A % 2 == 0:
        return A ^ t
    return t


def f(A, B):
    return g(A - 1) ^ g(B)


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

print(f(A, B))

Solution (Python):
def h(A, n):
    if A == -1:
        return 0
    return A // (2 * n) * n + max(A % (2 * n) - (n - 1), 0)


def g(A):
    result = 0
    for i in range(48):
        t = 1 << i
        if h(A, t) % 2 == 1:
            result += t
    return result


def f(A, B):
    return g(A - 1) ^ g(B)


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

print(f(A, B))

Solution (Python):
def g(A, n):
    if A == -1:
        return 0
    return A // (2 * n) * n + max(A % (2 * n) - (n - 1), 0)


def f(A, B):
    result = 0
    for i in range(48):
        t = 1 << i
        if (g(B, t) - g(A - 1, t)) % 2 == 1:
            result += t
    return result


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

print(f(A, B))

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

def calc(x):
    x += 1
    ans = 0
    for i in range(40):
        loop = 1<<(i+1)
        cnt = (x//loop)*(loop//2)
        cnt += max(0, (x%loop)-(loop//2))
        if cnt%2 == 1:
            ans += 1<<i
    return ans

ans = calc(b)^calc(a-1)
print(ans)

Solution (Python):
def F(N): return ((N + 1) // 2) % 2 if N & 1 else ((N // 2) % 2) ^ N
A,B = map(int,input().split())
print(F(A-1) ^ F(B))

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

if b-a < 5:
    res = 0
    for i in range(a,b+1):
        res = res ^ i
    print(res)
else:
    a2 = ((a+3)//4)*4
    b2 = (b//4)*4

    res = 0
    for i in range(a,a2):
        res = res ^ i
    for i in range(b2,b+1):
        res = res ^ i
    print(res)