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