#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <iomanip>
#include <set>
#include <bitset>
#define int long long
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using piii = tuple<int,int,int>;
#define endl '\n'
#define f first
#define s second
#define all(x) begin(x),end(x)
int const md = 1e9+7;
int cal(int n,int m){
//cout << n << " " << m << endl;
int n2;
int m2;
if(n%2) n2 = (((n)%md)*(((n+1)/2)%md))%md;
else n2 = (((n/2)%md)*((n+1)%md))%md;
if(m%2) m2 = (((m)%md)*(((m+1)/2)%md))%md;
else m2 = (((m/2)%md)*((m+1)%md))%md;
return (n2*m2)%md;
}
signed main(){
int n;cin >> n;
vector<pii> vc(n);
for(int i{};i < n;i++){
cin >> vc[i].f;
}
for(int i{};i < n;i++){
cin >> vc[i].s;
}
vc.emplace_back(0,0);
stack<piii> mono;//start, end, hight
int ans = 0;
mono.emplace(0,0,0);
for(int i{};i <= n;i++){
auto [h,w] = vc[i];
while(get<2>(mono.top()) > h){
auto [stt,edt,ht] = mono.top();mono.pop();
auto [stnt,ednt,hnt] = mono.top();
ans = (ans+cal(edt-stt,ht))%md;
ans = (ans-cal(edt-stt,hnt)+md)%md;
if(hnt != 0) mono.top() = {stnt,edt,hnt};
}
mono.emplace(get<1>(mono.top()),get<1>(mono.top())+w,h);
}
cout << ans%md;
}