#[allow(unused)] use proconio::{input, marker::Chars}; use std::collections::{HashSet, VecDeque}; fn main() { input! { s: String, } let mut t = s.chars().collect::>(); let mut h = HashSet::::new(); let mut w = Vec::::new(); println!("{}", new_string(&mut t, &mut h, &mut w)) } fn new_string(t: &mut VecDeque, h: &mut HashSet, w: &mut Vec) -> i64 { if t.is_empty() { let s = w.iter().collect::(); 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 } }