#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().ok().unwrap() }; } fn main() { setup! { mut input: SplitWhitespace }; let m: usize = parse_next!(input); let a: Vec = (0..m).map(|_| parse_next!(input)).collect(); use std::collections::{HashMap, VecDeque}; let mut queue = VecDeque::new(); let mut parent = HashMap::new(); { let root = 0; queue.push_back(root); } while !queue.is_empty() { let i = match queue.pop_front() { Some(value) => value, None => unreachable!(), }; if i == 4094 { break; } let children = vec![(i * 2) + 1, (i * 2) + 2]; for j in children.into_iter() { queue.push_back(j); parent.insert(j, i); } } for i in 0..m { let mut path = VecDeque::new(); let mut node = a[i]; while let Some(prev) = parent.get(&node) { path.push_front(node); node = *prev; } let ans = path .iter() .map(|&node| match node % 2 != 0 { true => 'L', false => 'R', }) .collect::(); println!("{}", ans); } }