#include #define all(vec) vec.begin(), vec.end() #define pb push_back #define eb emplace_back using namespace std; using ll = long long; using P = pair; using V = vector; using VL = vector; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll MOD = 1e9 + 7; constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; template void chmin(T &a, T b) { a = min(a, b); } template void chmax(T &a, T b) { a = max(a, b); } void ok() { cerr << "ok" << endl; } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m; cin >> n >> m; VL a(n); deque q; for (int i = 0; i < n; i++) { cin >> a[i]; q.pb(a[i]); } int l = 0, r = n - 1; string s; cin >> s; for (int i = 0; i < m; i++) { if (s[i] == 'L') { if (q.size() > 1 && l == 0) { ll s = q.front(); q.pop_front(); s += q.front(); q.pop_front(); q.push_front(s); } r = max(0, r - 1); l = max(0, l - 1); } else { if (q.size() > 1 && r == n - 1) { ll s = q.back(); q.pop_back(); s += q.back(); q.pop_back(); q.push_back(s); } l = min(n - 1, l + 1); r = min(n - 1, r + 1); } } for (int i = 0; i < n; i++) { if (l <= i && i <= r) { cout << q.front(); q.pop_front(); } else { cout << 0; } cout << (i + 1 == n ? '\n' : ' '); } }