#[allow(unused)] use proconio::{input, marker::Chars}; use std::collections::{HashSet, VecDeque}; fn main() { input! { s: String, } let mut t = s.chars().collect::<VecDeque<_>>(); let mut h = HashSet::<String>::new(); let mut w = Vec::<char>::new(); println!("{}", new_string(&mut t, &mut h, &mut w)) } fn new_string(t: &mut VecDeque<char>, h: &mut HashSet<String>, w: &mut Vec<char>) -> i64 { if t.is_empty() { let s = w.iter().collect::<String>(); if !h.contains(&s) { h.insert(s); return 1; } else { return 0; } } else { let mut ret = 0; for &top in [true, false].iter() { if top { w.push(t.pop_front().unwrap()); } else { w.push(t.pop_back().unwrap()); } ret += new_string(t, h, w); if top { t.push_front(w.pop().unwrap()); } else { t.push_back(w.pop().unwrap()); } } ret } }