N = gets.to_i A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) positions = Array.new(1_000_010, false) A.each do |a| positions[a] = true end def dfs(i, positions, commands) while A[i] != B[i] a = A[i] if A[i] < B[i] if positions[a + 1] dfs(i + 1, positions, commands) else commands << [i, 'R'] positions[a] = false positions[a + 1] = true A[i] += 1 end else if positions[a - 1] dfs(i + 1, positions, commands) else commands << [i, 'L'] positions[a] = false positions[a - 1] = true A[i] -= 1 end end end end commands = [] N.times do |i| dfs(i, positions, commands) end puts commands.size puts commands.map { |i, d| [i + 1, d].join(' ') }