#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
char inp[10000];
string nextString() {
  scanf("%s", inp);
  return inp;
}
double nextDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
const int Mod = 1000000007;
void add(int &a, int b) {
  a += b;
  if (a >= Mod) {
    a -= Mod;
  }
}
long long C[1010][1010];
int main() {
  C[0][0] = 1;
  for (int i = 1; i < 1010; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
    }
  }
  int m = nextInt();
  vector<int> x(m);
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    x[i] = nextInt();
    sum += x[i];
  }
  vector<int> y(m);
  for (int i = 0; i < m; ++i) {
    y[i] = nextInt();
  }
  vector<vector<int> > dp(m + 1, vector<int>(1001, 0));
  dp[0][0] = 1;
  for (int at = 0; at < m; ++at) {
    for (int s = 0; s <= 1000; ++s) {
      if (dp[at][s] != 0) {
        for (int cur = 0; cur <= y[at] && cur <= x[at] + s; ++cur) {
          add(dp[at + 1][s + x[at] - cur], C[x[at] + s][cur] * dp[at][s] % Mod);
        }
      }
    }
  }
  long long res = dp[m][0];
  for (int i = 0; i < m; ++i) {
    res = res * C[sum][x[i]] % Mod;
    sum -= x[i];
  }
  printf("%d\n", res);
  return 0;
}
