local n, m = io.read("*n", "*n", "*l") local s = io.read() local t = {} for i = 1, (n + 1) * (n + 1) do t[i] = 1 end t[1] = 0 local byte_u = string.byte("U") local byte_d = string.byte("D") local byte_r = string.byte("R") local curpos = 0 local x, y = 1, 1 for irep = 1, m do local b = s:byte(irep) if b == byte_u then y = y + 1 elseif b == byte_d then y = y - 1 elseif b == byte_r then x = x + 1 else x = x - 1 end local idx = (x - 1) * (n + 1) + y t[idx] = 0 end for y = n + 1, 1, -1 do for x = 1, n + 1 do local idx = (x - 1) * (n + 1) + y io.write(t[idx]) io.write(x == n + 1 and "\n" or " ") end end