#include #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair pii; template bool chmax(T &a, const T &b){if(a bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1e9+7; constexpr lint INF = mod * mod; constexpr int MAX = 200010; int n, m, a[MAX]; string s; bool check_L(int mid){ if(mid == 0) return true; for(auto c: s){ (c == 'L' ? --mid : ++mid); if(mid == 0) return true; } return false; } bool check_R(int mid){ if(mid == n-1) return true; for(auto c: s){ (c == 'L' ? --mid : ++mid); if(mid == n-1) return true; } return false; } int main(){ scanf("%d%d", &n, &m); rep(i, n) scanf("%d", &a[i]); cin >> s; int x = 0, y = 0, z = n-1; for(auto c: s){ if(c == 'L'){ --x; --y; --z; chmax(x, 0); chmax(z, 0); } else{ ++x; ++y; ++z; chmin(x, n-1); chmin(z, n-1); } } int ans[n]; memset(ans, 0, sizeof(ans)); int L, R, low = 0, high = n-1; if(check_L(n-1)){ ans[x] = accumulate(a, a+n, 0); rep(i, n) printf("%d ", ans[i]); return 0; } while(high - low > 1){ int mid = (high + low) / 2; (check_L(mid) ? low : high) = mid; } L = low; low = L, high = n-1; if(check_R(0)){ ans[z] = accumulate(a, a+n, 0); rep(i, n) printf("%d ", ans[i]); return 0; } while(high - low > 1){ int mid = (high + low) / 2; (check_R(mid) ? high : low) = mid; } R = high; rep(i, n){ if(i <= L) ans[x] += a[i]; else if(i >= R) ans[z] += a[i]; else ans[i+y] += a[i]; } rep(i, n) printf("%d ", ans[i]); }