#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int main() { int n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; string s; cin >> s; int leftpos = 0; int rightpos = n-1; int left = 0; int right = n -1; rep(i, m) { if(s[i] == 'L') { if(leftpos == 0) { left = min(left+1, n-1); } else { leftpos -= 1; } rightpos = max(0, rightpos-1); } else { if(rightpos == n-1) { right = max(0, right-1); } else { rightpos += 1; } leftpos = min(n-1, leftpos+1); } } vector result(n, 0); rep(i, left+1) result[leftpos] += a[i]; if(leftpos < rightpos) { for(int i=left+1; i