#include <bits/stdc++.h>
using namespace std;
long long c[1024][1024] = {0};
long long s[1024] = {0};
long long f[1024][1024];
long long x[1024];
long long y[1024];
long long INF = 1e9 + 7;
int main() {
  c[0][0] = 1;
  for (int i = 1; i < 1024; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % INF;
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    s[i + 1] = s[i] + x[i];
  }
  long long e = 1;
  for (int i = 0; i < n; i++) {
    e = (e * c[s[n] - s[i]][x[i]]) % INF;
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  int z;
  f[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s[i]; j++) {
      z = s[i + 1] - j;
      for (int k = 0; k + j <= s[i + 1] && k <= y[i]; k++) {
        f[i + 1][j + k] = (f[i + 1][j + k] + (c[z][k] * f[i][j]) % INF) % INF;
      }
    }
  }
  cout << ((e * f[n][s[n]]) % INF) << endl;
  return 0;
}
