#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N;
int L[200005];
int R[200005];
long long inv[200005];
long long Y[200005];
long long expo(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b % 2 == 0) return expo(a * a % MOD, b / 2);
  return a * expo(a * a % MOD, (b - 1) / 2) % MOD;
}
pair<long long, long long> intersect(int a1, int a2, int b1, int b2) {
  if (a2 < b1 || b2 < a1) return make_pair(1, 0);
  return make_pair(max(a1, b1), min(a2, b2));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> L[i];
  for (int i = 0; i < N; i++) cin >> R[i];
  for (int i = 0; i < N; i++) inv[i] = expo(R[i] - L[i] + 1, MOD - 2);
  long long ans = 1;
  for (int i = 1; i < N; i++) {
    pair<long long, long long> cur = intersect(L[i - 1], R[i - 1], L[i], R[i]);
    Y[i] = cur.second - cur.first + 1;
    Y[i] = Y[i] * inv[i - 1] % MOD;
    Y[i] = Y[i] * inv[i] % MOD;
    Y[i] = (1 - Y[i]) % MOD;
    ans = (ans + 3 * Y[i] % MOD) % MOD;
  }
  for (int i = 2; i < N; i++) {
    pair<long long, long long> cur = intersect(L[i - 1], R[i - 1], L[i], R[i]);
    cur = intersect(L[i - 2], R[i - 2], cur.first, cur.second);
    long long equal = 0;
    equal = cur.second - cur.first + 1;
    equal = equal * inv[i - 2] % MOD;
    equal = equal * inv[i - 1] % MOD;
    equal = equal * inv[i] % MOD;
    long long prob = (1 - (1 - Y[i]) - (1 - Y[i - 1]) + equal) % MOD;
    ans = (ans + 2 * prob % MOD) % MOD;
  }
  long long sum = 0;
  for (int i = 1; i < N; i++) sum = (sum + Y[i]) % MOD;
  ans = (ans + sum * sum % MOD) % MOD;
  for (int i = 1; i < N; i++) ans = (ans - Y[i] * Y[i] % MOD) % MOD;
  for (int i = 2; i < N; i++) ans = (ans - 2 * Y[i] * Y[i - 1] % MOD) % MOD;
  if (ans < 0) ans += MOD;
  cout << ans << "\n";
  return 0;
}
