#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
ll fast_pow(ll a,ll b,ll m){
ll res=1;
a%=m;
while(b!=0){
if(b&1){
res=(res*a)%m;
}
a=(a*a)%m;
b>>=1;
}
return res;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n;
cin>>n;
ll z=1,m=1;
vector<ll>a(n+1);
for(ll i=1;i<=n;i++){
cin>>a[i];
m=(m*a[i])%mod;
}
for(ll i=1;i<=n;i++){
ll b;
cin>>b;
z=(z*(a[i]-b))%mod;
}
cout<<(1-z*fast_pow(m,mod-2,mod)%mod+mod)%mod;
return 0;
}

京公网安备 11010502036488号