Problem:
Score : 600 points

Problem Statement

Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x.

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

1 \leq L \leq R \leq 10^{18}

Input

Input is given from Standard Input in the following format:

L R

Output

Print the number of pairs of integers (x, y) (L \leq x \leq y \leq R) satisfying the condition, modulo 10^9 + 7.

Sample Input 1

2 3

Sample Output 1

3

Three pairs satisfy the condition: (2, 2), (2, 3), and (3, 3).

Sample Input 2

10 100

Sample Output 2

604

Sample Input 3

1 1000000000000000000

Sample Output 3

68038601

Be sure to compute the number modulo 10^9 + 7.

Solution in Python (3.4.3) (judge verdict: Wrong Answer)

import numpy as np
LARGE = 10 ** 9 + 7


def get_l(vl, le_r):
    # vl <= L <= R <= 2 ** le_r - 1
    res_ = 0

    if vl == 0:
        res_ += pow(2, le_r, LARGE)
        vl = 1
    for l_ in range(le_r):
        if vl % (2 ** (l_ + 1)) != 0:
            le_total = le_r - bin(vl).count("1")
            res_ += pow(3, l_, LARGE) * pow(2, le_total - l_, LARGE)
            res_ %= LARGE
            vl += 2 ** l_
    return res_


def get_r(vr):
    # 0 <= L <= R <= vr
    if vr == 0:
        return 1
    elif vr == 1:
        return 2
    l_ = 0
    while True:
        if 2 ** (l_ + 1) - 1 > vr:
            break
        l_ += 1
    if 2 ** l_ - 1 == vr:
        return pow(3, l_, LARGE)
    else:
        return (pow(3, l_, LARGE) + 2 * get_r(vr - 2 ** l_)) % LARGE


def solve_F(L, R):
    res = 0
    le = 0
    left = 2 ** le
    right = 2 ** (le + 1) - 1

    while True:
        if right < L:
            pass
        elif L <= left <= right <= R:
            res += pow(3, le, LARGE)
        elif R < left:
            break
        elif left <= L <= right < R:
            res += get_l(L, le + 1)
        elif L < left <= R <= right:
            res += get_r(R - left)
        elif L < R:
            # left <= L <= R <= right:
            # find mid
            mid = left
            for le2 in range(le - 1, -1, -1):
                if L < mid + 2 ** le2 <= R:
                    res += get_l(L - mid, le2)
                    res += get_r(R - mid)
                elif mid + 2 ** le2 <= L:
                    mid += 2 ** le2
                else:
                    pass
        else:
            res = 1

        res %= LARGE
        le += 1
        left *= 2
        right *= 2
        right += 1
    return res


test = False
if __name__ == "__main__":
    if test:
        for _ in range(100000):
            L, R = np.random.choice(10**10, 2)
            L, R = min(L, R) + 1, max(L, R) + 1
            print(L, R)
            res = solve_F(L, R)
    else:
        L, R = map(int, input().split())
        print(solve_F(L, R))