#include <bits/stdc++.h>
using namespace std;
const int inf32 = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3f;
const int M = 1e9 + 7;
struct mint {
  int x;
  mint(int x = 0) : x(x) {}
  friend mint operator+(const mint a, const mint &b) {
    int x = a.x + b.x;
    return mint(x >= M ? x - M : x);
  }
  friend mint operator-(const mint a, const mint &b) {
    int x = a.x - b.x;
    return mint(x < 0 ? x + M : x);
  }
  friend mint operator*(const mint a, const mint &b) {
    return mint(1ll * a.x * b.x % M);
  }
};
int Pw(int a, int x = M - 2, int res = 1) {
  for (; x; x >>= 1, a = (mint(a) * a).x)
    if (x & 1) res = (mint(res) * a).x;
  return res;
}
const int N = 2e5 + 1;
int n, lx[N], rx[N], ix[N];
int p[N], sp[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n, ++n;
  lx[0] = -1;
  for (int i = (1); i < (n); ++i) cin >> lx[i], --lx[i];
  for (int i = (1); i < (n); ++i) cin >> rx[i];
  for (int i = (0); i < (n); ++i) ix[i] = Pw(rx[i] - lx[i]);
  int EC = 0;
  for (int i = (1); i < (n); ++i) {
    int l2 = max(lx[i], lx[i - 1]);
    int r2 = min(rx[i], rx[i - 1]);
    p[i] = (mint(ix[i]) * ix[i - 1] * max(0, r2 - l2)).x;
    sp[i] = (mint(sp[i - 1]) + 1 - p[i]).x;
    if (i >= 2) {
      int l3 = max(l2, lx[i - 2]);
      int r3 = min(r2, rx[i - 2]);
      EC = (EC + (1 - mint(p[i])) * sp[i - 2] + 1 - p[i] - p[i - 1] +
            mint(ix[i]) * ix[i - 1] * ix[i - 2] * max(0, r3 - l3))
               .x;
    }
  }
  int res = (sp[n - 1] + mint(2) * EC).x;
  cout << res << '\n';
  return 0;
}
