#include <bits/stdc++.h>
const int maxn = 1e6 + 9, mod = 1e9 + 7;
inline int Read() {
  int x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3ll) + (x << 1ll) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, ans, sum;
int l[maxn], r[maxn], q[maxn], E[maxn];
inline int Pow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1LL * a * a % mod)
    if (b & 1) res = 1LL * res * a % mod;
  return res;
}
inline int P(int x, int y, int z) {
  int L(std::max(l[x], std::max(l[y], l[z]))),
      R(std::min(r[x], std::min(r[y], r[z])));
  return std::max(0ll, 1ll * (R - L) *
                           Pow(1ll * (r[x] - l[x]) * (r[y] - l[y]) % mod *
                                   (r[z] - l[z]) % mod,
                               mod - 2) %
                           mod);
}
inline int Calc(int x) {
  int y(x + 1), ret(0);
  if (x > 1) ret = P(x - 1, x, y);
  return ((1ll - 1ll * (q[x] + q[y]) % mod + mod) % mod + ret) % mod;
}
int main() {
  n = Read();
  for (int i = 1; i <= n; ++i) {
    l[i] = Read();
  }
  for (int i = 1; i <= n; ++i) {
    r[i] = Read() + 1;
    int R(std::min(r[i], r[i - 1])), L(std::max(l[i], l[i - 1]));
    q[i] = std::max(
        0ll,
        1ll * (R - L) *
            Pow(1ll * (r[i - 1] - l[i - 1]) * (r[i] - l[i]) % mod, mod - 2) %
            mod);
    E[i] = 1ll * (1 - q[i] + mod) % mod;
    sum = 1ll * (sum + E[i]) % mod;
  }
  for (int i = 1; i <= n; ++i) {
    int tmp(sum);
    for (int j = std::max(1, i - 1); j <= std::min(n, i + 1); ++j)
      tmp = 1ll * (tmp - E[j] + mod) % mod;
    ans = 1ll * (ans + 1ll * E[i] * tmp % mod) % mod;
    if (i > 1) ans = 1ll * (ans + Calc(i - 1)) % mod;
    if (i < n) ans = 1ll * (ans + Calc(i)) % mod;
    ans = 1ll * (ans + E[i]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
