const MOD: usize = 1e9 as usize + 7; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } fn main() { let mut l = String::new(); std::io::stdin().read_line(&mut l).ok(); let l: usize = l.trim().parse().unwrap(); let factors = (0..l).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1]) }) .collect::>(); let mut result = 1usize; for &(p, e) in factors.iter() { let modval = power(p-1, MOD-2); let pe1 = power(p, e+1); result *= (MOD + pe1 - e - 2 + (MOD + pe1 - 1) * modval % MOD) % MOD * modval % MOD; result %= MOD; } println!("{}", result); }