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: Accepted)

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 inp() a=gets.chomp.split(" ").map(&:to_i)end

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

l,r = inp
dp = Array.new(60){Array.new(2){Array.new(2){Array.new(2,0)}}}
ls = l.to_s(2)
rs = r.to_s(2)
ls = "0"*100 + ls
rs = "0"*100 + rs
ls.reverse!
rs.reverse!
dp[59][0][0][0] = 1
ans = na3(2,2,2,0)
(0..59).to_a.reverse.each do |keta|
  2.times do |i|
    2.times do |j|
      2.times do |k|
        now = dp[keta][i][j][k]
        next if(now == 0)
        2.times do |x|
          2.times do |y|
            next if(y<x)
            nx=i
            ny=j
            nb=k
            next if(k==0 and x!=y)
            next if(i==0 and x==0 and ls[keta].to_i == 1)
            next if(j==0 and y==1 and rs[keta].to_i == 0)
            nb = 1 if(x == y and x == 1)
            ny = 1 if(y < rs[keta].to_i)
            nx = 1 if(ls[keta].to_i < x)
            if(keta == 0)
              ans[nx][ny][nb] += now
            else
              dp[keta-1][nx][ny][nb] += now
              dp[keta-1][nx][ny][nb] %= (10**9+7)
            end
          end
        end
      end
    end
  end

end
p ans.flatten.inject{|m,u|(m+u)%(10**9+7)}