-- 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 = check n "" s0 calc o = chr . flip o 1 . ord inc = calc (+) dec = calc (-) check b ys (x:xs) = select =<< res where res = putStrLn str >> hFlush stdout >> read . head . words <$> getLine str = reverse ys ++ (x:xs) d = dec x i = inc x select r | r == n = pure () | r > b = check n (x:ys) xs | r < b && b < n = check n (d:ys) xs | otherwise = check r ys (i:xs)