import java.util.*;

public class Main{
    static final long mod = 1000000007;
    static long qpower(long x, long y){
        long res = 1;
        for(; y > 0; x = x*x%mod, y >>= 1){
            if((y & 1) != 0)
                res = res * x % mod;
        }
        return res;
    }
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] a = new long[n+5];
        long[] b = new long[n+5];
        for(int i = 1; i <= n; i++) a[i] = in.nextLong();
        for(int i = 1; i <= n; i++) b[i] = in.nextLong();
        long p = 1;
        for(int i = 1; i <= n; i++){
            p = p * (a[i] - b[i]) % mod;
            p = p * qpower(a[i], mod - 2) % mod;
            //System.out.println(x + " " + y);
        }
        System.out.println((1 - p + mod) % mod);
        //System.out.println(x + " " + y);
    }
}