import Data.List import Data.Char main = getContents >>= print . block . unfoldr ints where ints xs = if null xs then Nothing else (return . head . reads . dropWhile isSpace) xs block (l:_:ws) = length $ takeWhile (<= l) (scanl1 (+) (sort ws))