module Main where import Control.Monad import Control.Applicative import Data.Maybe import Data.List import qualified Text.Printf import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString as BC ------------------------------------------ main :: IO () main = do n <- readInt fs <- replicateM (n-1) readInt (_,c0):xs <- replicateM n $ do [b, c] <- readInts return (b, c) let h (a,p) (f,(b,c)) = (a+f*p,p-b+c) print $ fst $ foldl' h (0,c0) (zip fs xs) ------------------------------------------ {- Int input -} parseInt :: BC.ByteString -> Int parseInt = fst . fromJust . BC.readInt parseInts :: BC.ByteString -> [Int] parseInts = map parseInt <$> BC.words readInt :: IO Int readInt = parseInt <$> BC.getLine readInts :: IO [Int] readInts = parseInts <$> BC.getLine {- Double Formatting -} doubleFmt :: Double -> String doubleFmt = Text.Printf.printf "%.12f"