use std::collections::VecDeque; use std::io::*; fn main() { // ref: https://yukicoder.me/submissions/462707 let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let _m: usize = itr.next().unwrap().parse().unwrap(); let d: VecDeque = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let s: String = itr.next().unwrap().to_string(); let r: String = solve(d, s); println!("{}", r); } fn solve(d: VecDeque, s: String) -> String { let mut e = d; for c in s.chars() { if c == 'L' { let a = e.pop_front().unwrap(); let b = e.pop_front().unwrap(); e.push_front(a + b); e.push_back(0); } else { let a = e.pop_back().unwrap(); let b = e.pop_back().unwrap(); e.push_back(a + b); e.push_front(0); } } e.iter() .map(|i| i.to_string()) .into_iter() .collect::>() .join(" ") }