#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long qpow(long long a, long long n) {
  long long ans = 1;
  for (; n; n >>= 1, a = a * a % mod)
    if (n & 1) ans = ans * a % mod;
  return ans;
}
long long mul(long long a, long long b) { return a * b % mod; }
long long dv(long long a, long long b) { return mul(a, qpow(b, mod - 2)); }
const long long N = 2e5 + 10;
long long n;
long long I[N], l[N], r[N], p[N], q[N];
long long min(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
long long max(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long aeqbeqc(long long i, long long j, long long k) {
  if (min(r[i], r[j], r[k]) < max(l[i], l[j], l[k])) return 0;
  return dv(min(r[i], r[j], r[k]) - max(l[i], l[j], l[k]) + 1,
            mul(r[i] - l[i] + 1, mul(r[j] - l[j] + 1, r[k] - l[k] + 1)));
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> l[i];
  for (long long i = 1; i <= n; i++) cin >> r[i];
  for (long long i = 1; i <= n; i++) {
    if (min(r[i], r[i - 1]) < max(l[i], l[i - 1]))
      q[i] = 0;
    else
      q[i] = dv(min(r[i], r[i - 1]) - max(l[i], l[i - 1]) + 1,
                mul(r[i - 1] - l[i - 1] + 1, r[i] - l[i] + 1));
    p[i] = (1 - q[i] + mod) % mod;
  }
  long long ans = 0;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) sum = (sum + p[i]) % mod;
  for (long long i = 1; i <= n; i++)
    ans =
        (ans + mul(p[i], sum - p[i] + mod - p[i - 1] + mod - p[i + 1] + mod)) %
        mod;
  ans = (ans + sum) % mod;
  for (long long i = 1; i <= n - 1; i++) {
    long long tmp =
        (1 - q[i] - q[i + 1] + 2 * mod + aeqbeqc(i - 1, i, i + 1)) % mod;
    ans = (ans + tmp + tmp) % mod;
  }
  cout << ans << endl;
}
