#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long m;
long long a[1010], b[1010];
long long dp[1010][1010];
long long f[1010], pref[1010];
long long inv[1010];
long long C(long long n, long long m) {
  return (long long)f[n] * inv[m] % MOD * inv[n - m] % MOD;
}
signed main() {
  cin >> m;
  dp[0][0] = f[0] = inv[1] = 1;
  for (long long i = 1; i <= 1000; i++) f[i] = (long long)i * f[i - 1] % MOD;
  for (long long i = 2; i <= 1000; i++)
    inv[i] = MOD - (long long)(MOD / i) * inv[MOD % i] % MOD;
  inv[0] = 1;
  for (long long i = 1; i <= 1000; i++)
    inv[i] = (long long)inv[i - 1] * inv[i] % MOD;
  for (long long i = 1; i <= m; i++) cin >> a[i], pref[i] = pref[i - 1] + a[i];
  for (long long i = 1; i <= m; i++) cin >> b[i];
  for (long long i = 1; i <= m; i++) {
    for (long long j = 0; j <= pref[i]; j++) {
      for (long long k = 0; k <= min(j, b[i]); k++) {
        dp[i][j] += (long long)(dp[i - 1][j - k] * C(pref[i] - j + k, k)) % MOD;
        if (dp[i][j] >= MOD) dp[i][j] -= MOD;
      }
    }
  }
  long long ans = (long long)dp[m][pref[m]] * f[pref[m]] % MOD;
  for (long long i = 1; i <= m; i++) ans = (long long)ans * inv[a[i]] % MOD;
  cout << ans << '\n';
  return 0;
}
