#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int sum(int a, int b) {
  int s = a + b;
  if (s > mod) return s - mod;
  return s;
}
int sub(int a, int b) {
  int s = a - b;
  if (s < 0) return s + mod;
  return s;
}
int mult(int a, int b) { return (1LL * a * b % mod); }
int power(int a, int b) {
  if (b == 0) return 1;
  int res = power(a, b / 2);
  res = mult(res, res);
  if (b & 1) return mult(a, res);
  return res;
}
int inv(int a) { return power(a, mod - 2); }
int n;
int l[maxn], r[maxn], prob[maxn], E[maxn];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> r[i];
    prob[i] = inv(r[i] - l[i] + 1);
  }
  int tot = 0, t2 = 0;
  for (int i = 1; i < n; i++) {
    int cur = max(0, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1);
    E[i] = sub(1, mult(cur, mult(prob[i], prob[i + 1])));
    tot = sum(tot, E[i]);
    t2 = sum(t2, mult(E[i], E[i]));
  }
  int ans = sum(1, sub(sum(mult(3, tot), mult(tot, tot)), t2));
  for (int i = 1; i < n - 1; i++) {
    int cur = max(0, min({r[i], r[i + 1], r[i + 2]}) -
                         max({l[i], l[i + 1], l[i + 2]}) + 1);
    int cur_p_00 = mult(cur, mult(prob[i], mult(prob[i + 1], prob[i + 2])));
    int cur_p_11 = sub(sum(E[i], E[i + 1]), sub(1, cur_p_00));
    ans = sum(ans, mult(2, sub(cur_p_11, mult(E[i], E[i + 1]))));
  }
  cout << ans << endl;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  solve();
}
