import Data.Functor import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe countExaminee :: [[Int]] -> Int countExaminee (_:xs) = count xs `mod` 1000000007 where count :: [[Int]] -> Int count [] = 0 count ((c:d:_):xs) = v' + ((count xs) `mod` 1000000007) where c' = c `mod` 1000000007 d' = d `mod` 1000000007 v' = (((c' + 1) `div` 2) * d') `mod` 1000000007 readInts :: B.ByteString -> [Int] readInts s = fst <$> mapMaybe (B.readInt) (B.words s) main :: IO () main = countExaminee <$> (readInts <$>) <$> B.lines <$> B.getContents >>= putStrLn . show