#include using namespace std; using ll = long long; using P = pair; int main () { int N; cin >> N; vector

A(N); for (auto& [a, b] : A) { cin >> a; } for (auto& [a, b] : A) { cin >> b; } sort(A.begin(), A.end(), [](P a, P b) {return a.first + a.second * b.first > b.first + b.second * a.first;}); ll ans = 0; ll m = 1e9 + 7; ll now = 1; for (auto [a, b] : A) { ans += a * now; ans %= m; now *= b; now %= m; } cout << ans << endl; }