//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // type DP = [f64; 2]; fn factor(s: &[u8], k: &mut usize, p: &[f64]) -> DP { let c = s[*k]; match c { b'Y' => { *k += 3; [0.0, 1.0] }, b'N' => { *k += 2; [1.0, 0.0] }, b'r' => { *k += 7; let a = exp(s, k, p); let b = exp(s, k, p); *k += 1; let x = a[1] * b[1] * p[0] + (1.0 - a[1] * b[1]) * p[1]; [1.0 - x, x] }, b'(' => { *k += 1; let res = exp(s, k, p); *k += 1; res }, _ => unreachable!(), } } fn term(s: &[u8], k: &mut usize, p: &[f64]) -> DP { let mut res = factor(s, k, p); while *k < s.len() && s[*k] == b'a' { *k += 3; let v = term(s, k, p); let x = res[1] * v[1]; let x = x * (1.0 - p[2]) + (1.0 - x) * p[2]; res = [1.0 - x, x]; } res } fn exp(s: &[u8], k: &mut usize, p: &[f64]) -> DP { let mut res = term(s, k, p); while *k < s.len() && s[*k] == b'o' { *k += 2; let v = term(s, k, p); let x = 1.0 - res[0] * v[0]; let x = x * (1.0 - p[2]) + (1.0 - x) * p[2]; res = [1.0 - x, x]; } res } fn run() { input! { n: usize, p: [f64; 3], s: bytes, } let ans = exp(&s, &mut 0, &p)[1]; println!("{}", (ans * 100.0).floor() as usize); } fn main() { run(); }