#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
const int N = 1005;
const int M = 105;
int n, m;
int x[N], y[N];
int s[N];
long long c[N][N];
long long f[M][N];
long long mo(long long x) {
  if (x < p) return x;
  return x - p;
}
void pre() {
  c[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; ++j) c[i][j] = mo(c[i - 1][j - 1] + c[i - 1][j]);
  }
}
int main() {
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%d", &x[i]), n += x[i], s[i] = n;
  for (int i = 1; i <= m; ++i) scanf("%d", &y[i]);
  pre();
  f[0][0] = 1;
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= s[i]; ++j)
      for (int k = 0; k <= y[i] && k <= j; ++k)
        f[i][j] = mo(f[i][j] + f[i - 1][j - k] * c[s[i] - j + k][k] % p);
  }
  long long ans = f[m][n];
  for (int i = 1; i <= m; ++i) ans = ans * c[n - s[i - 1]][x[i]] % p;
  cout << ans;
  return 0;
}
