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 Ruby (2.3.3) (judge verdict: Wrong Answer)

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def na4(n,m,l,j,d=0) Array.new(n){Array.new(m){Array.new(l){Array.new(j,d)}}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

l,r = inp
dp = na4(63,2,2,2)
dp[-1][0][0][0] = 1
(1..62).reverse_each do |i|
  (0..1).each do |j|
    (0..1).each do |k|
      (0..1).each do |s|
        t = [[0,0],[0,1],[1,1]]
        t.each do |nx,ny|
          nj,nk,ns = j,k,s
          next if(s == 0 and nx != ny)
          ns = 1 if(nx == 1)
          next if(r[i-1]< ny and k == 0)
          nk = 1 if(r[i-1]> ny)
          next if(nx<l[i-1] and s == 0)
          nj = 1 if(l[i-1]> nx)
          dp[i-1][nj][nk][ns] += dp[i][j][k][s]
        end
      end
    end
  end
end
p dp[0].flatten.inject(:+)%(10**9+7)