use proconio::input; fn main() { input! { n:usize, a:[usize;n], b:[usize;n], } let mut c = (0..n) .map(|i| ((b[i] - 1) as f64 / a[i] as f64, i)) .collect::>(); c.sort_by(|x, y| y.0.partial_cmp(&x.0).unwrap()); let mut ans = 0; let mut level = 1; for &(_, id) in c.iter() { ans += level * a[id]; ans %= MOD; level *= b[id]; level %= MOD; } println!("{}", ans); } const MOD: usize = 1000000007;