#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::stdin; mod util { use std::io::stdin; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } } #[allow(unused_macros)] macro_rules! get { ($t:ty) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().parse::<$t>().unwrap() } }; ($($t:ty),*) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( $(iter.next().unwrap().parse::<$t>().unwrap(),)* ) } }; ($t:ty; $n:expr) => { (0..$n).map(|_| get!($t) ).collect::>() }; ($($t:ty),*; $n:expr) => { (0..$n).map(|_| get!($($t),*) ).collect::>() }; ($t:ty ;;) => { { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse::<$t>().unwrap()) .collect::>() } }; } #[allow(unused_macros)] macro_rules! debug { ($($a:expr),*) => { println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*); } } struct RollingHash { hash: Vec, pow: Vec, } impl RollingHash { const M: u64 = 1000000007; const B: u64 = 10009; fn new(s: &[u64]) -> RollingHash { let mut hash = Vec::with_capacity(s.len() + 1); let mut pow = Vec::with_capacity(s.len() + 1); hash.push(0); pow.push(1); for (i, &x) in s.iter().enumerate() { let h = hash[i]; let p = pow[i]; hash.push((h + x) * Self::B % Self::M); pow.push(p * Self::B % Self::M); } RollingHash { hash: hash, pow: pow, } } fn get(&self, l: usize, r: usize) -> u64 { (self.hash[r] + Self::M - self.hash[l] * self.pow[r - l] % Self::M) % Self::M } fn len(&self) -> usize { self.hash.len() - 1 } } const M: usize = 1000000007; fn rec(rollig_hash: &RollingHash, i: usize, memo: &mut [Option]) -> usize { if let Some(res) = memo[i] { return res; } let mut sum = 1; for k in 1.. { if i + k > rollig_hash.hash.len() - i - k { break; } if rollig_hash.get(i, i + k) == rollig_hash.get(rollig_hash.len() - i - k, rollig_hash.len() - i) { sum += rec(rollig_hash, i + k, memo); sum %= M; } } memo[i] = Some(sum); sum } fn main() { let s: Vec = util::line().chars().map(|c| c as u64).collect(); let rolling_hash = RollingHash::new(&s); let mut memo = vec![None; s.len()]; println!("{}", rec(&rolling_hash, 0, &mut memo)); // debug!(memo); }