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

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

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

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

Solution (Python):


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

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

Solution (Python):
a, b = list(map(int, input().split()))
def division2(n):
    if(n % 2 == 0):
        return True
    else:
        return False
k = b - a + 1
if division2(k):
    if division2(a):
        if division2(k / 2):
            print(0)
        else:
            print(1)
    else:
        if division2((k - 2)/2):
            print(a ^ b)
        else:
            print(1 ^ a ^ b)
else:
    if division2(a):
        if division2((k - 1) / 2):
            print(b)
        else:
            print(b ^ 1)
    else:
        if division2((k - 1) / 2):
            print(a)
        else:
            print(a ^ 1)

Solution (Python):



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

    if a % 2 == 0:
        if b - (a - 1) >= 4:
            start = b - ((b - (a - 1)) % 4)
            ans = 0
    else:
        if b - a >= 4:
            start = b - ((b - a) % 4)
            ans = a

    for i in range(start + 1, b + 1):
        ans ^= i

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

import math

if a % 2 == 1:
  ax = a
  an = a+1
else:
  ax = 0
  an = a

if b % 2 == 1:
  bx = 0
  bn = b
else:
  bx = b
  bn = b-1

tmp = ax ^ bx
if ((bn - an + 1) // 2) % 2 == 1:
  ans = tmp ^ 1
else:
  ans = tmp
  
print(ans)

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

import math

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

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

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




def cumlative_xor(a):
	ans = 0
	if a % 4 == 1 or a % 4 == 2 :
		ans = 1

	for i in range(1, 41):
		temp = 2 ** i
		if a & 1 == 0 and a & temp > 0:
			ans = ans | temp

	return ans

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

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

Solution (Python):
def f2(k):
    r = k % 4
    if r == 0:
        return k
    elif r == 1:
        return 1
    elif r == 2:
        return k ^ 1
    else:
        
        return 0


def f(m, n):
    return f2(m - 1) ^ f2(n)


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

"""
f(a,b) = f(0,a-1) ^ f(0,b)
重なった範囲がキャンセルされるため
"""

Solution (Python):
def f(m, n):
    
    res = 0

    t = ((m + 3) // 4) * 4
    for i in range(m, t):
        res ^= i

    t = (n // 4) * 4
    for i in range(t, n + 1):
        res ^= i

    return res


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

Solution (Python):
def find(A):
    if A%2==1:
        num=(1+(A-1)//2)%2
        return num
    ans=A
    A-=1
    num=(1+(A-1)//2)%2
    num=ans^num
    
    return num
A,B=list(map(int,input().strip().split(' ')))
if A==0:
    print(find(B))
else:
    print(find(A-1)^find(B))

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

Solution (Python):
def main():

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    if __name__ != '__main__':
        
        sys.stdin = open('sample.txt')

    
    
    
    A, B = R()
    i, k, ans = 2, 2, 0
    bina = format(A, '50b')
    binb = format(B, '50b')
 
    if A % 2 == 0:
        if (B-A+3)%4 == 0 or (B-A+2)%4 == 0:
            ans += 1
    else:
        if (B-A)%4 == 0 or (B-A+3)%4 == 0:
            ans += 1
 
    while True:
        if bina[-i] == "0" or bina[-i] == " ":
            tmpa = 0
        else:
            tmpa = A % 2
        if binb[-i] == "0" or binb[-i] == " ":
            tmpb = 0
        else:
            tmpb = abs(B % 2-1)
        if (tmpa + tmpb) % 2 == 1:
            ans += k
        k *= 2
        i += 1
        if B < k:
            break
    
    print(ans)
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B = nl()

def xor(N):
    if N % 2 == 0:
        t = 0
        if (N // 2) % 2 > 0:
            t = 1
        return N ^ t
    return 1 - ((N // 2) % 2)

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

Solution (Python):
def main():
    a, b = map(int, input().split())
    print(calc(a - 1) ^ calc(b))


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


main()

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

def f(n):
    
    if (n+1)%2 == 0: 
        if ((n+1)//2)%2 == 0: 
            return 0
        else: 
            return 1
    else: 
        if ((n+1)//2)%2 == 0: 
            return n
        else: 
            return n+1
        
        
result = f(a-1) ^ f(b)
    
print(result)

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

def xor_sum(x):
    ans = 0 
    if x % 2 == 1:
        if ((x + 1) // 2 )%2 ==0:
            ans = 0
        else:
            ans = 1
    else:
        if x%4 == 0:
            ans = x
        else:
            ans = 1^x
    return ans

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

Solution (Python):

def xor_sum(x):
    """
    Return 0 ^ 1 ^ ... ^ x - 1 ^ 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 = list(map(int, input().rstrip().split()))
    print(xor_sum(a - 1) ^ xor_sum(b))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    a, b = list(map(int, input().rstrip().split()))
    c = a if a % 2 == 0 else a + 1
    n = b - c + 1
    pairs = n // 2
    if n % 2 == 0:
        ans = pairs % 2
        ans ^= 0 if c == a else a
        print(ans)
    else:
        ans = (pairs % 2) ^ b
        ans ^= 0 if c == a else a
        print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
from operator import xor

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

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

x = f(B)

if A == 0 :
    y = 0
else :
    y = f(A-1)

ans = xor(x,y)

print(ans)

Solution (Python):



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

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

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


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


a, b = MI()
print(f(a - 1) ^ f(b))

Solution (Python):
from sys import exit, stdin

A, B = [int(_) for _ in stdin.readline().rstrip().split()]

def oddsolve(x):
    return int((x+1)/2)%2

def solve(x):
    if x % 2 == 1:
        return oddsolve(x)
    else:
        return oddsolve(x+1) ^ (x+1)

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

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

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

a = ((A-1)+1)//2
b = (B+1)//2

a = a%2
b = b%2

if A%2 == 1:
    fa = (A-1)^a
else:
    fa = a
if B%2 == 0:
    fb = B^b
else:
    fb = b

print (fa^fb)

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

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

Solution (Python):
def f(n):
        nn = (n+1)//2
        if n%2==1:
                return nn%2
        else:
                return (nn%2)^n


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

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


def count(i):
    n = 1
    c = 0
    while n < i:
        c += 1
        n *=2
    return c

def check(i):
    lst = [0] * count(i)
    for j in range(len(lst)):
        if i%(2 ** (j+1)) == i%(2 ** j):
            tmp = (i//(2 ** (j+1)) * (2 ** j))
        else:
            tmp = (i//(2 ** (j+1)) * (2 ** j)) + i%(2 ** j)
        lst[j] = tmp
    return lst

lstA = check(A)
lstB = check(B+1)


for k in range(len(lstA)):
    lstB[k] -= lstA[k]


ans = 0
for l in range(len(lstB)):
    ans += (2 ** l) * (lstB[l]%2)

print (ans)

Solution (Python):
a,b = map(int,input().split())
def xor(x):
    return(x,1,x+1,0)[x%4]
print(xor(a-1)^xor(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+1
    else:
        return 0
        
aor = f(A-1)
bor = f(B)

print(aor^bor)

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


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


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

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

cnt = B-A+1

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

Solution (Python):
def f(X):
    x = (X + 1) // 2
    y = x % 2

    if X % 2 == 1:
        ans = 1 - y % 2
    else:
        ans = (1 - y % 2) ^ X
    return ans


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

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

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

Solution (Python):
from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
k = 1
bit_sum = []


def bit(x, n):
    return 2 ** (n - 1) * ((x + 1) // (2 ** n)) + max(0, (x + 1) % (2 ** n) - 2 ** (n - 1))


while 2 ** (k - 1) <= B:
    bit_sum.append(bit(B, k) - bit(A - 1, k))
    k += 1

ans = [(bit_sum[k] % 2) * 2 ** k for k in range(len(bit_sum))]
print(sum(ans))

Solution (Python):
def f(n):
    if n < 1:
        s = 0
    elif n == 1:
        s = 1
    else:
        s = ((n+1) // 2) % 2
        if n % 2 == 0:
            s ^= n
    return s

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

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

Solution (Python):
def func(li, a):
  i = 1
  while a//i > 0:
    if i == 1:
        li.append(1 - (a-1) // 2 % 2)
    elif ((a - i + 1) // i) % 2 == 0 and (a - i + 1) % 2 == 1:
      li.append(1)
    else:
      li.append(0)
    i *= 2

def bi_to_int(li):
    ans = 0
    i = 1
    for x in li:
        ans += x * i
        i *= 2
    
    return ans
    
a, b = map(int, input().split())

bit_a = []
bit_b = []

func(bit_a, a-1)
func(bit_b, b)

print(bi_to_int(bit_a) ^ bi_to_int(bit_b))

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

def func(n):
    ans=0
    if n>0:
        for i in range((n//4)*4,n+1):
            ans ^= i
        return ans
    else:return 0

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

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

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

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

Solution (Python):
n,m=map(int,input().split())
lm=[]
m1=m
if m!=0:
  while m1!=0:
    lm.append(m1%2)
    m1=m1//2
else:
  lm=[0]
ln=[]
n1=n-1
if n!=0:
  while n1!=0:
    ln.append(n1%2)
    n1=n1//2
while len(ln)!=len(lm):
  ln.append(0)
if n!=0:
  lm1=[0 for i in range(len(lm))]
  ln1=[0 for i in range(len(ln))]
  if lm[0]!=lm[1]:
    lm1[0]=1
  if ln[0]!=ln[1]:
    ln1[0]=1
  for i in range(1,len(lm)):
    if lm[i]==1 and lm[0]==0:
      lm1[i]=1
  for i in range(1,len(ln)):
    if ln[i]==1 and ln[0]==0:
      ln1[i]=1
  lmn=[0 for i in range(len(lm))]
  for i in range(len(lm)):
    if lm1[i]==ln1[i]:
      pass
    else:
      lmn[i]=1
  s=1
  ss=0
  for i in lmn:
    ss+=s*i
    s*=2
  print(ss)
else:
  print(m)

Solution (Python):

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

def getBin(b):
    return bin(b)[2:]
def xorTo(d):
    
    num=[[0,0] for _ in range(100)]
    d+=1
    for k in range(len(getBin(d))):
        period=2**(k+1)
        num[k][0]=(d/period)*(period/2)
        num[k][1]=(d/period)*(period/2)
        last=(d%period)
        if last < period/2:
            num[k][0]+=last
        else:
            num[k][0]+=period/2
            num[k][1]+=last-(period/2)
    ans=""
    for n0,n1 in num:
        if n1%2==0:ans+="0"
        else:ans+="1"
    ans=ans[::-1]
    ans=eval("0b"+ans)
    return ans    
print(xorTo(A-1) ^ xorTo(B))

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

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

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

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

if(A%2 == 0):
  min_even = A
  min_val = 0
else:
  min_even = A + 1
  min_val = A

if(B%2 == 0):
  max_odd = B - 1
  max_val = B
else:
  max_odd = B
  max_val = 0

tmp = (max_odd - min_even + 1)/2

if(tmp%2 == 1):
  print(min_val^1^max_val)
else:
  print(min_val^0^max_val)

Solution (Python):

def xors_0toN(N):
  if N <= 1:
    return N
  
  ans = 1*(N%4==1 or N%4==2)
  i = 2
  while (N >= i):    
    if N % (2*i) > i-1 and N % 2 == 0:
      ans += i
    i *= 2
  return ans


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

ans = xors_0toN(B) ^ xors_0toN(max(A-1,0))
print(ans)

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

def xor(n):
    check = n % 4
    if check == 0:
        return n
    if check == 1:
        return 1
    if check == 2:
        return n + 1
    if check == 3:
        return 0
      
print(xor(a-1)^ xor(b))

Solution (Python):
a,b=map(int,input().split())
l=(a+3)//4*4
r=b//4*4
x=[]
for i in range(a,l):x.append(i)
for i in range(r,b+1):x.append(i)
while len(x)>1:x.append(x.pop()^x.pop())
print(x[0])

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

exp_two = [2 ** i for i in range(1, 51)]


A += 1
B += 1

ans1 = 0
for i in range(50):
    
    num = ((A - 1) // exp_two[i]) * (exp_two[i] // 2)
    amari = max(0, ((A - 1) % exp_two[i]) - (exp_two[i] // 2))
    cnt = num + amari
    
    if cnt % 2:
        ans1 += 1 << i

ans2 = 0
for i in range(50):
    
    num = (B // exp_two[i]) * (exp_two[i] // 2)
    amari = max(0, (B % exp_two[i]) - (exp_two[i] // 2))
    cnt = num + amari
    if cnt % 2:
        ans2 += 1 << i

print(ans1 ^ ans2)

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

def XOR(x):
    if x%4==1 or x%4==2:
        l="0"
    else:
        l="1"
    i=2
    while x>=(2**(i-1)):
        k=x%(2**i)
        if k<=2**(i-1)-1:
            l+="0"
        else:
            if k%2==0:
                l+="1"
            else:
                l+="0"
        i+=1    
    l=l[::-1]
    return(int(l,2))

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

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

def XOR(x):
    if x%4==1 or x%4==2:
        l="0"
    else:
        l="1"
    i=2
    while x>=(2**(i-1)):
        k=x%(2**i)
        if k<=2**(i-1)-1:
            l+="0"
        else:
            if k%2==0:
                l+="1"
            else:
                l+="0"
        i+=1    
    l=l[::-1]
    return(l)

b=XOR(B)
a=XOR(A-1).zfill(len(b))
ans=""

for j in range(len(b)):
    if b[j]==a[j]:
        ans+="0"
    else:
        ans+="1"

print(int(ans,2))

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

print(ans)

Solution (Python):
def calc(i,x):
    if i ==0:
        return int((x % 4 == 1) or (x % 4 == 2))
    else:
        return int((x % (2**(i+1)) >= 2**i) and (x % 2 == 0))

def main():
    A,B = map(int, input().split())
    
    
    ans = 0
    for i in range(41):
        ans += 2**i*(calc(i,A-1)^calc(i,B))
    print(ans)
    
main()

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

def f(n):
    ans = ((n >> 1) ^ (n & 1)) & 1
    key = 2
    while key <= n:
        ans |= (key & n != 0) * (key ^ (key * (n & 1)))
        key <<= 1
    return ans
print(f(A-1)^f(B))

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

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,input().split())

def x(a,b):
    m = (b+1-a)//2
    if m%2==0:
        return 0
    else:
        return 1

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

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

ans=0

for i in range(4):
    if (A+i)%4==0:
        break
    ans=ans^(A+i)
for i in range(B-3,B+1):
    if i%4==3:
        end=i+1
        break

for i in range(end,B+1):
    ans=ans^i

print(ans)

Solution (Python):
a, b = map(int, input().split())
ans = b
done = 0
for i in range(a, b+1):
    if i % 4 != 0:
        ans ^= i
    else:
        done = i
        break

for i in range(b-1, a, -1):
    if i % 4 != 3 and i >= done:
        ans ^= i
    else:
        break

print(ans)

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

r = 0
def F(n):
	ec = (n + 1) // 2
	r = ec % 2
	if not n % 2:
		r ^= n
	return r
"""
def F2(n):
	r = 0
	for i in range(n + 1):
		r ^= i
	return r
"""

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

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

Solution (Python):
A,B=map(int,input().split())
def xor(N):
    if N%4 in [1,2]:
        xor_list=[1]
    else:
        xor_list=[0]
    i=1
    while(2**i<=N):
        if N%(2**(i+1))<2**(i):
            xor_list.append(0)
        else:
            xor_list.append((N+1)%2)
        i+=1
    return int("".join(list(reversed(list(map(str,xor_list))))),2)
print(xor(A-1)^xor(B))

Solution (Python):
import math

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

bA = bin(A)
bB = bin(B)


if (A - 1) % 2 == 0 :
    fA = A - 1
    fA += ((A - 1) / 2) % 2
else :
    fA = (A / 2) % 2

if B % 2 == 0 :
    fB = B
    fB += (B / 2) % 2
else :
    fB = ((B + 1) / 2) % 2

bfA = bin(int(fA))
bfB = bin(int(fB))

bAB = [0] * (max(len(bfA) , len(bfB)) - 2)
ans = 0

for i in range(1,len(bAB) + 1) :
    if i > len(bfA) - 2 :
        bAB[-i] = int(bfB[-i])
    elif i > len(bfB) - 2 :
        bAB[-i] = int(bfA[-i])
    else :
        bAB[-i] = 1 if (int(bfA[-i]) + int(bfB[-i])) % 2 == 1 else 0

for b in bAB : 
    ans = ans * 2 + b

print(ans)

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

Solution (Python):

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

Solution (Python):
a,b = map(lambda x:
          int(format(int(x),'b')),input().split())
a -= 1
A = str(a)
la = len(A)
ga = [0]*la
if a%4 == 1 or a%4 == 2:
  ga[-1] = 1
for ai in range(0,la-1):
  if A[ai] == '1' and A[-1] == '0':
    ga[ai] = 1
aa = 0
for ai in range(la):
  aa *= 2
  aa += ga[ai]
B = str(b)
lb = len(B)
gb = [0]*lb
if b%4 == 1 or b%4 == 2:
  gb[-1] = 1
for bi in range(0,lb-1):
  if B[bi] == '1' and B[-1] == '0':
    gb[bi] = 1
bb = 0
for bi in range(lb):
  bb *= 2
  bb += gb[bi]
if a < 0:
  print(bb)
else:
  print(aa^bb)

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


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


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

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


def calc(A, B):
    k = B - A + 1
    if k % 4 == 0:
        return 0
    elif k % 4 == 1:
        return B
    elif k % 4 == 2:
        return 1
    elif k % 4 == 3:
        return 1 ^ B


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

Solution (Python):


import math
a,b=map(int,input().split())
c=0
list=[]
d=0


number_of_1=0
sum_of_1=0
nose=0
tail=0

if a%2==0:
	number_of_1=(b+1-a)//2
else:
	number_of_1=(b-a)//2

sum_of_1=number_of_1 % 2

if a%2==0:
	nose=0
else:
	nose=a

if b%2==0:
	tail=b
else:
	tail=0

print(nose^tail^sum_of_1)

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

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

Solution (Python):
def func(n):
    if n % 2 == 1:
        a = n + 1
    else:
        a = n 
    if a % 4 == 0:
        between = 1
    else:
        between = 0
    if n % 2 == 0:
        ans = between ^ n
    else:
        ans = between
    return ans

n, m = map(int, input().split())
ans = func(n - 1) ^ func(m)
print(ans)

Solution (Python):
def func(x):
    k = (x + 1) // 2
    if x % 2:
        y = k % 2
    else:
        y = (k % 2) ^ x
    return y

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