use std::collections::HashSet; use std::process; fn getline() -> String{ let mut __ret=String::new(); std::io::stdin().read_line(&mut __ret).ok(); return __ret; } fn main() { let S=getline(); let S=S.trim(); if S.len() == 1 { print!("{}", -1); process::exit(0); } let rev:String = S.chars().rev().collect(); if S != rev { print!("{}", S.len()); process::exit(0); } if S.len() == 2 { print!("{}", 0); process::exit(0); } if S.len() == 3 { print!("{}", -1); process::exit(0); } let char_set: HashSet<_> = S.chars().collect(); let char_num = char_set.len(); if char_num == 1 { if S.len() % 2 == 0 { print!("{}", 0); process::exit(0); }else { print!("{}", -1); process::exit(0); } } if S.len() % 2 == 0 { print!("{}", S.len() -2); process::exit(0); }else { let mS = format!("{}{}", &S[..S.len()/2], &S[S.len()/2+2..]); let m_char_set: HashSet<_> = mS.chars().collect(); let m_char_num = m_char_set.len(); if m_char_num == 1 { print!("{}", S.len() -2); process::exit(0); }else { print!("{}", S.len() -2); process::exit(0); } } }