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