#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1005;
int bc[MAXN + 5][MAXN + 5];
int c(int n, int m) {
  if (n < m) return 0;
  if (n - m <= m) m = n - m;
  return bc[n][m];
}
void intialize() {
  int i, j;
  for (i = 0; i <= MAXN; i++) bc[i][0] = 1;
  for (j = 0; j <= MAXN; j++) bc[j][j] = 1;
  for (i = 1; i <= MAXN; i++)
    for (j = 1; j < i; j++) {
      bc[i][j] = bc[i - 1][j - 1] + bc[i - 1][j];
      if (bc[i][j] >= mod) bc[i][j] -= mod;
    }
}
int m;
int x[200];
int y[200];
int pre[200];
int all;
int dp[105][1009];
int f(int i = 0, int last = 0) {
  if (i == m) return last == 0;
  int& ret = dp[i][last];
  if (ret != -1) return ret;
  int k = all - (i ? pre[i - 1] : 0);
  ret = c(k, x[i]);
  int sum = 0;
  last += x[i];
  for (int j = 0; j <= y[i]; ++j) {
    sum += ((long long)c(last, j) * f(i + 1, last - j)) % mod;
    if (sum >= mod) sum -= mod;
  }
  ret = ((long long)ret * sum) % mod;
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  intialize();
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", x + i);
    all += x[i];
    pre[i] = x[i];
    if (i) pre[i] += pre[i - 1];
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", y + i);
  }
  printf("%d", f());
  return 0;
}
