import qualified Data.List as L main :: IO () main = do [n, _m] <- map read . words <$> getLine s <- getLine putStrLn $ solve n s solve :: Int -> [Char] -> String solve n = unlines . map (unwords . map showBool) . solve' n where showBool :: Bool -> String showBool b = if b then "0" else "1" solve' :: Int -> [Char] -> [[Bool]] solve' n cs = solve'' n cs [(0, n)] solve'' :: Int -> [Char] -> [(Int, Int)] -> [[Bool]] solve'' n [] ps = fromCoords n $ L.nub ps solve'' n (c:cs) ps@((x, y):_) = solve'' n cs ((x', y'):ps) where x' = case c of 'R' -> x + 1 'L' -> x - 1 _ -> x y' = case c of 'U' -> y - 1 'D' -> y + 1 _ -> y solve'' _ _ [] = [[]] -- unreachable fromCoords :: Int -> [(Int, Int)] -> [[Bool]] fromCoords n ps = fromCoords' ps $ replicate (n + 1) (replicate (n + 1) False) where fromCoords' :: [(Int, Int)] -> [[Bool]] -> [[Bool]] fromCoords' [] bs = bs fromCoords' ((x, y):qs) bs = fromCoords' qs $ update y (update x True (bs!!y)) bs where update :: Int -> a -> [a] -> [a] update i a as = take i as ++ [a] ++ drop (i + 1) as