-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU import Control.Applicative import System.IO import Data.List import Data.Char main = g n [] $ replicate n '0' where n = 10 g b ys (x:xs) = h =<< m where m = putStrLn str >> hFlush stdout >> read . head . words <$> getLine str = reverse ys ++ (x:xs) calc o = chr . flip o 1 . ord d = calc (-) x i = calc (+) x h r | r == n = pure () | r > b = g r (x:ys) xs | r < b && b < n = g r (d:ys) xs | otherwise = g r ys (i:xs)