#include <bits/stdc++.h>
using namespace std;
const int md = int(1e9) + 7;
int mul(int a, int b) {
return 1LL * a * b % md;
}
void add(int& a, int b) {
a += b;
if (a >= md) a -= md;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
auto c = a;
c.insert(c.end(), b.begin(), b.end());
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
int ans = 0;
vector dpL(n + 2, vector<int>(3)), dpR = dpL;
for (int x : c) {
dpL[0][0] = 1;
for (int i = 0; i < n; i++) {
dpL[i + 1][0] = dpL[i + 1][1] = dpL[i + 1][2] = 0;
for (int y : {a[i + 1], b[i + 1]}) {
if (x > y) {
add(dpL[i + 1][0], dpL[i][0]);
add(dpL[i + 1][1], dpL[i][1]);
add(dpL[i + 1][2], dpL[i][2]);
} else if (y == x) {
add(dpL[i + 1][1], dpL[i][0]);
add(dpL[i + 1][1], dpL[i][1]);
add(dpL[i + 1][2], dpL[i][2]);
} else {
add(dpL[i + 1][2], dpL[i][0]);
add(dpL[i + 1][2], dpL[i][1]);
add(dpL[i + 1][2], dpL[i][2]);
}
}
}
dpR[n + 1][0] = 1;
for (int i = n + 1; i >= 1; i--) {
dpR[i - 1][0] = dpR[i - 1][1] = dpR[i - 1][2] = 0;
for (int y : {a[i - 1], b[i - 1]}) {
if (x > y) {
add(dpR[i - 1][0], dpR[i][0]);
add(dpR[i - 1][1], dpR[i][1]);
add(dpR[i - 1][2], dpR[i][2]);
} else if (y == x) {
add(dpR[i - 1][1], dpR[i][0]);
add(dpR[i - 1][1], dpR[i][1]);
add(dpR[i - 1][2], dpR[i][2]);
} else {
add(dpR[i - 1][2], dpR[i][0]);
add(dpR[i - 1][2], dpR[i][1]);
add(dpR[i - 1][2], dpR[i][2]);
}
}
}
for (int i = 1; i <= n; i++) {
int res = 0;
add(res, mul(dpL[i - 1][1], dpR[i + 1][1]));
add(res, mul(dpL[i - 1][2], dpR[i + 1][1]));
add(res, mul(dpL[i - 1][1], dpR[i + 1][2]));
add(ans, mul(max(0, x - a[i]), res));
add(ans, mul(max(0, x - b[i]), res));
}
}
cout << ans << '\n';
return 0;
}