pub mod io { use std::io::{BufRead, ErrorKind}; pub fn scan(r: &mut R) -> Vec { let mut res = Vec::new(); loop { let buf = match r.fill_buf() { Ok(buf) => buf, Err(e) if e.kind() == ErrorKind::Interrupted => continue, Err(e) => panic!("{}", e), }; let (done, used, buf) = { match buf.iter().position(u8::is_ascii_whitespace) { Some(i) => (i > 0 || res.len() > 0, i + 1, &buf[..i]), None => (buf.is_empty(), buf.len(), buf), } }; res.extend_from_slice(buf); r.consume(used); if done { return res; } } } #[macro_export] macro_rules! scan { ($r:expr, [$t:tt; $n:expr]) => { (0..$n).map(|_| scan!($r, $t)).collect::>() }; ($r:expr, [$t:tt]) => { scan!($r, [$t; scan!($r, usize)]) }; ($r:expr, ($($t:tt),*)) => { ($(scan!($r, $t)),*) }; ($r:expr, Usize1) => { scan!($r, usize) - 1 }; ($r:expr, Bytes) => { io::scan($r) }; ($r:expr, String) => { String::from_utf8(scan!($r, Bytes)).unwrap() }; ($r:expr, $t:ty) => { scan!($r, String).parse::<$t>().unwrap() }; } #[macro_export] macro_rules! input { ($($($v:ident)* : $t:tt),* $(,)?) => { let stdin = std::io::stdin(); let ref mut reader = std::io::BufReader::new(stdin.lock()); $(let $($v)* = scan!(reader, $t);)* }; } } pub mod binary_search { pub trait BinarySearch { fn lower_bound(&self, x: &T) -> usize; fn upper_bound(&self, x: &T) -> usize; } impl BinarySearch for [T] { fn lower_bound(&self, x: &T) -> usize { let mut left = 0; let mut right = self.len(); while left < right { let mid = (left + right) / 2; if unsafe { self.get_unchecked(mid) } < x { left = mid + 1; } else { right = mid; } } left } fn upper_bound(&self, x: &T) -> usize { let mut left = 0; let mut right = self.len(); while left < right { let mid = (left + right) / 2; if unsafe { self.get_unchecked(mid) } <= x { left = mid + 1; } else { right = mid; } } left } } } use std::io::Write; use binary_search::BinarySearch; fn main() { input! { n: usize, a: [usize; n], b: [usize; n], } let stdout = std::io::stdout(); let mut writer = std::io::BufWriter::new(stdout.lock()); let m = { a.iter() .zip(b.iter()) .map(|(a, b)| if a < b { b - a } else { a - b }) .sum::() }; writeln!(writer, "{}", m).ok(); let i = { (0..n).position(|i| { if a[i] == b[i] { true } else if a[i] < b[i] { i + 1 == a.upper_bound(&b[i]) } else { a.lower_bound(&b[i]) == i } }).unwrap() }; let mut moving = |i: usize| { if a[i] < b[i] { for _ in 0..b[i] - a[i] { writeln!(writer, "{} {}", i + 1, 'R').ok(); } } else if b[i] < a[i] { for _ in 0..a[i] - b[i] { writeln!(writer, "{} {}", i + 1, 'L').ok(); } } }; moving(i); for i in (0..i).rev() { moving(i); } for i in i + 1..n { moving(i); } }