#include <bits/stdc++.h>
using namespace std;

#define int long long

int n, c;
int a[404], b[404];

const int mod = 1e9 + 7;
long long dp[404][404];

signed main()
{
  cin >> n >> c;
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  for (int i = 0; i < n; i++){
    cin >> b[i];
  }

  dp[0][0] = 1;
  for (int i = 0; i < n; i++){
    for (int j = a[i]; j <= b[i]; j++){
      int po[404] ={};
      po[0] = dp[i][0];
      for (int k = 0; k <= c; k++){
        if (k) po[k] = (po[k - 1] * j + dp[i][k]) % mod;
        dp[i + 1][k] += po[k];
        dp[i + 1][k] %= mod;
      }
    }
  }

  cout << dp[n][c] << endl;
}
