#include <bits/stdc++.h>

#define Chris ""
#define Fast std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
#define File(Chris) if(std::fopen(Chris".inp", "r")){std::freopen(Chris".inp", "r", stdin);std::freopen(Chris".out", "w", stdout);}

template<class X, class Y>bool maximize(X &x, const Y &y){if(x < y){x = y; return true;} else return false;}
template<class X, class Y>bool minimize(X &x, const Y &y){if(x > y){x = y; return true;} else return false;}

static constexpr long long mod = 1e9 + 7;
static constexpr long long INF = (long long) 1e18;
static constexpr int MAXN = (int) 1e5 + 5;

void add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

#define int long long

int n;

long long calc(int x){
    x %= mod;
    long long ans = (x * (x + 1)) >> 1;
    ans %= mod;
    return ans;
}

void Inp(){
    std::cin >> n;
}

void Solve() {
    Inp();
    std::vector<long long> h(n + 1);
    std::vector<long long> w(n + 1);
    std::vector<long long> prefixW(n + 1, 0);
    for (int i = 1; i <= n; ++i) std::cin >> h[i];
    for (int i = 1; i <= n; ++i) {
        std::cin >> w[i];
        prefixW[i] = prefixW[i - 1] + w[i];
    }
    std::vector<int> L(n + 1, 0);
    std::vector<int> R(n + 1, n + 1);
    std::stack<int> st;
    for (int i = 1; i <= n; ++i) {
        while (!st.empty() && h[st.top()] >= h[i]) {
            st.pop();
        }
        if (!st.empty()) L[i] = st.top();
        st.push(i);
    }
    while (!st.empty()) st.pop();
    for (int i = n; i >= 1; --i) {
        while (!st.empty() && h[st.top()] > h[i]) {
            st.pop();
        }
        if (!st.empty()) R[i] = st.top();
        st.push(i);
    }
    long long ans = 0;
    for(int i = 1; i <= n; ++i){
        int l = L[i] + 1;
        int r = R[i] - 1;
        long long vatngangquaI = (calc(prefixW[r] - prefixW[l - 1]) - calc(prefixW[i - 1] - prefixW[l - 1]) - calc(prefixW[r] - prefixW[i])) % mod;
        if(vatngangquaI < 0) vatngangquaI += mod;
        long long contribution = (vatngangquaI * calc(h[i])) % mod;
        ans = (ans + contribution) % mod;
    }
    std::cout << ans << '\n';
    return;
}

signed main() {
    Fast
    File(Chris)

    Solve();

    return 0;
}