#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::(); let (n, m) = (v[0], v[1]); let a = read_vec::(); let s = read::().chars().collect::>(); let mut cur_0 = 0; for &ch in &s { if ch == 'L' { if cur_0 > 0 { cur_0 -= 1; } } else if ch == 'R' { if cur_0 < n - 1 { cur_0 += 1; } } } let mut a = a.into_iter().collect::>(); let mut count = 0i64; let mut min_count = 0i64; let mut max_count = 0i64; for &ch in &s { if ch == 'L' { count -= 1; } else if ch == 'R' { count += 1; } if count < min_count { min_count = count; if a.len() > 1 { let f = a.pop_front().unwrap(); a[0] += f; } } if count > max_count { max_count = count; if a.len() > 1 { let f = a.pop_back().unwrap(); let idx = a.len() - 1; a[idx] += f; } } } let mut answers = vec![0; n]; for i in cur_0..cur_0 + a.len() { answers[i] = a[i - cur_0]; } for i in 0..n - 1 { print!("{} ", answers[i]); } println!("{}", answers[n - 1]); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }