#include using namespace std; using ll = long long; template ostream& operator<<(ostream& os, const deque arr){ for(int i = 0; i < (int)arr.size(); i++)cout << arr[i] << (i == (int)arr.size() -1 ? "" : " "); return os;} int main() { int n, m; cin >> n >> m; deque que(n); for(int i = 0; i < n; i++)cin >> que[i]; for(int i = 0; i < m; i++) { char c; cin >> c; if(c == 'R') { int a = que.back(); que.pop_back(); int b = que.back(); que.pop_back(); que.push_back(a + b); que.push_front(0); } else { int a = que.front(); que.pop_front(); int b = que.front(); que.pop_front(); que.push_front(a + b); que.push_back(0); } } cout << que << endl; }