#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}

template <long long modulo>
class Modulo
{
private:
  long long pow(long long q)
  {
    long long a=1;
    long long y=x;
    for(;q!=0;q>>=1)
    {
      if(q&1LL)a=(a*y)%mod;
      y=(y*y)%mod;
    }
    return a;
  }
  long long inv(){return pow(mod-2);}

public:
  long long mod = modulo;
  unsigned long long x;
  Modulo() : x(0) {}
  Modulo(signed s) {while(s<0)s+=mod;x=s%mod;}
  Modulo(signed long long s) {while(s<0)s+=mod;x=s%mod;}
  operator int(){return (int) x;}
  operator long long(){return (long long) x;}
  void operator++(){(*this)+=1;}
  void operator--(){(*this)-=1;}
  Modulo &operator+=(Modulo q){if((x+=q.x)>=mod)x-=mod; return *this;}
  Modulo &operator-=(Modulo q){if((x+=mod-q.x)>=mod)x-=mod; return *this;}
  Modulo &operator*=(Modulo q){x=(unsigned long long)x*q.x%mod; return *this;}
  Modulo &operator/=(Modulo q){x=(unsigned long long)x*q.inv()%mod; return *this;}
  Modulo operator+(Modulo q){return Modulo(*this)+=q;}
  Modulo operator-(Modulo q){return Modulo(*this)-=q;}
  Modulo operator*(Modulo q){return Modulo(*this)*=q;}
  Modulo operator/(Modulo q){return Modulo(*this)/=q;}
  template<typename T> Modulo &operator+=(const T q){if((x+=q)>=mod)x-=mod; return *this;}
  template<typename T> Modulo &operator-=(const T q){if((x+=mod-q)>=mod)x-=mod; return *this;}
  template<typename T> Modulo &operator*=(const T q){x=(unsigned long long)x*q%mod; return *this;}
  template<typename T> Modulo &operator/=(const T q){x=(unsigned long long)x*(Modulo(q)).inv()%mod; return *this;}
  template<typename T> Modulo operator+(const T q){return Modulo(*this)+=q;}
  template<typename T> Modulo operator-(const T q){return Modulo(*this)-=q;}
  template<typename T> Modulo operator*(const T q){return Modulo(*this)*=q;}
  template<typename T> Modulo operator/(const T q){return Modulo(*this)/=q;}
  template<typename T> Modulo power(const T q){return Modulo(pow((long long)q));}
};

int a[410],b[410];
Modulo<MOD> dp[410][410];

int main()
{
  int n,c;cin>>n>>c;
  REP(i,n) cin>>a[i];
  REP(i,n) cin>>b[i];
  Modulo<MOD> x[410][410];
  FOR(i,0,409)
  {
    x[i][0]=1;
    FOR(j,1,c) x[i][j]=x[i][j-1]*i;
  }
  FOR(j,0,c) FOR(i,1,409)
    x[i][j]+=x[i-1][j];
  dp[0][0]=1;
  FOR(i,0,n)FOR(j,0,c)FOR(k,0,c-j)
    dp[j+k][i+1]+=dp[j][i]*(x[b[i]][k]-x[a[i]-1][k]);
  cout << (ll)(dp[c][n]) << endl;
  return 0;
}


Measured memory_bytes: 5504