use std::io::*; use std::str::FromStr; fn main() { exec(read()); } fn exec(a: String) { println!("{}", all_c_count(a.chars().collect())); } fn all_c_count(r: Vec) -> i64 { let first_cww_char = 'c'; let mut cww_list: Vec = vec![]; for (i, v) in r.iter().enumerate() { if v == &first_cww_char { let c_head_arr: Vec = r.clone().drain(i..).collect(); cww_list.push(count_cww(c_head_arr)); } } let mut ans: Vec = cww_list.iter().filter(|&x| x != &-1).cloned().collect(); if ans.is_empty() { return -1; } ans.sort(); ans[0] } 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") }