#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mo = 1e9 + 7;
long long qk(long long x, int y) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % mo;
    x = x * x % mo;
  }
  return r;
}
long long l[N], r[N], ls[N], rs[N];
int main() {
  int n;
  scanf("%d", &n);
  for (auto i = (1); i <= (n); ++i) scanf("%lld", &l[i]);
  for (auto i = (1); i <= (n); ++i) scanf("%lld", &r[i]);
  if (n == 1) return printf("1\n"), 0;
  ls[0] = rs[n + 1] = 1;
  for (auto i = (1); i <= (n); ++i) ls[i] = ls[i - 1] * (r[i] - l[i] + 1) % mo;
  for (auto i = (n); i >= (1); --i) rs[i] = rs[i + 1] * (r[i] - l[i] + 1) % mo;
  long long nw = 0, ans = 0;
  for (auto i = (1); i <= (n); ++i) {
    long long dl = r[i] - l[i] + 1, dr = r[i] - l[i] + 1;
    if (i > 1) {
      long long L = max(l[i], l[i - 1]), R = min(r[i], r[i - 1]);
      dl = (ls[i] + mo - (R < L ? 0 : R - L + 1) * ls[i - 2] % mo) % mo;
    }
    if (i < n) {
      long long L = max(l[i], l[i + 1]), R = min(r[i], r[i + 1]);
      dr = (rs[i] + mo - (R < L ? 0 : R - L + 1) * rs[i + 2] % mo) % mo;
    }
    (ans += nw * dr) %= mo;
    ((nw *= r[i] - l[i] + 1) += dl) %= mo;
    if (i == 1)
      (ans += dr) %= mo;
    else if (i == n)
      (ans += dl) %= mo;
    else {
      long long L = max(max(l[i], l[i - 1]), l[i + 1]),
                R = min(min(r[i], r[i - 1]), r[i + 1]);
      (ans += dl * rs[i + 1] + dr * ls[i - 1] +
              (R < L ? 0 : R - L + 1) * ls[i - 2] % mo * rs[i + 2] + mo -
              ls[n]) %= mo;
    }
  }
  (ans *= 2) %= mo;
  for (auto i = (1); i <= (n); ++i) {
    long long dr = r[i] - l[i] + 1;
    if (i < n) {
      long long L = max(l[i], l[i + 1]), R = min(r[i], r[i + 1]);
      dr = (rs[i] + mo - (R < L ? 0 : R - L + 1) * rs[i + 2] % mo) % mo;
    }
    (ans += mo - dr * ls[i - 1] % mo) %= mo;
  }
  printf("%lld\n", ans * qk(ls[n], mo - 2) % mo);
}
