use proconio::input;

trait Automaton { 
  type Alphabet;
  type State;
  fn init(&self) -> Self::State;
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State;
  fn accept(&self, state: Self::State) -> bool;
}
struct IntersectionAutomaton<X,Y>(X,Y) where X: Automaton, Y: Automaton;
impl<X,Y,A> Automaton for IntersectionAutomaton<X,Y> 
where X: Automaton<Alphabet=A>, 
      Y: Automaton<Alphabet=A>, 
      A: Copy {
  type Alphabet = A;
  type State = (X::State, Y::State);
  fn init(&self) -> Self::State {
    (self.0.init(), self.1.init())
  }
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State {
    (self.0.next(state.0, a), self.1.next(state.1, a))
  }
  fn accept(&self, state: Self::State) -> bool {
    self.0.accept(state.0) & self.1.accept(state.1)
  }
}
struct NegateAutomaton<X>(X) where X: Automaton;
impl<X: Automaton> Automaton for NegateAutomaton<X> {
  type Alphabet = X::Alphabet;
  type State = X::State;
  fn init(&self) -> Self::State {
    self.0.init()
  }
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State {
    self.0.next(state, a)
  }
  fn accept(&self, state: Self::State) -> bool {
    !self.0.accept(state) 
  }
}
struct ProductAutomaton<X,Y>(X,Y) where X: Automaton, Y: Automaton;
impl<X: Automaton,Y: Automaton> Automaton for ProductAutomaton<X,Y> {
  type Alphabet = (X::Alphabet, Y::Alphabet);
  type State = (X::State, Y::State);
  fn init(&self) -> Self::State {
    (self.0.init(), self.1.init())
  }
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State {
    (self.0.next(state.0, a.0), self.1.next(state.1, a.1))
  }
  fn accept(&self, state: Self::State) -> bool {
    self.0.accept(state.0) & self.1.accept(state.1)
  }
}

use std::hash::Hash;
fn count<X: Automaton>(dfa: &X, n: usize, alphabet: &[X::Alphabet]) -> usize 
where X::State: Copy + Eq + Hash, X::Alphabet: Copy {
  let init = dfa.init();
  let mut curr = std::collections::HashMap::new();
  curr.insert(init, 1);
  for _ in 0..n {
    let mut next = std::collections::HashMap::new();
    for (&state, value) in &curr {
      for &a in alphabet {
        *next.entry(dfa.next(state, a)).or_insert(0) += value;
        *next.entry(dfa.next(state, a)).or_insert(0) %= 1_000_000_007;
      }
    }
    curr = next;
  }
  let mut total = 0;
  for (&state, value) in &curr {
    if dfa.accept(state) {
      total += value;
      total %= 1_000_000_007;
    }
  }
  total
}

struct LessThanEqualAutomaton(Vec<char>);
impl Automaton for LessThanEqualAutomaton {
  type State = Result<(usize, bool),()>;
  type Alphabet = char;
  fn init(&self) -> Self::State { 
    Ok((0, true))
  }
  fn next(&self, s: Self::State, a: Self::Alphabet) -> Self::State {
    if let Ok((i, tight)) = s {
      if i >= self.0.len() { return Err(()); }
      if tight {
        if a  > self.0[i] { return Err(()); }
        if a == self.0[i] { return Ok((i+1, true)); }
      }
      return Ok((i+1, false));
    } else { Err(()) }
  }
  fn accept(&self, s: Self::State) -> bool {
    return s.is_ok();
  }
}

struct SameMSB;
impl Automaton for SameMSB {
  type Alphabet = (char, char);
  type State = usize;
  fn init(&self) -> Self::State { 0 } // 0: not started; 1: same msb, 2: not same msb
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State {
    match (state, a) {
      (0, ('0', '0')) => 0,
      (0, ('1', '1')) => 1,
      (0, _) => 2,
      (s, _) => s,
    }
  }
  fn accept(&self, state: Self::State) -> bool {
    state <= 1
  }
}
struct Between;
impl Automaton for Between {
  type Alphabet = (char, char);
  type State = bool;
  fn init(&self) -> Self::State { true }
  fn next(&self, state: Self::State, a: Self::Alphabet) -> Self::State {
    state & (a.0 <= a.1)
  }
  fn accept(&self, state: Self::State) -> bool {
    state
  }
}

fn main() {
  input!{
    l: usize,
    r: usize,
  }
  let r = format!("{:b}", r);
  let l = format!("{:0width$b}", l-1, width = r.len());

  let at_least_l = {
    let num: Vec<char> = l.chars().collect();
    NegateAutomaton(LessThanEqualAutomaton(num))
  };
  let at_most_r = {
    let num: Vec<char> = r.chars().collect();
    LessThanEqualAutomaton(num)
  };
  let dfa = IntersectionAutomaton(ProductAutomaton(at_least_l, at_most_r), 
                                  IntersectionAutomaton(SameMSB, Between));

  let alphabet = vec![('0','0'), ('0','1'), ('1','0'), ('1','1')];
  println!("{}", count(&dfa, r.len(), &alphabet));
}


Measured memory_bytes: 2212