#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#define int long long #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back using namespace std; typedef long long ll; typedef pair P; typedef long double ld; typedef complex com; constexpr ll INF = 1000000000000000000; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238; template inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; string s; cin >> s; int leftcnt = 0, rightcnt = 0, leftidx = 0, rightidx = n - 1; rep(i, m) { if (s[i] == 'L') { if (leftcnt) { leftcnt--; rightcnt++; } else { if (rightcnt < n - 1) { rightcnt++; leftidx++; } } } else { if (rightcnt) { rightcnt--; leftcnt++; } else { if (leftcnt < n - 1) { leftcnt++; rightidx--; } } } } int left = 0, right = 0; rep(i, leftidx + 1) left += a[i]; for (int i = rightidx; i < n; i++) right += a[i]; rep(i, leftcnt) cout << 0 << ' '; cout << left << ' '; for (int i = leftidx + 1; i < rightidx; i++) cout << a[i] << ' '; if (leftcnt + rightcnt != n - 1) cout << right << ' '; rep(i, rightcnt) cout << 0 << ' '; }