#include <bits/stdc++.h>
using namespace std;
const long long modulo = 1000000007;
const int MAXN = 1005;
int X[MAXN], Y[MAXN];
long long ans;
long long C[MAXN][MAXN];
long long dp[MAXN][MAXN];
int main() {
  int m, n, nowcnt;
  n = 0;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &(X[i])), n += X[i];
  for (int i = 1; i <= m; i++) scanf("%d", &(Y[i]));
  for (int i = 0; i <= n; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j <= i - 1; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % modulo;
  }
  ans = 1;
  nowcnt = n;
  for (int i = 1; i <= m; i++)
    ans = ans * C[nowcnt][X[i]] % modulo, nowcnt -= X[i];
  dp[0][0] = 1;
  for (int i = 0, nowcnt = X[1]; i <= m - 1; i++, nowcnt += X[i + 1])
    for (int j = 0; j <= nowcnt; j++) {
      for (int k = 0; k <= min(Y[i + 1], nowcnt - j); k++)
        dp[i + 1][j + k] =
            (dp[i + 1][j + k] + C[nowcnt - j][k] * dp[i][j] % modulo) % modulo;
    }
  ans = ans * dp[m][n] % modulo;
  printf("%I64d\n", ans);
  return 0;
}
