#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
const int MOD = (1e9) + 7;
int n, fact[N], invfact[N];
bool used[N][N];
int state[N][N];
int x[N], y[N], s[N], g;
int c[N][N];
int ans;
int fpow(int a, int b) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  int p = fpow(a, b >> 1);
  p = (p * 1ll * p) % MOD;
  if (b & 1) p = (p * 1ll * a) % MOD;
  return p;
}
int div_mod(int a, int b) { return (a * 1ll * fpow(b, MOD - 2)) % MOD; }
int combinations(int n, int k) {
  return div_mod(fact[n], (fact[k] * 1ll * fact[n - k]) % MOD);
}
int comb(int n, int k) { return c[n][k]; }
int recurse(int pos, int groups_used) {
  if (pos > n) {
    if (groups_used == g)
      return 1;
    else
      return 0;
  }
  if (used[pos][groups_used]) return state[pos][groups_used];
  int ans = 0, i, groups = s[pos] - groups_used;
  for (i = 0; i <= y[pos]; i++) {
    if (i <= groups) {
      ans = (ans + (recurse(pos + 1, groups_used + i) * 1ll * comb(groups, i)) %
                       MOD) %
            MOD;
    }
  }
  used[pos][groups_used] = true;
  state[pos][groups_used] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  fact[0] = 1;
  for (i = 1; i < N; i++)
    fact[i] = (fact[i - 1] * 1ll * i) % MOD,
    invfact[i] = fpow(fact[i], MOD - 2);
  for (i = 0; i < N; i++)
    for (j = 0; j <= i; j++) c[i][j] = combinations(i, j);
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &x[i]), g += x[i], s[i] = s[i - 1] + x[i];
  for (i = 1; i <= n; i++) scanf("%d", &y[i]);
  ans = 1;
  for (i = 1; i <= n; i++) {
    ans = (ans * 1ll * comb(g, x[i])) % MOD;
    g -= x[i];
  }
  for (i = 1; i <= n; i++) g += x[i];
  printf("%d\n", (int)((ans * 1ll * recurse(1, 0)) % MOD));
  return 0;
}
