--- /dev/null
+import Data.Word
+import Data.Bits
+import Numeric (showIntAtBase)
+import Data.Char (intToDigit)
+
+main :: IO ()
+main = do
+ line1 <- getLine
+ let nBits = read line1 :: Int
+ let n = fromIntegral $ 2 ^ nBits
+ let codes = [toGray x | x <- [0..(n - 1)]]
+ putStrLn $ unlines $ map (showBits nBits) codes
+
+toGray :: Word16 -> Word16
+toGray n = n `xor` (n `shiftR` 1)
+
+showBits :: Int -> Word16 -> String
+showBits k n = prefix ++ suffix
+ where suffix = showIntAtBase 2 intToDigit n ""
+ prefix = replicate (k - length suffix) '0'
\ No newline at end of file