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: Wrong Answer)

#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
ll ans;
ll x, y;
vll thr;
void calc_x(ll k){
    ll mn = (1ll << k);
    ll nowx = mn;
    ll res = 1;
    repr(i,k-1,-1){
        if ((1ll<<i)+nowx>=x){
            ans += (res * thr[i]) % mod;
            ans %= mod;
            res = (res * 2) % mod;
        }
        else {
            nowx += (1ll << i);
        }
    }
}
void calc_y(ll k){
    ll mn = (1ll << k);
    ll nowy = mn;
    ll res = 1;
    repr(i,k-1,-1){
        if ((1ll<<i)+nowy-1<=y){
            ans = ((ans + (res * thr[i]) % mod)) % mod;
            nowy += (1ll << i);
            res = (res * 2) % mod;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> x >> y;
    ans = 0;
    thr.eb(1);
    rep(i,65){
        thr.eb(thr[i] * 3 % mod);
    }
    rep(k,65){
        ll mn = (1ll << k);
        ll mx = (1ll << (k + 1)) - 1;
        if (y<mn)
            break;
        if (mx<x)
            continue;
        if (mn<x){
            calc_x(k);
        }
        else if (y<mx){
            calc_y(k);
        }
        else{
            ans = (ans + thr[k]) % mod;
        }
    }
    cout << ans << ENDL;
}