import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ts <- getIntList
    as <- getIntList
    let tans = reverse . fst $ foldl' f ([],0) ts
        aans = fst $ foldr (flip f) ([],0) as
    let ans = foldl' g 1 $ zipWith check tans aans
    print ans

f (hs,p) h | p == h = ((h,h):hs,h)
           | p > h = ((0,h):hs,h)
           | p < h = ((1,h):hs,h)

check (d1,h1) (d2,h2) | d1 == 1 && d2 == 1 && h1 == h2 = 1
                      | d1 == 1 && d2 == 1 = 0
                      | d1 == 0 || d2 == 0 = 0
                      | d1 == 1 && h1 > h2 = 0
                      | d2 == 1 && h1 < h2 = 0
                      | otherwise = min d1 d2

g a b = (a*b) `mod` 1000000007