{-# LANGUAGE NumDecimals #-}
module Main where
import Data.List
import Debug.Trace

getInt :: IO Int
getInt = read <$> getLine

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  n <- getInt
  ts <- getInts
  as <- getInts
  print $ solve ts as
  return ()
solve :: [Int] -> [Int] -> Int
solve ts as = prod' s12
  where
    s1 = determine ts
    s2 = reverse $ determine $ reverse as
    s12 = zipWith f s1 s2
      where
        f (Just a) (Just b) = min a b
        f _ _ = 1
prod' :: [Int] -> Int
prod' = foldl f 1
  where
    f a b = a * b `mod` (1e9 + 7)

determine :: [Int] -> [Maybe Int]
determine xs = Nothing : zipWith f sublist (tail xs)
  where
    sublist = map (>=0) . zipWith (-) xs $ tail xs
    f b x = if b
            then Just x
            else Nothing
