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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <memory.h>
#include <iostream>

#define ll long long
#define N 63
#define mod  1000000007

int dp[N][2][2][2];
ll L, R;
 
int add(int x, int y) {
	int ret = (x + y);
	if (ret >= mod) {
		ret -= mod;
	}
	return ret;
}
int solveDp(int ind, int msb, int xeq, int yeq) {
	if (ind < 0) {
		if (msb) {
			return 1;
		}
		return 0;
	}
	int &ret = dp[ind][msb][xeq][yeq];
	if (ret != -1) {
		return ret;
	}
	ret = 0;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			if (i > j) {
				continue;
			}
			if (xeq && i == 0 && L&(1LL << ind)) {
				continue;
			}
			if (yeq && j == 1 && (R&(1LL << ind)) == 0)
			{
				continue;
			}
			int nxeq, nyeq;
			nxeq = xeq;
			nyeq = yeq;
			if (xeq && i == 1 && (L&(1LL << ind)) ==0 ) {
				nxeq = 0;
			}
			if (yeq && j == 0 && (R&(1LL << ind))) {
				nyeq = 0;
			}
			if (msb == 0) {
				if (i != j) {
					continue;
				}
				if (i == 1) {
					ret = add(ret, solveDp(ind - 1, 1, nxeq, nyeq));
				}
				else {
					ret = add(ret, solveDp(ind - 1, 0, nxeq, nyeq));
				}
			}
			else {
				ret = add(ret, solveDp(ind - 1, 1, nxeq, nyeq));
			}
		}
	}
	return ret;
}
void solve() {
	scanf("%lld %lld", &L, &R);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", solveDp(N-1, 0, 1, 1));
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}