#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll mod=1000000007;
ll h[200005],w[200005],pre[200005];
ll C(ll x,ll y){
ll ans=(x*(x+1)/2)%mod;
ll ans1=(y*(y+1)/2)%mod;
ll a=(ans*ans1)%mod;
return a;
}
int main() {_
ll n;
cin>>n;
for(ll i=1;i<=n;i++){
cin>>h[i];
}
h[0]=0;
pre[0]=0;
w[0]=0;
for(ll i=1;i<=n;i++){
cin>>w[i];
pre[i]=(pre[i-1]+w[i])%mod;
}
stack<ll> s;
s.push(0);
ll ans=0;
for(ll i=1;i<=n;i++){
while(s.size()>1 and h[s.top()]>h[i]){
ll x=s.top();
s.pop();
ll y=s.top();
ans+=(C(h[x],pre[i-1]-pre[y])-C(h[y],pre[i-1]-pre[y]))%mod;
ans%=mod;
}
s.push(i);
}
while(s.size()>1){
ll x=s.top();
s.pop();
ll y=s.top();
ans+=(C(h[x],pre[n]-pre[y])-C(h[y],pre[n]-pre[y]))%mod;
ans%=mod;
}
ans%=mod;
cout<<ans;
return 0;
}
//maybe its multiset not set
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHMgc2Vjb25kCiNkZWZpbmUgXyBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CgpsbCBtb2Q9MTAwMDAwMDAwNzsKbGwgaFsyMDAwMDVdLHdbMjAwMDA1XSxwcmVbMjAwMDA1XTsKCmxsIEMobGwgeCxsbCB5KXsKCWxsIGFucz0oeCooeCsxKS8yKSVtb2Q7CglsbCBhbnMxPSh5Kih5KzEpLzIpJW1vZDsKCWxsIGE9KGFucyphbnMxKSVtb2Q7CglyZXR1cm4gYTsKfQoKaW50IG1haW4oKSB7XwoJbG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