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 power_mat(target: &Vec>, times: usize) -> Vec> { let n = target.len(); if times == 0 { let mut ret = vec![vec![0usize; n]; n]; for i in 0..n { ret[i][i] = 1; } return ret; } if times == 1 { return target.clone(); } let temp = power_mat(target, times/2); if times % 2 == 1 { calc_mat(&calc_mat(&temp, &temp), target) } else { calc_mat(&temp, &temp) } } fn calc_mat(left: &Vec>, right: &Vec>) -> Vec> { let sizei = left.len(); let sizej = right[0].len(); let sizek = left[0].len(); let mut ret = vec![vec![0usize; sizej]; sizei]; for i in 0..sizei { for j in 0..sizej { ret[i][j] = (0..sizek).map(|k| left[i][k] * right[k][j] % MOD).sum::() % MOD; } } ret } fn main() { 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(); let n = temp[0]; let m = temp[1]; let k = temp[2]; let p = temp[3]; let q = temp[4]; let b = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: usize = temp.trim().parse().unwrap(); temp }) .collect::>(); let prob = p * power(q, MOD-2) % MOD; let revp = (MOD + 1 - prob) % MOD; let mat = vec![vec![revp, prob], vec![prob, revp]]; let mat = power_mat(&mat, k); let mut result = 0usize; for i in 0..n { if i < m { result += mat[0][0] * b[i] % MOD; } else { result += mat[1][0] * b[i] % MOD; } result %= MOD; } println!("{}", result); }