import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace import System.IO import System.Exit up xs i x = take i xs ++ [x] ++ drop (i+1) xs maxind [x] i = i maxind (x:y:xs) i = if x > y then i else maxind (y:xs) (i+1) solve :: Int -> [Int] -> IO [Int] solve i xs = do res <- forM [0..9] $ \j -> do [a,_] <- query $ up xs i j return a return $ up xs i (maxind res 0) query (n1:n2:n3:n4:_) = do printf "%d %d %d %d\n" n1 n2 n3 n4 hFlush stdout res <- fmap (read :: String -> Int) . words <$> getLine if (head res) == 4 then exitSuccess else return res main = solve 0 [0,0,0,0] >>= solve 1 >>= solve 2 >>= solve 3 >>= query