N, M = gets.split.map(&:to_i) S = gets.chomp grid = Array.new(N + 1) { Array.new(N + 1, 1) } cy = N cx = 0 grid[cy][cx] = 0 S.each_char do |s| case s when 'U' cy -= 1 when 'R' cx += 1 when 'D' cy += 1 when 'L' cx -= 1 end grid[cy][cx] = 0 end puts grid.map { |row| row.join(' ') }