#pragma GCC optimize("O3") #include #define ll long long #define rep(i,n) for(ll i=0;i<(n);i++) #define pll pair #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define lb(c,x) distance(c.begin(),lower_bound(all(c),x)) #define ub(c,x) distance(c.begin(),upper_bound(all(c),x)) using namespace std; template inline bool chmax(T& a,T b){if(a inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} const ll INF=1e9+7; int main() { ll n,m; cin >> n >> m; vector a(n); ll sum=0; rep(i,n){ cin >> a[i]; sum+=a[i]; } ll cnt=0; ll Min=0; ll Max=0; string s; cin >> s; rep(i,m){ if(s[i]=='R') cnt++; else cnt--; Min=min(Min,cnt); Max=max(Max,cnt); } ll le=Max; ll ri=n-1-abs(Min); if(Max>=n-1 || abs(Min)>=n-1){ ll p=0; //一番左としてよい。 rep(i,m){ if(s[i]=='L') p--; else p++; if(p>=n) p=n-1; if(p<=-1) p=0; } rep(i,n){ if(i) cout << " "; if(i==p) cout << sum; else cout << 0; } cout << endl; } else{ ll sum_L=0; for(ll i=0;i<=abs(Min);i++){ sum_L+=a[i]; } ll sum_R=0; for(ll i=n-1-Max;i<=n-1;i++){ sum_R+=a[i]; } rep(i,n){ if(i) cout << " "; if(0<=i && i<=abs(Min)+cnt-1) cout << 0; else if(n-Max+cnt<=i && i<=n-1) cout << 0; else if(i==abs(Min)+cnt) cout << sum_L; else if(i==n-1-Max+cnt) cout << sum_R; else cout << a[i]; } } return 0; }