//ojou kawayo no.1
#include <bits/stdc++.h>
using namespace std;
#define tsk "FancyFence"
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define Ningen_sama signed
#define tachi main()
#define __builtin_popcount __builtin_popcountll
#define el cout<<'\n'
#define all(a) a.begin(),a.end()
#define invAll(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define BIT(x, k) (1ll&((x) >> (k)))
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << " = " << x << '\n'
#define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define FORD(i, l, r) for(int i = (l); i >= (r); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define int long long
template<class T> bool maximize(T& u, T v){if(u >= v) return false;return u = v, true;}
template<class T> bool minimize(T& u, T v){if(u <= v) return false;return u = v, true;}
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vpii = vector<pair<int, int>>;
#define inf32 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
const int maxn = 1e6+5;
const int N = 5e3 + 5;
const int base = 31;
const ll mod = 1e9 + 7;
const ll need = 67108863;
const int vc = 2e9 + 1;
const ll INF18 = 4557430888798830399;
const ll LOG = 20;
const double eps = 1e-9;
const int BLOCK = 447;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
#define rand rd
inline long long Rand(long long L, long long R) {
if(L>R) return 0;
return L + rd() % (R - L + 1);
}
inline ll add(ll x, ll y){x+=y;if(x>=mod) x-=mod;if(x<0) x+=mod;return x;}
inline ll mult(ll x, ll y){return 1LL * x * y % mod;}
ll calPow(ll a, ll b){
ll s = 1;
while(b){
if(b & 1) s = s * a % mod;
a = a * a % mod;
b >>= 1;
}
return s;
}
int n;
int w[maxn], h[maxn];
int r, c;
inline void init(){
}
inline void input(){
cin >> n;
FOR(i, 1, n) cin >> h[i];
FOR(i, 1, n) cin >> w[i], c += w[i];
}
inline void solve(){
// cout << calPow(2, mod - 2); el;
r = h[1];
// cout << r << " " << c; el;
ll res = 0;
c %= mod;
int tmp = min(r, c);
FOR(i, 1, tmp){
// cout << r << " " << c << " " << res; el;
res = add(res, r * c % mod);
res = add(res, r * (c * (c - 1) % mod * 500000004 % mod) % mod);
res = add(res, c * (r * (r - 1) % mod * 500000004 % mod) % mod);
r--, c--;
}
cout << res;
}
Ningen_sama tachi{
//konnakiri~~
if(fopen(tsk".inp","r")){
freopen(tsk".inp","r",stdin);
freopen(tsk".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int Yodayo = 1;
//cin >> Yodayo;
//init();
while(Yodayo--){
input();
solve();
}
//execute;
}
//otsunakiri~~