#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