#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, m; cin >> n >> m; vector a(n); rep(i,n) cin >> a[i]; string s; cin >> s; int top = a[0], back = a[n - 1]; deque que; for (int i = 1; i < n - 1; i++) que.push_back(a[i]); for (int i = 0; i < m; i++) { if (s[i] == 'L') { que.push_back(back); back = 0; top += que.front(); que.pop_front(); } else { que.push_front(top); top = 0; back += que.back(); que.pop_back(); } //cout << top << " " << back << endl; } cout << top << " "; while (!que.empty()) cout << que.front() << " ", que.pop_front(); cout << back << endl; return 0; }