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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

type Mint = kyopro_lib::modint::Mint1_000_000_007;

fn main() {
    input! {
        l: u64, r: u64,
    }

    let mut dp = [[[[Mint::new(0); 2]; 2]; 2]; 60 + 1];
    dp[60][0][0][0] = Mint::new(1);
    for i in (0..60).rev() {
        let lb = (l >> i) & 1;
        let rb = (r >> i) & 1;
        for (j, k, s) in (0..2)
            .flat_map(|j| (0..2).map(move |k| (j, k)))
            .flat_map(|(j, k)| (0..2).map(move |s| (j, k, s)))
        {
            let pre = dp[i + 1][j][k][s];
            for (x, y) in (0..2).flat_map(|x| (0..2).map(move |y| (x, y))) {
                if y == 0 && x != 0 {
                    continue;
                }
                let mut nj = j;
                let mut nk = k;
                let mut ns = s;
                if s == 0 && x != y {
                    continue;
                }
                if x == 1 && y == 1 {
                    ns = 1;
                }
                if j == 0 && x == 0 && lb == 1 {
                    continue;
                }
                if x == 1 && lb == 0 {
                    nj = 1;
                }
                if k == 0 && y == 1 && rb == 0 {
                    continue;
                }
                if y == 0 && rb == 1 {
                    nk = 1;
                }

                dp[i][nj][nk][ns] += pre;
            }
        }
    }

    let mut res = Mint::new(0);
    for (j, k, s) in (0..2)
        .flat_map(|j| (0..2).map(move |k| (j, k)))
        .flat_map(|(j, k)| (0..2).map(move |s| (j, k, s)))
    {
        res += dp[0][j][k][s];
    }
    println!("{}", res.val());
}
*/

fn main() {
    let exe = "/tmp/binFCFC6959";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";