#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; template (1000000007), HashType mod2 = static_cast(1000000009), HashType add1 = static_cast(1000010007), HashType add2 = static_cast(1003333331)> class RollingHash { public: static constexpr HashType MOD1 = mod1; static constexpr HashType MOD2 = mod2; using T = HashType; RollingHash(const Container& original) : size(original.size()), mt{random_device{}()}, base1{getRand1()}, base2{getRand2()}, pow1(size + 1, 1), pow2(size + 1, 1), accum_hash1(size + 1, 0), accum_hash2(size + 1, 0) { for (int i = 1; i <= size; i++) { pow1[i] = (pow1[i - 1] * base1) % mod1; accum_hash1[i] = (accum_hash1[i - 1] * base1 + add1 + static_cast(original[i - 1])) % mod1; } for (int i = 1; i <= size; i++) { pow2[i] = (pow2[i - 1] * base2) % mod2; accum_hash2[i] = (accum_hash2[i - 1] * base2 + add2 + static_cast(original[i - 1])) % mod2; } } pair getHash(const int l, const int r) const // [l,r) { const T h1 = (((accum_hash1[r] - accum_hash1[l] * pow1[r - l]) % mod1) + mod1) % mod1; const T h2 = (((accum_hash2[r] - accum_hash2[l] * pow2[r - l]) % mod2) + mod2) % mod2; return make_pair(h1, h2); } private: T getRand1() { static T value = 0; static uniform_int_distribution dist{2, mod1 - 1}; if (value == 0) { value = dist(mt); } return value; } T getRand2() { static T value = 0; static uniform_int_distribution dist{2, mod2 - 1}; if (value == 0) { value = dist(mt); } return value; } const int size; mt19937 mt; const T base1; const T base2; vector pow1; vector pow2; vector accum_hash1; vector accum_hash2; }; map mp; ll rec(const string& s, const int l, const string& s1, const RollingHash& hash) { cerr << l << " " << s1 << endl; if (mp.find(s1) != mp.end()) { return mp[s1]; } ll sum = 1; for (int i = 1; 2 * (l + i) < s.size() + 1; i++) { if (hash.getHash(l, l + i) == hash.getHash(s.size() - l - i, s.size() - l)) { const ll v = rec(s, l + i, s.substr(l + i, s.size() - l - i - l - i), hash); // show(v); sum += v; } } mp[s1] = sum; return sum; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; // mp[""] = 1; RollingHash hash(s); cout << rec(s, 0, s, hash) << endl; return 0; }