import Data.List
import Data.List.Split
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
main = mapM_ (print . solve) . chunksOf 3 . map (map read . words) . lines =<< getContents
solve [[n,c],as,bs] = dp VU.! (idx n c)  where
  ps = V.fromList . map VU.fromList . transpose . map f2 . transpose . map f1 $ [0..maximum bs] where
    f1 = scanl (\a b->a*b`mod`m) 1 . replicate c
    f2 = scanl1 (\a b->(a+b)`mod`m)
  qs = V.fromList $ zipWith (\b a->VU.fromList $ map (\k->(p b k-p a k+m)`mod`m) [0..c]) bs $ map pred as
    where p i j = ps V.! i VU.! j
  idx i j = i*(c+1)+j
  dp = VU.create $ do
    dp <- VM.replicate ((c+1)*(n+1)) 0
    VM.write dp (idx 0 0) 1
    forM_ [1..n] $ \i ->
      forM_ [0..c] $ \j ->
        forM_ [0..j] $ \k -> do
          a <- VM.read dp (idx i j)
          b <- VM.read dp (idx (i-1) (j-k))
          VM.write dp (idx i j) ((a+b*(qs V.! (i-1) VU.! k))`mod`m)
    return dp
m = 1000000007