#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;
//thr[i]:3^(i-1)
//calc_x（k）：xがx以上になるようなk桁の整数。yはFREE
//calc＿xy（k）：xがx以上、yがy以下になるようなk桁の整数。
void calc_x(ll k)
{
    ll nowx = (1ll << k);
    ll res = 1;
    repr(i,k-1,-1){
        if ((x>>i)&1){
            nowx += (1ll << i);
        }
        else{
            ans = (ans + thr[i] * res % mod) % mod;
            res = (res * 2) % mod;
        }
    }
    ans = (ans + res) % mod;
}
void calc_y(ll k)
{
    ll nowy = (1ll << k);
    ll res = 1;
    repr(i,k-1,-1){
        if ((y>>i)&1){
            ans = (ans + thr[i] * res % mod) % mod;
            nowy += (1ll << i);
            res = (res * 2) % mod;
        }
        else{
            continue;
        }
    }
    ans = (ans + res) % mod;
}
void calc_xy(ll k)
{
    ll nowx, nowy;
    nowx = nowy = (1ll << k);
    repr(i,k-1,-1){
        bool bx = ((x >> i) & 1), by = ((y >> i) & 1);
        if (bx&&by){
            //x1y1
            nowx += (1ll << i);
            nowy += (1ll << i);
        }
        else if (bx){
            //x1y0
            return;
        }
        else if (by){
            //x0y1
            //x1y0できない
            //x0y0：yのみFREE
            x -= nowx;
            x += (1ll << i);
            calc_x(i);
            x -= (1ll << i);
            x += nowx;
            //x1y1：xのみFREE
            y -= nowy;
            calc_y(i);
            y += nowy;
            //x0y1：次
            nowy += (1ll << i);
        }
        else{
            //x0y0
            //y0固定なのでx0y0のみ。特に何もできない。
            continue;
        }
    }
    ans = (ans + 1) % 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, 62)
    {
        ll mn = (1ll << k);
        ll mx = (1ll << (k + 1)) - 1;
        if (y < mn)
            break;
        if (mx < x)
            continue;
        if (mn <= x && y <= mx)
        {
            if (mn == x && y == mx)
            {
                ans = (ans + thr[k]) % mod;
            }
            else
                calc_xy(k);
        }
        else if (mn < x)
        {
            calc_x(k);
        }
        else if (y < mx)
        {
            calc_y(k);
        }
        else
        {
            ans = (ans + thr[k]) % mod;
        }
    }
    cout << ans << ENDL;
}


Measured memory_bytes: 256