#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
void gcdE(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    gcdE(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long inv(long long a, long long n) {
  long long d, x, y;
  gcdE(a, n, d, x, y);
  return d == 1 ? (x + n) % n : -1;
}
int n;
vector<long long> l, r;
vector<long long> d;
vector<long long> ind;
long long get(int lp, int rp) {
  long long lb = 0;
  long long ub = 1000000001;
  long long b = 1;
  for (int i = lp; i <= rp; i++) {
    lb = max(lb, l[i]);
    ub = min(ub, r[i]);
    b *= ind[i];
    b %= mod;
  }
  long long g = max(ub - lb + 1, 0LL);
  return g * b % mod;
}
int main() {
  cin >> n;
  l.assign(n, 0);
  r.assign(n, 0);
  d.assign(n, 0);
  ind = d;
  for (int i = 0; i < n; i++) scanf("%lld", &l[i]);
  for (int i = 0; i < n; i++) scanf("%lld", &r[i]);
  for (int i = 0; i < n; i++) d[i] = r[i] - l[i] + 1;
  for (int i = 0; i < n; i++) ind[i] = inv(d[i], mod);
  vector<long long> pre(n, 0);
  long long s1 = 0;
  long long s3 = 0;
  for (int i = 1; i < n; i++) {
    pre[i] = get(i - 1, i);
    s1 += pre[i];
    if (i - 2 >= 0) s3 += pre[i] * pre[i - 2] % mod;
    pre[i] += pre[i - 1];
    pre[i] %= mod;
  }
  s1 %= mod;
  s3 %= mod;
  long long s2 = 0;
  for (int i = 2; i < n; i++) s2 += get(i - 2, i);
  s2 %= mod;
  long long ans = 1LL * n * n % mod;
  ans += mod - 2LL * n * s1 % mod;
  ans += s1;
  ans += 2LL * s2;
  ans += 2LL * s3;
  cout << ans % mod << endl;
  return 0;
}
