#include using namespace std; const int INF = 1000000; vector dy = {1, 0, 0}; vector dx = {0, 1, -1}; struct lazy_segment_tree{ int N; vector ST, lazy; lazy_segment_tree(vector &A){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector(N * 2 - 1, -INF); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } lazy = vector(N * 2 - 1, 0); } void eval(int i){ if (i < N - 1){ lazy[i * 2 + 1] += lazy[i]; lazy[i * 2 + 2] += lazy[i]; } ST[i] += lazy[i]; lazy[i] = 0; } void range_add(int L, int R, int x, int i, int l, int r){ eval(i); if (r <= L || R <= l){ return; } else if (L <= l && r <= R){ lazy[i] = x; eval(i); } else { int m = (l + r) / 2; range_add(L, R, x, i * 2 + 1, l, m); range_add(L, R, x, i * 2 + 2, m, r); ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void range_add(int L, int R, int x){ range_add(L, R, x, 0, 0, N); } int range_max(int L, int R, int i, int l, int r){ eval(i); if (r <= L || R <= l){ return -INF; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r)); } } int range_max(int L, int R){ return range_max(L, R, 0, 0, N); } }; int main(){ int N, X, Y; cin >> N >> X >> Y; string S; cin >> S; vector T(1); for (int i = 0; i < N; i++){ if (S[i] == 'S'){ T.push_back(""); } else { T.back() += S[i]; } } int K = T.size(); if (Y >= K){ cout << -1 << endl; } else { vector a(K + 1, 0); vector>> add(K); vector> a2 = {a}; for (int i = 0; i < K; i++){ int sz = T[i].size(); for (int j = 0; j < sz; j++){ if (T[i][j] == 'R'){ for (int k = 0; k <= i; k++){ a[k]++; } add[i].push_back(make_pair(i + 1, 1)); } if (T[i][j] == 'L'){ int r = 0; while (a[r] > 0){ r++; } for (int k = 0; k < r; k++){ a[k]--; } add[i].push_back(make_pair(r, -1)); } } a2.push_back(a); } vector> dp(Y + 2, vector(K + 1, -INF)); dp[0][0] = 0; for (int i = 0; i <= Y; i++){ lazy_segment_tree ST(dp[i]); for (int j = 0; j <= K; j++){ dp[i + 1][j] = ST.range_max(0, j); if (j < K){ int cnt = add[j].size(); for (int k = 0; k < cnt; k++){ ST.range_add(0, add[j][k].first, add[j][k].second); } } } } if (dp[Y + 1][K] < X){ cout << -1 << endl; } else { vector P(Y + 2); P[Y + 1] = K; for (int i = Y; i >= 0; i--){ for (int j = 0; j < P[i + 1]; j++){ if (dp[i + 1][P[i + 1]] == dp[i][j] + a2[P[i + 1]][j]){ P[i] = j; break; } } } vector L(Y + 1); for (int i = 0; i <= Y; i++){ L[i] = dp[i][P[i]]; } vector T2(Y + 1); for (int i = 0; i <= Y; i++){ for (int j = P[i]; j < P[i + 1]; j++){ T2[i] += T[j]; T2[i] += 'S'; } } T2[Y].pop_back(); vector R = L; for (int i = 0; i <= Y; i++){ int x = L[i]; int l = T2[i].size(); for (int j = 0; j < l; j++){ if (T2[i][j] == 'L'){ x--; } if (T2[i][j] == 'R'){ x++; } x = max(x, L[i]); R[i] = max(R[i], x); } } set> st; for (int i = 0; i <= Y; i++){ for (int j = L[i]; j <= R[i]; j++){ st.insert(make_pair(i, j)); } } vector> ans(Y + 2); for (auto P : st){ int y = P.first; int x = P.second; for (int i = 0; i < 3; i++){ int y2 = y + dy[i]; int x2 = x + dx[i]; if (st.count(make_pair(y2, x2)) == 0){ ans[y2].push_back(x2); } } } for (int i = 0; i < Y + 2; i++){ sort(ans[i].begin(), ans[i].end()); ans[i].erase(unique(ans[i].begin(), ans[i].end()), ans[i].end()); } while (true){ set> st2; for (int i = 0; i < Y + 2; i++){ int cnt = ans[i].size(); for (int j = 0; j < cnt; j++){ st2.insert(make_pair(i, ans[i][j])); } } int cx = 0, cy = 0; vector up(Y + 1); vector id(Y); for (int i = 0; i < N; i++){ int x2 = cx, y2 = cy; if (S[i] == 'L'){ x2--; } if (S[i] == 'R'){ x2++; } if (S[i] == 'S'){ y2++; } if (st2.count(make_pair(y2, x2)) == 1){ x2 = cx; y2 = cy; } if (y2 != cy){ id[cy] = i; up[cy] = x2; } cx = x2; cy = y2; } up[Y] = cx; if (cx == X){ break; } vector d(Y + 1); d[0] = up[0]; for (int j = 1; j <= Y; j++){ d[j] = up[j] - up[j - 1]; } int p = 0; while (d[p] == 0){ p++; } ans[p].back()--; set> st3; for (int i = 0; i < Y + 2; i++){ int cnt = ans[i].size(); for (int j = 0; j < cnt; j++){ st3.insert(make_pair(i, ans[i][j])); } } vector px(N + 1), py(N + 1); px[0] = 0; py[0] = 0; for (int i = 0; i < N; i++){ px[i + 1] = px[i]; py[i + 1] = py[i]; if (S[i] == 'L'){ px[i + 1]--; } if (S[i] == 'R'){ px[i + 1]++; } if (S[i] == 'S'){ py[i + 1]++; } if (st3.count(make_pair(py[i + 1], px[i + 1])) == 1 || py[i + 1] > p){ px[i + 1] = px[i]; py[i + 1] = py[i]; } } if (px[id[p]] != up[p]){ for (int i = p + 1; i < Y + 2; i++){ int cnt = ans[i].size(); for (int j = 0; j < cnt; j++){ ans[i][j]--; } } } } for (int i = 0; i < Y + 2; i++){ ans[i].erase(unique(ans[i].begin(), ans[i].end()), ans[i].end()); } int M = 0; for (int i = 0; i < Y + 2; i++){ M += ans[i].size(); } cout << M << endl; for (int i = 0; i < Y + 2; i++){ int cnt = ans[i].size(); for (int j = 0; j < cnt; j++){ cout << ans[i][j] << ' ' << i << endl; } } } } }