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# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections;
using System.Linq;
using System.Numerics;

class F
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long L = a[0], R = a[1];

		BigInteger c = 0;
		var pow2 = new long[61];
		var pow3 = new BigInteger[61];
		pow2[0] = 1;
		pow3[0] = 1;
		for (var i = 1; i <= 60; pow2[i] = 2 * pow2[i - 1], pow3[i] = 3 * pow3[i - 1], i++) ;

		for (int i = 0; i < 60; i++)
		{
			var p2l = pow2[i];
			var p2r = pow2[i + 1] - 1;

			if (R < p2l) break;
			if (p2r < L) continue;
			if (L <= p2l && p2r <= R) { c += pow3[i]; continue; }

			if (p2r <= R)
			{
				for (var x = L; x <= p2r; c += pow2[CountBit(x, false, i - 1)], x++) ;
			}
			else if (L <= p2l)
			{
				for (var x = p2l; x <= R; c += pow2[CountBit(x, true, i - 1)], x++) ;
			}
			else
			{
				for (var x = L; x <= R; x++)
					for (var y = x; y <= R; y++)
						if (y - x == (y ^ x)) c++;
			}
		}
		Console.WriteLine(c % 1000000007);
	}

	static int CountBit(long v, bool flag, int maxBit)
	{
		var c = 0;
		var b = new BitArray(new[] { (int)v, (int)(v >> 32) });
		for (var i = 0; i <= maxBit; i++) if (b[i] == flag) c++;
		return c;
	}
}