#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int mod = 1e9 + 7;
long long ksm(long long a, long long k) {
  a %= mod;
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * a % mod;
    a = a * a % mod;
    k >>= 1;
  }
  return ans;
}
int l[N], r[N], q[N], p[N];
long long cal(int i) {
  long long fm = ksm(1LL * (r[i - 1] - l[i - 1]) * (r[i] - l[i]) % mod *
                         (r[i + 1] - l[i + 1]) % mod,
                     mod - 2);
  long long fz = max(0, min(r[i - 1], min(r[i], r[i + 1])) -
                            max(l[i - 1], max(l[i], l[i + 1])));
  return fz * fm % mod;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &l[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &r[i]), ++r[i];
  for (int i = 2; i <= n; ++i)
    q[i] = 1LL * max(0, min(r[i], r[i - 1]) - max(l[i], l[i - 1])) *
           ksm(1LL * (r[i] - l[i]) * (r[i - 1] - l[i - 1]), mod - 2) % mod;
  long long ans = 0, s = 0;
  for (int i = 1; i <= n; ++i) p[i] = 1 - q[i], s += p[i];
  s %= mod;
  for (int i = 1; i <= n; ++i) {
    ans += p[i];
    long long t = s - p[i];
    if (i > 1) t -= p[i - 1], ans += 1 - q[i - 1] - q[i] + cal(i - 1);
    if (i < n) t -= p[i + 1], ans += 1 - q[i] - q[i + 1] + cal(i);
    ans += t * p[i] % mod;
  }
  printf("%lld\n", (ans % mod + mod) % mod);
  return 0;
}
