#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483640;
long long geti() {
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  long long ret = 0, k = 1;
  if (ch == '-') k = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
  return ret * k;
}
const int mo = 1e9 + 7;
int n;
long long C[1052][1052], f[1052][1052];
int x[1052], y[1052], S[1052];
int main() {
  n = geti();
  for (int i = 1; i <= n; i++) x[i] = geti();
  for (int i = 1; i <= n; i++) y[i] = geti();
  for (int i = 1; i <= n; i++) S[i] = S[i - 1] + x[i];
  for (int i = 0; i <= S[n]; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mo;
    }
  }
  f[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= S[i]; j++) {
      int mxk = min(S[i + 1] - j, y[i + 1]);
      for (int k = 0; k <= mxk; k++) {
        (f[i + 1][j + k] += f[i][j] * C[S[i + 1] - j][k] % mo) %= mo;
      }
    }
  }
  long long mul = 1;
  int tot = S[n];
  for (int i = 1; i <= n; i++) {
    (mul *= C[tot][x[i]]) %= mo;
    tot -= x[i];
  }
  cout << mul * f[n][S[n]] % mo;
  return 0;
}
