#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> l((size_t)n), r((size_t)n);
  for (long long i = 0; i < n; i++) {
    cin >> l[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> r[i];
  }
  auto m = [&](long long x) {
    return (x % 1000000007 + 1000000007) % 1000000007;
  };
  function<long long(long long, long long)> power = [&](long long x,
                                                        long long y) {
    if (y == 0) {
      return (long long)1;
    } else {
      long long z = power(x, y / 2);
      return y % 2 == 0 ? m(z * z) : m(m(z * z) * x);
    }
  };
  auto div = [&](long long x) { return power(x, 1000000007 - 2); };
  vector<long long> q((size_t)n, 0);
  for (long long i = 1; i < n; i++) {
    q[i] =
        m(m(max(min(r[i - 1], r[i]) - max(l[i - 1], l[i]) + 1, (long long)0) *
            div(r[i - 1] - l[i - 1] + 1)) *
          div(r[i] - l[i] + 1));
  }
  vector<long long> p((size_t)n);
  for (long long i = 0; i < n; i++) {
    p[i] = m(1 - q[i]);
  }
  vector<long long> g((size_t)n, 1);
  for (long long i = 0; i < n - 1; i++) {
    g[i] = m(1 - q[i] - q[i + 1] +
             (i == 0 ? 0
                     : m(m(m(max(min({r[i - 1], r[i], r[i + 1]}) -
                                     max({l[i - 1], l[i], l[i + 1]}) + 1,
                                 (long long)0) *
                             div(r[i - 1] - l[i - 1] + 1)) *
                           div(r[i] - l[i] + 1)) *
                         div(r[i + 1] - l[i + 1] + 1))));
  }
  long long h = 0;
  for (long long i = 0; i < n; i++) {
    h += p[i];
    h = m(h);
  }
  long long o = 0;
  for (long long i = 0; i < n; i++) {
    o += m(p[i] +
           m(p[i] * m(h - (i == 0 ? 0 : p[i - 1]) - p[i] -
                      (i == n - 1 ? 0 : p[i + 1]))) +
           (i == 0 ? 0 : g[i - 1]) + (i == n - 1 ? 0 : g[i]));
    o = m(o);
  }
  cout << o << endl;
  return 0;
}
