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