#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long pw(long long a, long long t = mod - 2) {
  long long x = 1;
  while (t > 0) {
    if (t & 1) x = x * a % mod;
    a = a * a % mod, t /= 2;
  }
  return x;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long n;
  cin >> n;
  long long l[n], r[n];
  for (long long i = 0; i < n; i++) cin >> l[i];
  for (long long i = 0; i < n; i++) {
    cin >> r[i];
    r[i]++;
  }
  long long x = 1, ls = 1, ans = -1;
  for (long long i = 1; i < n; i++) {
    long long in = max(0ll, min(r[i], r[i - 1]) - max(l[i], l[i - 1]));
    long long p =
        pw(r[i] - l[i]) % mod * in % mod * pw(r[i - 1] - l[i - 1]) % mod;
    p = (1 - p + mod) % mod;
    x = (x + p) % mod, ans = (ans + mod - p * p % mod) % mod;
    if (i > 1) {
      ans = (ans + mod - 2 * ls * p % mod) % mod;
      in = max(0ll, min({r[i], r[i - 1], r[i - 2]}) -
                        max({l[i], l[i - 1], l[i - 2]}));
      long long q = in * pw(r[i] - l[i]) % mod * pw(r[i - 1] - l[i - 1]) % mod *
                    pw(r[i - 2] - l[i - 2]) % mod;
      ans = (ans + 2 * (q + p - 1 + ls + mod) % mod) % mod;
    }
    ls = p;
  }
  ans = (x * x % mod + x + ans) % mod;
  cout << ans;
}
