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) = ((c' + 1) `div` 2) * d' + count xs where c' = c `mod` 1000000007 d' = 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