#include #include #include #include #include #include #include #include #include #include #include #include //cout << fixed << setprecision(15) << x << endl; using namespace std; typedef long long ll; const ll INF = 1e9 + 8; const ll MOD = 1e9 + 7; const ll LLINF = 1e18; #define Pint pair #define rng(i, a, b) for(int i = int(a); i < int(b); i++) #define rnr(i, a, b) for(int i = int(a); i >= int(b); i--) #define rep(i, b) rng(i, 0, b) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() /* -- template -- */ int main() { int n, m; cin >> n >> m; ll a[n]; rep(i, n) cin >> a[i]; string s; cin >> s; int l = 0, r = n - 1; int now = 0, maxr = 0, minl = 0, peni = 0; for(char c : s) { if(c == 'L') { if(peni > 0) --peni; --now; if(l < n - 1) { if(now < minl) { a[l + 1] += a[l]; a[l] = 0; ++l; minl = now; } } } else if(c == 'R') { if(peni < n - 1) ++peni; ++now; if(r > 0) { if(now > maxr) { a[r - 1] += a[r]; a[r] = 0; --r; maxr = now; } } } } rep(i, peni) cout << 0 << ' '; rng(i, peni, n) { cout << a[i] << ' '; } }