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(X):
    Y = 1 << 45
    ans = 0
    if ((X+1) // 2) % 2:
        ans ^= 1
    while Y > 1:
        if X >= Y:
            ans += ((X - Y + 1) & 1) * Y
            X -= Y
        Y >>= 1
    return ans
A, B = map(int, input().split())
print(g(B) ^ g(A-1))

Solution (Python):


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

def F(a, b):
    return F_0n(a - 1) ^ F_0n(b)

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

print(F(A, B))

Solution (Python):

import copy
import numpy as np
import random

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



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

    return tmp_ans

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

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

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

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

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

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

print(ans)

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

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

    return digit

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

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

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

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


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

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

print(ans)
'''

Solution (Python):
a,b = map(int,input().split())
def func(x):
    ans = 0
    for i in range(1,41):
        loop = 2**i
        cnt = (x//loop) * (loop//2)
        cnt += max(0,(x%loop)-(loop//2)+1)
        if cnt%2 == 1:
            ans += 2**(i-1)
    return ans

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

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

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


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

Solution (Python):






def calc(A):
    if A < 0:
        return 0

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

a = list(map(int,input().split()))
A = a[0]
B = a[1]
ans = calc(B) ^ calc(A-1)
print(str(ans))

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

def calcXorSum(a):
    bin_a = format(a, 'b')
    N = len(bin_a)
    a += 1
    ans = 0
    for i in range(N):
        unit = 1 << i
        div = int(a / unit)
        res = int(a % unit)
        cnt = unit * int(div / 2)
        if div % 2 == 1:
            cnt += res
        if cnt % 2 == 1:
            ans += 1 << i
    return ans

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

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

def f(x):
  amari = x % 4
  if amari == 0:
    return x
  elif amari == 1:
    return x ^ (x-1)
  elif amari == 2:
    return x ^ (x-1) ^ (x-2)
  elif amari == 3:
    return 0
    
    
A = f(a-1)
B = f(b)


print(A^B)

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

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

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

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

def f(a, b):
    if a > 0:
        return f(0, a - 1) ^ f(0, b)
    if b % 2 == 1:
        return (b + 1) // 2 % 2
    else:
        return b ^ f(0, b - 1)

result = f(A, B)

print(result)

Solution (Python):


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

def func (A, B):
  return calc(A-1) ^ calc(B)


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

A = a[0]
B = a[1]

ans = func(A, B)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
a,b = map(int,input().split())
if a >0:
    a-=1
bit = [0]*42
c = b+0
i= 0
while c>1:
    c//=2
    i+=1
bit[i] += b - 2**i+1
for j in range(i):
    bit[j] += 2**i//2
for j in range(i):
    bit[j] += (b-2**i)//(2**(j+1))*(2**j)
    bit[j] += max(0,(b-2**i)%(2**(j+1))-2**j+1)

b = a
c = b+0
i= 0
while c>1:
    c//=2
    i+=1
bit[i] -= b - 2**i+1
for j in range(i):
    bit[j] -= 2**i//2
for j in range(i):
    bit[j] -= (b-2**i)//(2**(j+1))*(2**j)
    bit[j] -= max(0,(b-2**i)%(2**(j+1))-2**j+1)

ans = 0
for i in range(42):
    if bit[i] %2 == 1:
        ans += 2**i
print(ans)

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

Solution (Python):
A, B = map(int, input().split())
def calc(a):
    cnt = (a + 1) // 2
    ans = cnt % 2
    if a % 2 == 0:
        ans ^= a
    return ans
print(calc(A-1) ^ calc(B))







1

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

def eo_of_ones(a):
  if (a+1)%4==1 or (a+1)%4==0:
    l='0'
  else:
    l='1'
  for i in range(1,50):
    l=str((max(0,((a+1)%(2**(i+1)))-(2**i)))%2)+l
  return list(l)

def solve():
  ans=0
  if A==B:
    ans=B
  elif A==0:
    l_b=eo_of_ones(B)
    for i in range(50):
      ans+=int(l_b.pop())*(2**i)
  else:
    l_a=eo_of_ones(A-1)
    l_b=eo_of_ones(B)
    for i in range(50):
      ans+=((int(l_b.pop())+int(l_a.pop()))%2)*(2**i)
      
  print(ans)

solve()

Solution (Python):


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

def F(a, b):
    return F_0n(a - 1) ^ F_0n(b)

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

print(F(A, B))

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

Solution (Python):
import numpy as np
A,B = map(int,input().split())
"""
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
"""
def funcXOR(S):
  if S % 2 == 0:
    s = S // 2
    if s % 2 == 0:
      return 0^S
    else:
      return 1^S
  else:
    s = (S+1) // 2
    if s % 2 == 0:
      return 0
    else:
      return 1
print(funcXOR(A-1)^funcXOR(B))

Solution (Python):
def get_input_row():
  return [int(i) for i in input().split(" ")]

def calc(n):
  a = n % 4
  if a == 0:
    return n
  elif a == 1:
    return 1
  elif a == 2:
    return n + 1
  elif a == 3:
    return 0
  
A, B = get_input_row()
ans = calc(B)^calc(A-1)
print(ans)

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

Solution (Python):
def to_bin(number):

    return bin(number)[2:].zfill(45)


def xor(num1, num2):

    num1_str = to_bin(num1)
    num2_str = to_bin(num2)

    result_list = [0] * 45

    for digit in range(0, 45):
        result_list[digit] += int(num1_str[digit])
        result_list[digit] += int(num2_str[digit])

    result_str = ''

    for digit in result_list:

        if digit % 2 == 0:
            result_str += '0'
        else:
            result_str += '1'
    return int(result_str, 2)


def f(a, b):
    if a > 0:
        a -= 1

    return xor(g(a), g(b))


def g(num):

    others = 0

    if num % 2 == 0:
        if (num // 2) % 2 != 0:
            others = 1

        return xor(num, others)
    else:
        if ((num - 1) // 2) % 2 != 0:
            others = 1

        return xor(xor(num, others), num - 1)


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

result = f(A, B)

print(result)

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

print(
    [0,   A  -1,  1, (  A  -1)^1][  A  %4]
    ^
    [0, (B+1)-1,  1, ((B+1)-1)^1][(B+1)%4]
)

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

def gf(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    return n ^ 1

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

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

a2 = True
b2 = False
if a % 2 != 0:
    a0 = a
    a += 1
    a2 = False
if b % 2 == 0:
    b0 = b
    b -= 1
    b2 = True

c = b-(a-1)
if c % 2 == 0:
    if (c // 2) % 2 == 0:
        ans = 0
    else:
        ans = 1 
elif ((c-1) // 2) % 2 == 0:
    ans = 0 ^ b
else:
    ans = 1 ^ b
    
if a2 == False:
    ans = ans ^ a0
if b2 == True:
    ans = ans ^ b0

print(ans)

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

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

print([0, A-1, 1, (A-1)^1][A%4]^[0, (B+1)-1, 1, ((B+1)-1)^1][(B+1)%4])

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

print([0, A-1, 1, (A-1)^1][A%4]^[0, B, 1, B^1][(B+1)%4])

Solution (Python):
def calc(a):
    val = int((a+1) / 2)
    ans = (val % 2) ^ a if a % 2 == 0 else val % 2
    return ans
A,B = map(int, input().split())

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

Solution (Python):
def d_xor_world(A, B):
    
    def f(n):
        if n % 2 == 0:
            
            
            return int((n // 2) % 2 == 1) ^ n
        else:
            
            return int(((n + 1) // 2) % 2 == 1)
    return f(A - 1) ^ f(B)

A, B = [int(i) for i in input().split()]
print(d_xor_world(A, B))

Solution (Python):
A, B = map(int, input().split())
digits = len(format(B, 'b'))
def func(x):
    low = x // 4 * 4
    from functools import reduce
    ret = reduce(lambda x, y: x ^ y, range(low, x + 1))
    return ret

ans = func(B) ^ func(A - 1)

print(ans)

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

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

if a > 0:
    ans = func(a-1) ^ func(b)
else:
    ans = func(b)

print(ans)

Solution (Python):
def calcF(n):
    if n%2 == 0:
        if n%4 == 0:
            return n
        else:
            return n^1
    else:
        if (n+1)%4 == 0:
            return 0
        else:
            return 1
A,B = map(int,input().split())
ans_A = calcF(A-1)

ans_B = calcF(B)

ans = ans_A^ans_B
print(ans)

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

ans = 0
length = b-a+1
if a%2 != 0:
    ans = ans^a
if b%2 == 0:
    length -= 1
    ans = ans^b
pair_count= length//2
ans = ans^(pair_count%2)
print(ans)

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

if A % 2 != 0:
    tmp1 = (A-1)^(0 if ((A-2+1) // 2) % 2 == 0 else 1)
else:
    tmp1 = 0 if ((A-1+1) // 2) % 2 == 0 else 1

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

print(tmp1^tmp2)

Solution (Python):
a,b=map(int,input().split())
a+=1
b+=1
s=0
for i in range(1,42):
    k=b-(b//(2**i))*(2**i)
    if k>=2**(i-1):
        x=(b//(2**i))*(2**(i-1))+(k%(2**(i-1)))
    else:
        x=(b//(2**i))*(2**(i-1))
    j=(a-1)-((a-1)//(2**i))*(2**i)
    if j>=2**(i-1):
        y=((a-1)//(2**i))*(2**(i-1))+(j%(2**(i-1)))
    else:
        y=((a-1)//(2**i))*(2**(i-1))
    if x!=0 and (x-y)%2!=0:
        s+=2**(i-1)
print(s)

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

Solution (Python):
a,b=[int(x)for x in input().split()]
if a>b :
  a,b=b,a
l=a%4
m=b%4
tmp=0
for p in range(a,a+4-l):
  tmp^=p
for p in range(b-m,b+1):
  tmp^=p
print(tmp)

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

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


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

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

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

if a == b:
  print(a)
  exit()
elif b - a == 1:
  print(a ^ b)
  exit()

first_even = a if a % 2 == 0 else a + 1
last_odd = b if b % 2 == 1 else b - 1

num_pairs = (last_odd - first_even + 1) // 2
ones = num_pairs % 2
res = (a if a % 2 else 0) ^ ones ^ (b if b % 2 == 0 else 0)
print(res)

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

Solution (Python):
def count(k, cycle):
    k += 1
    tans = (k // cycle) * (cycle // 2)
    res = k % cycle
    if res >= cycle // 2:
        tans += res % (cycle // 2)
    return tans

def solve(A, B):
    cycle = 2
    ans = ""
    for _ in range(40):
        acount = count(A - 1, cycle)
        bcount = count(B, cycle)
        ans = str((bcount - acount) % 2) + ans
        cycle *= 2
    return int(ans, base=2)

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

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

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

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

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

def xor(x,y):
	c = 0
	k = 0
	while 2**k < max(x,y)+1:
		c += (2**k) * ( (((x//(2**k))%2) + ((y//(2**k))%2)) %2 )
		k += 1
	return c

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

Solution (Python):
def g(x):
    if x % 4 == 0 or x % 4 == 3:
        l = [0]
    else:
        l = [1]
    r = x % 2
    x //= 2
    while x > 0:
        if x % 2 == 0:
            l.append(0)
        else:
            l.append(1 - r)
        x //= 2
    return l + [0] * (40 - len(l))

def f(x, y):
    ans = 0
    a = g(x - 1)
    b = g(y)
    for i in range(40):
        ans *= 2
        ans += a[-1 - i] ^ b[-1 - i]
    return ans

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

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

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

def f(n):
    if n < 0:
        return 0
    if n % 2:
        return 1 if ((n + 1) // 2) % 2 else 0
    else:
        return n ^ (1 if (n // 2) % 2 else 0)

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

Solution (Python):
def xor(_x) :
    if _x % 4 == 0:
        return _x
    elif _x % 4 == 1:
        return 1
    elif _x % 4 == 2:
        return 1 ^ _x
    else:
        return 0


A, B = map(long, raw_input().split())
print(xor(A - 1) ^ xor(B))

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

def xor(n):
    m = n+1
    return m//2%2 + n*(m%2)

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

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

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

Solution (Python):
a, b = map(int, input().split())
if a&1:
	if (b-a) % 4 <= 1:
		ans = 1
	else:
		ans = 0
else:
	if 1 <= (b-a) % 4 <= 2:
		ans = 1
	else:
		ans = 0
for i in range(1, 40):
	cnt = 0
	if (a>>i) & 1 and (a % (1<<i)) & 1:
			cnt += 1
	if ((b+1)>>i) & 1 and ((b+1) % (1<<i)) & 1:
			cnt += 1
	if cnt & 1:
		ans += (1<<i)
print(ans)

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

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

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



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

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

Solution (Python):




def souwa(s):
    return [s, 1, s + 1, 0] [s % 4] 

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

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

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)


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

    r = 0
    if (a ^ b) & 1:
        r = (b-a+1) // 2 % 2
    else:
        r = (a+b) // 2 & 1

    for ii in range(1,44):
        i = 2 ** ii
        if a < i and b < i:
            break

        t = a + i - a % i
        if t > b:
            if a & i and (b-a) % 2 == 0:
                r += i
            continue
        k = t - a

        j = b % i + 1
        u = b - j

        s = 0
        if a & i:
            s += k
        if b & i:
            s += j

        if s & 1:
            r += i

    return r


print(main())

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

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

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

print(ans)

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 ^ (n-1) ^ (n-2)
    elif n % 4 == 3:
        return 0
print(f(A-1) ^ f(B))

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

Solution (Python):

import sys


def solve(A: int, B: int):
    
    def sub(X): 
        if X%2 == 0:
            if (X/2)%2 == 0:
                return 0^X
            else:
                return 1^X
        else:
            if ((X+1)/2)%2 == 0:
                return 0
            else:
                return 1

    print(sub(A-1)^sub(B))
    return


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

if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
b=(n==m)
ans=0
if n&1:
  ans=n
  n+=1
s=(m-n+1)%4
if b:
  ans=m
elif s==1:
  ans^=m
elif s==2:
  ans^=1
elif s==3:
  ans^=1^m
print(ans)

Solution (Python):
n,m=map(int,input().split())
b=(n==m)
ans=0
if n&1:
  ans=n
  n+=1
s=(m-n+1)%4
if b:
  ans=m
elif s==1:
  ans^=m
elif s==2:
  ans^=1
elif s==3:
  ans^=1^m
print(ans)

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

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

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

print(ans)

Solution (Python):


def count(k, cycle):
    k += 1
    tans = (k // cycle) * (cycle // 2)
    res = k % cycle
    if res >= cycle // 2:
        tans += res % (cycle // 2)
    return tans

def solve(A, B):
    if A == B:
        return A
    Abin = "{:040b}".format(A)
    cycle = 2
    ans = ""
    for i, b in enumerate(Abin[::-1]):
        acount = count(A - 1, cycle)
        bcount = count(B, cycle)
        ans = str((bcount - acount) % 2) + ans
        cycle *= 2

    return int(ans, base=2)


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

Solution (Python):


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


def xor_sum(n):
    if n == 0: return 0
    if n % 2 != 0:
        return int((n + 1) % 4 != 0)
    return xor_sum(n-1) ^ n

def main():
    A, B = MI()
    if A == 0:
        return xor_sum(B)
    return xor_sum(A-1) ^ xor_sum(B)

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

Solution (Python):
A, B = map(int, input().split())
ret, b = "", 1
for i in range(45):
    f = lambda b, x: b*((x+1)//(b*2)) + max((x+1) % (b*2) - b, 0)
    ret = str((f(b, B) - f(b, A-1)) % 2) + ret
    b *= 2
ans, b = 0, 1
for i in range(45):
    ans += b * int(ret[44 - i])
    b *= 2
print(ans)

Solution (Python):
def f0(x):
    ones = (x + 1) // 2
    if x % 2 == 1:
        x = ones % 2
    else:
        x = x ^ (ones % 2)

    return x


def f(A, B):
    s = f0(A - 1)
    t = f0(B)
    return s ^ t


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

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
a,b = map(int,input().split())
def func(x):
    if x%2 == 1:
        ans = ((x//2) + 1)%2
        return ans
    else:
        tmp = (x//2)%2
        ans = tmp^x
        return ans

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

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

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


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

def count_1(bi, idx):
    bi = bi[::-1]
    cnt = 0
    if idx > 0:
        for i in range(0, idx):
            cnt += int(bi[idx]) * int(bi[i]) * int(2**i)
    if idx < (len(bi) - 1):
        for i in range(idx + 1, len(bi)):
            cnt += int(bi[i]) * int(2**i) / 2
    cnt += int(bi[idx])        
    return(int(cnt))

a = str(bin(max(A-1, 0)))[2:]
b = str(bin(B))[2:]
a = (len(b) - len(a)) * "0" + a 

def count_1s(bi):
    return([count_1(bi, i) for i in range(len(bi))[::-1]])

a_cnt = count_1s(a)
b_cnt = count_1s(b)


print(int("".join([str((i - j) % 2) for i, j in zip(b_cnt, a_cnt)]), 2))

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







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




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

Solution (Python):
"""
D - XOR World

解説を参考に作成.
いろいろ試している最中に法則に気付けるチャンスはあった...無念
"""

import math


def solve():
    A, B = map(int, input().split())
    print(all_xor(A - 1) ^ all_xor(B))


def all_xor(num):
    """
    0 ~ numまでのすべての数値の排他的論理和を求める.

    :param num:
    :return:
    """
    if num % 2 == 0:
        if (num - 2) % 4 == 0:
            return num
        else:
            return 1 ^ num
    else:
        if (num - 1) % 4 == 0:
            return 0
        else:
            return 1


if __name__ == '__main__':
    solve()

Solution (Python):

"""
Created on Sat Mar  9 23:07:39 2019

@author: Yamazaki Kenichi
"""

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

def a(A):
    if A % 4 == 0:
        return A
    elif A % 4 == 2:
        return A ^ 1
    elif A % 4 == 1:
        return 1
    elif A % 4 == 3:
        return 0

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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return



A, B = 0, 0


def set_inputs():
    global A, B
    A, B = get_list_of_int()
    return


def f(n):
    mod = n % 4
    ret = n
    for i in range(mod):
        ret ^= (n-1-i)
    return ret


def main():
    setrecursionlimit(100000)
    set_inputs()
    print(f(A-1) ^ f(B))
    return


if __name__ == '__main__':
    main()

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

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

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return



A, B = 0, 0


def set_inputs():
    global A, B
    A, B = get_list_of_int()
    return


def f(n):
    if n == 0:
        return 0
    div, mod = divmod(n, 4)
    if mod == 0:
        div -= 1
        mod = 4
    ret = n
    for i in range(mod):
        ret ^= (n-1-i)
    return ret


def main():
    setrecursionlimit(100000)
    set_inputs()
    print(f(A-1) ^ f(B))
    return


if __name__ == '__main__':
    main()

Solution (Python):

"""
Created on Sat Mar  9 23:07:39 2019

@author: Yamazaki Kenichi
"""

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

def a(A):
    if A % 2 == 0:
        return A ^ (A%4//2)
    else:
        return ((A+1)%4//2)

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

Solution (Python):
def calc_num_one(num, b):
  res = (num + 1) / 2 ** (b + 1) * 2 ** b
  if (num + 1) >= 2 ** b and ((num + 1) / 2 ** b) % 2 != 0:
    res += (num + 1) % 2 ** b
  return res
A, B = map(int, raw_input().split())
res = 0
for b in range(40):
  num_one_A = calc_num_one(A, b)
  num_one_B = calc_num_one(B, b)
  if A / (2 ** b) % 2 == 0:
    rest = 0
  else:
    rest = 1
  
  num_one_A_B = num_one_B - num_one_A + rest
  if num_one_A_B % 2 == 0:
    continue
  res += 2 ** b
print res

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

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

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

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

def f(x):
    ans = [x,1,x+1,0]
    return ans[x%4]
print(f(a-1)^f(b))

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


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

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

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


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

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

Solution (Python):
def xor(n):
  if n % 2:
    t = (n+1) // 2
    if t % 2:
      return 1
    else:
      return 0
  else:
    t = n // 2
    if t % 2:
      return n+1
    else:
      return n
a,b = map(int, input().split())
c = xor(a-1)
d = xor(b)
print(c^d)

Solution (Python):
import numpy as np

def f(x):
    fm = x - (x % 4) - 1 
    ans = 0
    while fm < x:
        fm += 1
        ans ^= fm
    return ans

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