#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int x[1005], y[1005], sum[1005];
long long fac[1005], inv[1005], f[1005][1005];
long long qpow(long long x, long long y) {
  long long tmp = 1ll;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) tmp = tmp * x % mod;
  return tmp;
}
long long Inv(long long x) { return qpow(x, mod - 2); }
long long C(int x, int y) { return fac[x] * inv[y] % mod * inv[x - y] % mod; }
int main() {
  int i, j, m;
  fac[0] = inv[0] = 1ll;
  for (i = 1; i < 1005; ++i)
    fac[i] = fac[i - 1] * i % mod, inv[i] = Inv(fac[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; ++i) scanf("%d", &x[i]), sum[i] = sum[i - 1] + x[i];
  for (i = 1; i <= m; ++i) scanf("%d", &y[i]);
  f[0][0] = 1ll;
  for (i = 1; i <= m; ++i) {
    for (j = 0; j <= sum[i]; ++j) {
      for (int k = 0; k <= min(j, y[i]); ++k) {
        (f[i][j] += f[i - 1][j - k] * C(sum[i] - j + k, k) % mod) %= mod;
      }
    }
  }
  long long tmp = fac[sum[m]];
  for (i = 1; i <= m; ++i) tmp = tmp * Inv(fac[x[i]]) % mod;
  printf("%lld\n", f[m][sum[m]] * tmp % mod);
  return 0;
}
