from functools import cache def rolling_hash(s: str): """[l, r] のハッシュを返す関数を返す""" mod = 998244353 p = 1009 n = len(s) t = [ord(c) for c in s] a = [0] * n b = [0] * n a[0] = t[0] b[0] = 1 for i in range(1, n): a[i] = (a[i-1] * p + t[i]) % mod b[i] = (p * b[i-1]) % mod # [l, r] のハッシュ値 def f(l: int, r: int) -> int: assert 0 <= l <= r < n h = a[r] if l > 0: h -= a[l-1] * b[r-l+1] h %= mod return h return f S = input() h = rolling_hash(S) @cache def f(l, r): if l > r: return 0 res = 1 # ひとつの単語は回文 lo = l hi = r while lo < hi: if h(l, lo) == h(hi, r): res += f(lo+1, hi-1) lo += 1 hi -= 1 return res ans = f(0, len(S)-1) print(ans)