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

/*input
10 100
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=200005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll mod=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#include<iostream>
using namespace std;
ll dp[64][2][2];
ll L,R;
int main()
{
    cin>>L>>R;
    long ans=0;
    for(int k=1;k<=62;k++)
    {
        dp[62-k][L<=1L<<k-1][(1L<<k)-1<=R]=1L<<k>L&&R>=1L<<k-1;
    }
    for(int i=0;i<=60;i++)
    {
        int x=L>>60-i&1;
        int y=R>>60-i&1;
        for(int xl=0;xl<2;xl++)for(int yl=0;yl<2;yl++)
        {
            int limx=xl?0:x;
            int limy=yl?1:y;
            for(int yy=0;yy<=limy;yy++)for(int xx=limx;xx<=yy;xx++)
            {
                (dp[i+1][xl||xx>limx][yl||yy<limy]+=dp[i][xl][yl])%=mod;
            }
        }
    }
    for(int i=0;i<4;i++)(ans+=dp[61][i/2][i%2])%=mod;
    cout<<ans<<endl;
}