#include <bits/stdc++.h>
using namespace std;
int n;
long long l[200005], r[200005], f[200005], f1[200005], ans;
void ex_gcd(long long &x, long long &y, int a, int b) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  ex_gcd(x, y, b, a % b);
  int c = y;
  y = (-(a / b) * y + x) % 1000000007;
  x = c;
}
int cal(long long a, long long b) {
  if (a <= 0) return 0;
  long long x, y;
  a %= 1000000007, b %= 1000000007;
  ex_gcd(x, y, b, 1000000007);
  return a * x % 1000000007;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", l + i);
  for (int i = 1; i <= n; i++) scanf("%d", r + i), r[i]++;
  r[0] = 1;
  for (int i = 2; i <= n; i++) {
    if (min(r[i], r[i - 1]) > max(l[i], l[i - 1]))
      f[i] = cal(min(r[i], r[i - 1]) - max(l[i], l[i - 1]),
                 (r[i] - l[i]) * (r[i - 1] - l[i - 1]));
  }
  for (int i = 1; i < n; i++) {
    f1[i] = 1 - f[i] - f[i + 1] +
            cal(min(r[i], min(r[i + 1], r[i - 1])) -
                    max(l[i], max(l[i + 1], l[i - 1])),
                ((r[i] - l[i]) * (r[i + 1] - l[i + 1]) % 1000000007) *
                    (r[i - 1] - l[i - 1]));
    (ans += f1[i] * 2) %= 1000000007;
  }
  l[0] = l[1] = r[n + 1] = r[n + 2] = 0;
  for (int i = 1; i <= n; i++)
    f[i] = (1 - f[i]) % 1000000007, l[i] = (l[i - 1] + f[i]) % 1000000007;
  for (int i = n; i; i--) r[i] = (r[i + 1] + f[i]) % 1000000007;
  for (int i = 1; i <= n; i++) {
    (ans += f[i] * (1 + ((i > 2) ? l[i - 2] : 0) + r[i + 2])) %= 1000000007;
  }
  printf("%d", (ans + 1000000007) % 1000000007);
  return 0;
}
