#include <bits/stdc++.h>
using namespace std;
long long read(long long x = 0) {
  int c, f = 1;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return f * x;
}
long long n, l[300010], r[300010], ans, len[300010], p[300010], suf[300010],
    p2[300010];
long long fastpow(long long a, long long b) {
  long long ans(1), t(a % 1000000007ll);
  for (; b; b >>= 1, t = t * t % 1000000007ll)
    if (b & 1) ans = ans * t % 1000000007ll;
  return ans;
}
long long inv(long long x) { return fastpow(x, 1000000007ll - 2); }
int main() {
  long long i, tmp;
  n = read();
  for (i = 1; i <= n; i++) l[i] = read();
  for (i = 1; i <= n; i++) r[i] = read();
  for (i = 1; i <= n; i++) len[i] = r[i] - l[i] + 1;
  for (i = 2; i <= n; i++)
    p[i] = max(0ll, min(r[i], r[i - 1]) - max(l[i], l[i - 1]) + 1) *
           inv(len[i - 1] * len[i]) % 1000000007ll;
  for (i = 2; i < n; i++) {
    p2[i] = inv(len[i - 1] * len[i] % 1000000007ll * len[i + 1] % 1000000007ll);
    long long L = max(max(l[i - 1], l[i]), l[i + 1]);
    long long R = min(min(r[i - 1], r[i]), r[i + 1]);
    p2[i] = p2[i] * max(R - L + 1, 0ll) % 1000000007ll;
  }
  ans = n * n % 1000000007ll;
  tmp = 0;
  for (i = 2; i <= n; i++) tmp = (tmp + p[i]) % 1000000007ll;
  ans = (ans - 2 * n * tmp) % 1000000007ll;
  tmp = 0;
  for (i = 2; i <= n; i++) tmp = (tmp + p[i]) % 1000000007ll;
  ans = (ans + tmp) % 1000000007ll;
  tmp = 0;
  for (i = 2; i < n; i++) tmp = (tmp + p2[i]) % 1000000007ll;
  ans = (ans + 2 * tmp) % 1000000007ll;
  for (i = n; i; i--) suf[i] = (suf[i + 1] + p[i]) % 1000000007ll;
  tmp = 0;
  for (i = 2; i <= n; i++) tmp = (tmp + p[i] * suf[i + 2]) % 1000000007ll;
  ans = (ans + 2 * tmp) % 1000000007ll;
  cout << (ans + 1000000007ll) % 1000000007ll;
  return 0;
}
