#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; string s; cin >> s; int lp = 0, rp = n - 1; int lev = 0; set ls, rs; ls.insert(0); rs.insert(n - 1); rep(i, m){ if(s[i] == 'L'){ if(-(n - 1) < lev) lev--; if(lev < 0) ls.insert(-lev); if(lp > 0) lp--; if(rp > 0) rp--; }else{ if(lev < n - 1) lev++; if(lev > 0) rs.insert(n - 1 - lev); if(lp < n - 1) lp++; if(rp < n - 1) rp++; } } vector ans(n, 0); if(ls.size() == n || rs.size() == n){ ll sm = 0; rep(i, n) sm += a[i]; ans[lp] = sm; }else{ ll lsm = 0; for(int i : ls) lsm += a[i]; ll rsm = 0; for(int i : rs) rsm += a[i]; ans[lp] = lsm; int lc = ls.size(); for(int i = lp + 1; i < rp; i++){ ans[i] = a[lc + i - lp - 1]; } ans[rp] = rsm; } rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " "); }