#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){
return (((n*(n+1))/2)%md)*(((m*(m+1))/2)%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 [w,h] = vc[i];
int ed = get<1>(mono.top());
while(get<2>(mono.top()) > h){
auto [stt,edt,ht] = mono.top();mono.pop();
ans = (ans+cal((ed-stt)%md,ht))%md;
ans = (ans-cal((ed-get<1>(mono.top()))%md,get<2>(mono.top())));
}
mono.emplace(get<1>(mono.top()),get<1>(mono.top())+w,h);
}
cout << ans;
}