Problem: When Petya has free from computer games time, he attends university classes. Every day the lessons on Petya’s faculty consist of two double classes. The floor where the lessons take place is a long corridor with M classrooms numbered from 1 to M, situated along it.

All the students of Petya’s year are divided into N groups. Petya has noticed recently that these groups’ timetable has the following peculiarity: the number of the classroom where the first lesson of a group takes place does not exceed the number of the classroom where the second lesson of this group takes place. 

Once Petya decided to count the number of ways in which one can make a lesson timetable for all these groups. The timetable is a set of 2N numbers: for each group the number of the rooms where the first and the second lessons take place. Unfortunately, he quickly lost the track of his calculations and decided to count only the timetables that satisfy the following conditions:

1) On the first lesson in classroom i exactly Xi groups must be present.

2) In classroom i no more than Yi groups may be placed.

Help Petya count the number of timetables satisfying all those conditionsю As there can be a lot of such timetables, output modulo 109 + 7.

Input

The first line contains one integer M (1 ≤ M ≤ 100) — the number of classrooms.

The second line contains M space-separated integers — Xi (0 ≤ Xi ≤ 100) the amount of groups present in classroom i during the first lesson.

The third line contains M space-separated integers — Yi (0 ≤ Yi ≤ 100) the maximal amount of groups that can be present in classroom i at the same time.

It is guaranteed that all the Xi ≤ Yi, and that the sum of all the Xi is positive and does not exceed 1000.

Output

In the single line output the answer to the problem modulo 109 + 7.

Examples

Input

3
1 1 1
1 2 3


Output

36


Input

3
1 1 1
1 1 1


Output

6

Note

In the second sample test the first and the second lessons of each group must take place in the same classroom, that’s why the timetables will only be different in the rearrangement of the classrooms’ numbers for each group, e.g. 3! = 6.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
const long long MaxN = 105;
const long long MaxAi = 10005;
const long long p = 1e9 + 7;
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
inline long long fpow(long long a, long long b) {
  register long long res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) res = res * a % p;
  return res;
}
struct Cu {
  long long f[MaxAi], inv[MaxAi];
  Cu() {
    f[0] = 1;
    for (long long i = 1; i < MaxAi; ++i) f[i] = f[i - 1] * i % p;
    inv[MaxAi - 1] = fpow(f[MaxAi - 1], p - 2);
    for (long long i = MaxAi - 2; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % p;
  }
  inline long long operator()(const long long &n, const long long &m) const {
    if (!n || n < m) return 0;
    return f[n] * inv[m] % p * inv[n - m] % p;
  }
} C;
long long x[MaxN], y[MaxN], s[MaxN], n;
long long f[MaxN][MaxN * MaxN];
inline void add(long long &x, long long y) { (x += y) >= p && (x -= p); }
signed main(void) {
  read(n);
  for (long long i = 1; i <= n; ++i) read(x[i]), s[i] = s[i - 1] + x[i];
  for (long long i = 1; i <= n; ++i) read(y[i]);
  f[1][0] = 1;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 0; j <= std::min(y[i], s[i]); ++j)
      for (long long k = 0; k <= s[i - 1]; ++k)
        if (k + x[i] >= j)
          add(f[i + 1][k + x[i] - j], f[i][k] * C(k + x[i], j) % p);
  register long long ans = f[n + 1][0] * C.f[s[n]] % p;
  for (long long i = 1; i <= n; ++i) (ans *= C.inv[x[i]]) %= p;
  write(ans), std::puts("");
  return 0;
}