object Main extends App {
  import scala.io.StdIn._

  val mod = 1000000007L

  val Array(n, c) = readLine.trim.split(' ').map(_.toInt)
  val a = readLine.trim.split(' ').map(_.toInt)
  val b = readLine.trim.split(' ').map(_.toInt)

  println(
    solve(n, c, a, b)
  )

  def solve(n: Int, c: Int, a: Array[Int], b: Array[Int]): Long = {
    val memo = Array.tabulate(n){_ ⇒ Array.tabulate(c + 1){_ ⇒ -1L}}
    val sumExp = Array.tabulate(401){_ ⇒ Array.tabulate(401){_ ⇒ 0L}}.also{arr ⇒
      for (ab ← arr.indices){
        arr(ab)(0) = 1
        for (ar ← arr(ab).indices.tail){
          arr(ab)(ar) = (arr(ab)(ar - 1) * ab) % mod
        }
      }
      for (i ← arr(0).indices) arr(0)(i) = 0
      for (ab ← arr.indices.tail){
        for (ar ← arr(ab).indices){
          arr(ab)(ar) = (arr(ab)(ar) + arr(ab - 1)(ar)) % mod
        }
      }
    }
    def sub(position: Int, rest: Int): Long = {
      if (position == n) {
        if (rest == 0) 1L
        else 0L
      }else {
        if (memo(position)(rest) == -1L){
          memo(position)(rest) = 0
          for (use ← 0 to rest){
            memo(position)(rest) = (memo(position)(rest) + ((sumExp(b(position))(use) - sumExp(a(position) - 1)(use) + mod) % mod) * sub(position + 1, rest - use)) % mod
          }
        }
        memo(position)(rest)
      }
    }
    sub(0, c)
  }
  def exponent(base: Long, exp: Int): Long = {
    if (exp == 0) 1
    else if (exp == 1) base
    else exponent(base, exp / 2).let(it ⇒ it * it * exponent(base, exp % 2)) % mod
  }


  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
