#include using namespace std; constexpr int mod = 1000000007; bool flag(paira,pairb) { if(1ll*b.second*a.first+b.first < 1ll*a.second*b.first+a.first) { return true; } return false; } int main() { int N; cin >> N; vectorA(N),B(N); vector>tmp(N); for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; tmp[i] = {A[i],B[i]}; } sort(tmp.begin(),tmp.end(),flag); long long ans = 0,x = 1; for(int i = 0; i < N; i++) { ans += x*tmp[i].first%mod; ans %= mod; x *= tmp[i].second; x %= mod; } cout << ans << endl; }