import Data.Ord (comparing) import Data.List (sortBy, sort) import Data.Maybe (fromJust) import Control.Applicative ((<$>)) import Control.Monad (replicateM_) findDungeon :: [[Int]] -> Maybe Int findDungeon xs | 6 * x >= 30000 * 100 = Just i | otherwise = Nothing where (i, x) = head $ sortBy (flip $ comparing snd) $ zip [1 .. length xs] $ map (\(g : d : _) -> g - 30000 * d) xs main :: IO () main = do _ <- getLine i <- findDungeon . map (map read) . map words . lines <$> getContents if i == Nothing then putStrLn "NO" else putStrLn "YES" >> replicateM_ 6 (print $ fromJust i)