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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int MOD  = int(1e9)+7;


struct mint {
  ll x;
  mint(ll x=0) : x((x%MOD+MOD)%MOD) {}
  mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
};
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


const int M = 60;
mint dp[M+1][2][2][2];


int main() {
  ll L, R; cin >> L >> R;
  dp[0][0][0][0] = 1;

  rep(i, M) {
    int Li = L>>(M-1-i)&1; // L の上から i 桁目
    int Ri = R>>(M-1-i)&1; // R の上から i 桁目
    rep(j, 2) rep(l, 2) rep(r, 2) rep(xi, 2) rep(yi, 2) {
      int j2 = j, l2 = l, r2 = r; // 遷移前の状態で初期化

      if (xi > yi) continue; // (xi, yi) = (1, 0) なら無視

      if (!j && (xi < yi)) continue; // (1, 1) が現れる前に (0, 1) が現れたら無視
      if (xi&yi) j2 = 1;             // (1, 1) が現れたら j2 を更新

      // 条件 x ≧ L の処理
      if (!l && (xi < Li)) continue;
      if (xi > Li) l2 = 1;

      // 条件 y ≦ R の処理
      if (!r && (yi > Ri)) continue;
      if (yi < Ri) r2 = 1;

      dp[i+1][j2][l2][r2] += dp[i][j][l][r]; // 遷移式
    }
  }

  mint ans = 0;
  rep(l, 2) rep(r, 2) ans += dp[M][1][l][r];
  cout << ans << '\n';
}