#pragma region Macros // #pragma GCC target("avx2") #pragma GCC optimize("O3") #include #include #define rep(i, n) for (long long i = 0; i < (n); i++) #define rrep(i, n) for (long long i = (n - 1); i >= 0; i--) #define ALL(v) v.begin(), v.end() #define endl "\n" #define fi first #define se second #define popcount(bit) __builtin_popcount(bit) #define popcountll(bit) __builtin_popcountll(bit) #define pb push_back #define eb emplace_back using namespace std; using namespace atcoder; using P = pair; using PL = pair; using Graph = vector>; typedef long long ll; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; template const auto INF = numeric_limits::max()/2; int main() { int n; cin >> n; vector A(n), B(n); rep(i, n) cin >> A[i]; rep(i, n) cin >> B[i]; set st1; set st2; rep(i, n){ st1.insert(A[i]); st2.insert(B[i]); } if(n == 1){ return 0; } vector

ans; queue que; if(A[0] >= B[0])que.push(0); else { if(B[0] < A[1]){ que.push(0); } } if(A[n-1] <= B[n-1])que.push(n-1); else{ if(B[n-1] > A[n-2])que.push(n-1); } vector used(n); while (!que.empty()){ int d = que.front(); que.pop(); if(used[d])continue; used[d] = 1; st1.erase(A[d]); st1.insert(B[d]); st2.erase(B[d]); if(A[d] >= B[d]){ rep(j, A[d]- B[d]){ ans.pb({d, 0}); } }else{ rep(j, B[d]- A[d]){ ans.pb({d, 1}); } } if(st2.empty())break; if(d > 0){ if(*st2.lower_bound(A[d-1]) == B[d-1]){ que.push(d - 1); } if(*st2.rbegin() == B[d-1]){ que.push(d - 1); } if(*st1.lower_bound(B[d-1]) == A[d-1]){ que.push(d - 1); } if(*st1.lower_bound(B[d-1]) == A[d-1]){ que.push(d - 1); } } if(d < n-1){ if(*st2.lower_bound(A[d+1]) == B[d+1]){ que.push(d + 1); } if(*st1.lower_bound(B[d+1]) == A[d+1]){ que.push(d + 1); } } } cout << ans.size() << endl; for (auto [a, b] : ans){ if(b == 0){ cout << a + 1 << " L" << endl; }else{ cout << a + 1 << " R" << endl; } } }