#include using namespace std; #define rep(i,n) for(ll i=0;i<(n);++i) using ll = int_fast64_t; using pll = pair; constexpr ll INF = 1LL<<60; constexpr ll MOD = 1e9+7; template bool chmax(T &a,const T &b){if(a bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} #if loc||local void dump(){cerr< void dump(T&& h, Ts&&... t){cerr<(t)...);} #else void dump(){} template void dump(T&& h, Ts&&... t){} #endif template istream &operator>>(istream&is,vector&v){for(auto &elemnt:v)is>>elemnt;return is;} template istream &operator>>(istream&is,pair&p){is>>p.first>>p.second;return is;} template ostream &operator<<(ostream& os,vectorconst& v){for(auto const& vi:v)os< ostream &operator<<(ostream& os,pairconst& p){os<vector vec(size_t a){return vector(a);} templateauto vec(size_t a, Ts... ts){return vector(ts...))>(a, vec(ts...));} signed main(){ int n,m; cin>>n>>m; vector a(n); cin>>a; string s; cin>>s; int state = 0; set st; rep(i,n)st.emplace(i,a[i]); rep(i,m){ if(s[i]=='L'){ auto itr = st.lower_bound({state+1,-1}); state--; if((*itr).first!=state+2)continue; auto itr2 = begin(st); st.emplace(0,(*itr2).second+(*itr).second); st.erase(itr); st.erase(itr2); } if(s[i]=='R'){ auto itr = st.lower_bound({state+n-2,-1}); state++; if((*itr).first!=state+n-3)continue; auto itr2 = --end(st); st.emplace(n-1,(*itr2).second+(*itr).second); st.erase(itr); st.erase(itr2); } } vector ans(n); for(auto [i,v]:st){ if(state>0){ if(i==n-1)ans[i]=v; else ans[i+state]=v; } if(state<0){ if(i==0)ans[i]=v; else ans[i+state]=v; } if(state==0){ ans[i]=v; } dump(i,v); } rep(i,n)cout<