use std::io::*; use std::str::FromStr; fn main() { exec(read()); } fn exec(a: String) { println!("{}", answer_count(a.chars().collect())); } fn answer_count(mut r: Vec) -> i64 { let first_cww_char = 'c'; for (i, v) in r.iter().enumerate() { if v == &first_cww_char { let c_head_arr: Vec = r.drain(i..).collect(); return count_cww(c_head_arr); } } -1 } fn count_cww(mut r: Vec) -> i64 { let mut acc: Vec = vec![]; let c = r.remove(0); acc.push(c); let count = 1; rec_cww(r, acc, count) } fn rec_cww(mut r: Vec, mut acc: Vec, c: i64) -> i64 { if &acc.len() == &3 { return c; } if r.is_empty() { return -1; } let head = r.remove(0); let c = c + 1; if head == 'w' { acc.push(head); } rec_cww(r, acc, c) } fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") }