use std::collections::VecDeque; use std::io::*; fn main() { 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 mut a: VecDeque = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let s: Vec = itr.next().unwrap().chars().collect(); for i in 0..m { if s[i] == 'L' { let x = a.pop_front().unwrap(); let y = a.pop_front().unwrap(); a.push_front(x + y); a.push_back(0); } else { let x = a.pop_back().unwrap(); let y = a.pop_back().unwrap(); a.push_back(x + y); a.push_front(0); } } let mut out = Vec::new(); for i in 0..n { write!(out, "{} ", a.pop_front().unwrap()).ok(); if i == n - 1 { writeln!(out, "").ok(); } } stdout().write_all(&out).unwrap(); }