#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 1e9 + 10;   const ll inf_ll = 1e18 + 10;   template <ll M>   struct modint {     static ll reduce(ll n) {       constexpr static ll b = -1ull / M;       ll r = n - (ll)(__uint128_t(b) * n >> 64) * M;       return r >= M ? r - M : r;     }     static ll inv(ll n) {       ll r = 1;       for (ll k = M - 2; k > 0; k >>= 1, n = reduce(n * n))         if (k & 1) r = reduce(r * n);       return r;     }     ll v;     modint(ll n = 0) : v(reduce(n)) { v += (M & 0 - (v < 0)); }     friend string to_string(const modint n) { return to_string(n.v); }     friend istream& operator>>(istream& i, modint& n) { return i >> n.v; }     friend ostream& operator<<(ostream& o, const modint n) { return o << n.v; }     template <typename T>     explicit operator T() {       return T(v);     }     friend bool operator==(const modint n, const modint m) { return n.v == m.v; }     friend bool operator!=(const modint n, const modint m) { return n.v != m.v; }     friend bool operator<(const modint n, const modint m) { return n.v < m.v; }     friend bool operator<=(const modint n, const modint m) { return n.v <= m.v; }     friend bool operator>(const modint n, const modint m) { return n.v > m.v; }     friend bool operator>=(const modint n, const modint m) { return n.v >= m.v; }     modint& operator+=(const modint n) {       v += n.v;       v -= (M & 0 - (v >= M));       return *this;     }     modint& operator-=(const modint n) {       v -= n.v;       v += (M & 0 - (v < 0));       return *this;     }     modint& operator*=(const modint n) {       v = reduce(v * n.v);       return *this;     }     modint& operator/=(const modint n) {       v = reduce(v * inv(n.v));       return *this;     }     friend modint operator+(const modint n, const modint m) {       return modint(n) += m;     }     friend modint operator-(const modint n, const modint m) {       return modint(n) -= m;     }     friend modint operator*(const modint n, const modint m) {       return modint(n) *= m;     }     friend modint operator/(const modint n, const modint m) {       return modint(n) /= m;     }     modint& operator++() { return *this += 1; }     modint& operator--() { return *this -= 1; }     modint operator++(int) {       modint t = *this;       return *this += 1, t;     }     modint operator--(int) {       modint t = *this;       return *this -= 1, t;     }     modint operator+() { return *this; }     modint operator-() { return modint(0) -= *this; }     modint pow(const ll k) const {       if (k < 1) return k == 0 ? modint(1) : modint(inv(this->v)).pow(-k);       return k & 1 ? *this * (this->pow(k - 1)) : (*this * *this).pow(k >> 1);     }   };   using mod = modint<int(1e9 + 7)>;   const int N = 2e5 + 5;   ll l[N], r[N];   mod p[N], w[N], s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ll n;     cin >> n;     mod ans = n * 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++) w[i] = r[i] - l[i] + 1;     for (int i = 0; i < n - 1; i++) {       p[i] = mod(max(0ll, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1)) /              (w[i] * w[i + 1]);       if (i >= 2) s += p[i - 2];       ans += p[i] * (2 * s + 1 - 2 * n);     }     for (int i = 0; i < n - 2; i++) {       mod x = mod(max(0ll, min({r[i], r[i + 1], r[i + 2]}) -                                max({l[i], l[i + 1], l[i + 2]}) + 1)) /               (w[i] * w[i + 1] * w[i + 2]);       ans += 2 * x;     }     cout << ans <<   n ;   }