import Data.List splitWhen :: (a->Bool) -> [a] -> [[a]] splitWhen _ [] = [] splitWhen f xs = first : (splitWhen f $ drop 1 $ rest) where (first,rest) = break f xs incr :: String -> String -> Int incr lst rs@(r1:r2) | l < r && z = 10^(length rs) | l < r = 0 | difL == [] = difPow | read difR > r = bigL 1 | otherwise = bigL 0 where ls = dropWhile (=='0') lst l = read ls :: Int r = read rs :: Int z = r1 == '0' (difL,difR) = splitAt ((length ls) - (length rs)) ls difPow = 10^(length rs) bigL = \n -> difPow * (read difL + n) incr _ _ = 0 parse :: [[String]] -> [Int] parse (x@(x11:x12:x13:x1s):xs) = [f1,f1+(read x13)..(recAdd + ((read x12)-1))] ++ (map (+recAdd) $ parse $ [x12]:xs) where f1 = read x11 recAdd = incr x11 x12 parse ((x11:x12:x1s):xs) = [read x11..(recAdd+((read x12)-1))] ++ (map (+recAdd) $ parse $ [x12]:xs) where recAdd = incr x11 x12 parse ((x11:_):x2@(x21:_):xs) = read x11 : (map (+recAdd) $ parse $ x2:xs) where recAdd = incr x11 x21 parse ((x11:_):xs) = [read x11] parse _ = [] main = interact $ (intercalate "\n\n").(map ((intercalate " ").(map show).parse.(map $ (filter (/= [])).splitWhen ((flip elem) ":-.")).(splitWhen (==',')))).lines