#include using namespace std; using ll = long long; using vll = vector; using vvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll) (n); i++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N; cin>>N; vector>> T(N); rep(i,N){ cin>>T[i].second.first; } rep(i,N){ cin>>T[i].second.second; T[i].first=double(T[i].second.second-1)/double(T[i].second.first); } sort(all(T)); reverse(all(T)); ll X=1; ll an=0; ll mod=1e9+7; rep(i,N){ an+=X*T[i].second.first; X*=T[i].second.second; an%=mod; X%=mod; } cout<