#if !__INCLUDE_LEVEL__ #include __FILE__ class ModIntMersenne61 { static const long long md = (1LL << 61) - 1; long long _v; inline unsigned hi() const noexcept { return _v >> 31; } inline unsigned lo() const noexcept { return _v & ((1LL << 31) - 1); } public: static long long mod() { return md; } ModIntMersenne61() : _v(0) {} // 0 <= x < md * 2 explicit ModIntMersenne61(long long x) : _v(x >= md ? x - md : x) {} long long val() const noexcept { return _v; } ModIntMersenne61 operator+(const ModIntMersenne61 &x) const { return ModIntMersenne61(_v + x._v); } ModIntMersenne61 operator-(const ModIntMersenne61 &x) const { return ModIntMersenne61(_v + md - x._v); } ModIntMersenne61 operator*(const ModIntMersenne61 &x) const { // using ull = unsigned long long; ull uu = (ull)hi() * x.hi() * 2; ull llx = (ull)lo() * x.lo(); ull lu = (ull)hi() * x.lo() + (ull)lo() * x.hi(); ull sum = uu + llx + ((lu & ((1ULL << 30) - 1)) << 31) + (lu >> 30); ull reduced = (sum >> 61) + (sum & ull(md)); return ModIntMersenne61(reduced); } ModIntMersenne61 pow(long long n) const { assert(n >= 0); ModIntMersenne61 ans(1), tmp = *this; while (n) { if (n & 1) ans *= tmp; tmp *= tmp, n >>= 1; } return ans; } ModIntMersenne61 inv() const { return pow(md - 2); } ModIntMersenne61 operator/(const ModIntMersenne61 &x) const { return *this * x.inv(); } ModIntMersenne61 operator-() const { return ModIntMersenne61(md - _v); } ModIntMersenne61 &operator+=(const ModIntMersenne61 &x) { return *this = *this + x; } ModIntMersenne61 &operator-=(const ModIntMersenne61 &x) { return *this = *this - x; } ModIntMersenne61 &operator*=(const ModIntMersenne61 &x) { return *this = *this * x; } ModIntMersenne61 &operator/=(const ModIntMersenne61 &x) { return *this = *this / x; } ModIntMersenne61 operator+(unsigned x) const { return ModIntMersenne61(this->_v + x); } bool operator==(const ModIntMersenne61 &x) const { return _v == x._v; } bool operator!=(const ModIntMersenne61 &x) const { return _v != x._v; } bool operator<(const ModIntMersenne61 &x) const { return _v < x._v; } // To use std::map template friend OStream &operator<<(OStream &os, const ModIntMersenne61 &x) { return os << x._v; } static ModIntMersenne61 randgen(bool force_update = false) { static ModIntMersenne61 b(0); if (b == ModIntMersenne61(0) or force_update) { std::mt19937 mt(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution d(1, ModIntMersenne61::mod()); b = ModIntMersenne61(d(mt)); } return b; } }; //https://hitonanode.github.io/cplib-cpp/string/rolling_hash_1d.hpp template struct PairHash : public std::pair { using PH = PairHash; explicit PairHash(T1 x, T2 y) : std::pair(x, y) {} explicit PairHash(int x) : std::pair(x, x) {} PairHash() : PairHash(0) {} PH operator+(const PH &x) const { return PH(this->first + x.first, this->second + x.second); } PH operator-(const PH &x) const { return PH(this->first - x.first, this->second - x.second); } PH operator*(const PH &x) const { return PH(this->first * x.first, this->second * x.second); } PH operator+(int x) const { return PH(this->first + x, this->second + x); } static PH randgen(bool force_update = false) { static PH b(0); if (b == PH(0) or force_update) { std::mt19937 mt(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution d(1 << 30); b = PH(T1(d(mt)), T2(d(mt))); } return b; } }; template struct TupleHash3 : public std::tuple { using TH = TupleHash3; explicit TupleHash3(T1 x, T2 y, T3 z) : std::tuple(x, y, z) {} explicit TupleHash3(int x) : std::tuple(x, x, x) {} TupleHash3() : TupleHash3(0) {} inline const T1 &v1() const noexcept { return std::get<0>(*this); } inline const T2 &v2() const noexcept { return std::get<1>(*this); } inline const T3 &v3() const noexcept { return std::get<2>(*this); } TH operator+(const TH &x) const { return TH(v1() + x.v1(), v2() + x.v2(), v3() + x.v3()); } TH operator-(const TH &x) const { return TH(v1() - x.v1(), v2() - x.v2(), v3() - x.v3()); } TH operator*(const TH &x) const { return TH(v1() * x.v1(), v2() * x.v2(), v3() * x.v3()); } TH operator+(int x) const { return TH(v1() + x, v2() + x, v3() + x); } static TH randgen(bool force_update = false) { static TH b(0); if (b == TH(0) or force_update) { std::mt19937 mt(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution d(1 << 30); b = TH(T1(d(mt)), T2(d(mt)), T3(d(mt))); } return b; } }; // Rolling Hash (Rabin-Karp), 1dim template struct rolling_hash { int N; const V B; std::vector hash; // hash[i] = s[0] * B^(i - 1) + ... + s[i - 1] static std::vector power; // power[i] = B^i void _extend_powvec() { if (power.size() > 1 and power.at(1) != B) power = {V(1)}; while (static_cast(power.size()) <= N) { auto tmp = power.back() * B; power.push_back(tmp); } } template rolling_hash(const std::vector &s, V b = V::randgen()) : N(s.size()), B(b), hash(N + 1) { for (int i = 0; i < N; i++) hash[i + 1] = hash[i] * B + s[i]; _extend_powvec(); } rolling_hash(const std::string &s = "", V b = V::randgen()) : N(s.size()), B(b), hash(N + 1) { for (int i = 0; i < N; i++) hash[i + 1] = hash[i] * B + s[i]; _extend_powvec(); } void addchar(const char &c) { V hnew = hash[N] * B + c; N++, hash.emplace_back(hnew); _extend_powvec(); } V get(int l, int r) const { // s[l] * B^(r - l - 1) + ... + s[r - 1] return hash[r] - hash[l] * power[r - l]; } int lcplen(int l1, int l2) const { return longest_common_prefix(*this, l1, *this, l2); } }; template std::vector rolling_hash::power{V(1)}; // Longest common prerfix between s1[l1, N1) and s2[l2, N2) template int longest_common_prefix(const rolling_hash &rh1, int l1, const rolling_hash &rh2, int l2) { int lo = 0, hi = std::min(rh1.N + 1 - l1, rh2.N + 1 - l2); while (hi - lo > 1) { const int c = (lo + hi) / 2; auto h1 = rh1.get(l1, l1 + c), h2 = rh2.get(l2, l2 + c); (h1 == h2 ? lo : hi) = c; } return lo; } // Longest common suffix between s1[0, r1) and s2[0, r2) template int longest_common_suffix(const rolling_hash &rh1, int r1, const rolling_hash &rh2, int r2) { int lo = 0, hi = std::min(r1, r2) + 1; while (hi - lo > 1) { const int c = (lo + hi) / 2; auto h1 = rh1.get(r1 - c, r1), h2 = rh2.get(r2 - c, r2); (h1 == h2 ? lo : hi) = c; } return lo; } // using Hash = ModIntMersenne61; using Hash = PairHash; using rol = rolling_hash; const int maxs=5005; V> dp(maxs,V(maxs,-1)); string str; bool f(int l,int r,rol &rh,rol &rhrev){ int lrev=sz(str)-r-1,rrev=sz(str)-l-1; return rh.get(l,r)==rhrev.get(lrev,rrev); } int dfs(int l,int r,rol &rh,rol &rhrev){ if(dp[l][r]!=-1)return dp[l][r]; if(f(l,r,rh,rhrev)){ return (dp[l][r]=r-l+1); } int res=1; rep(i,l+1,r-1){ if(!f(l,i,rh,rhrev))continue; chmax(res,min(i-l+1,dfs(i+1,r,rh,rhrev))); } return (dp[l][r]=res); } struct Solver { void solve() { cin>>str; rol rh(str); reverse(all(str)); rol rhrev(str); cout< #include using namespace atcoder; // #include // #include // using namespace __gnu_pbds; using namespace std; #define int ll using ll=long long; using ld = long double; using uint = unsigned; using ull = unsigned long long; using P=pair; using TP=tuple; const int INF = 1001001001; const long long INFL = 3e18; const int MAX = 2e6+5; #define FOR1(a) for (ll _ = 0; _ < ll(a); ++_) #define FOR2(i, a) for (ll i = 0; i < ll(a); ++i) #define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i) #define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c)) #define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i) #define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i) #define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i) #define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define rrep(...) overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcountll((long long)(x))) #define elif else if #define mpa make_pair #define bit(n) (1LL<<(n)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) template using V = vector; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (bstring join(const T&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<ostream& operator<<(ostream&o,const vector&v){if(sz(v))o<ostream& operator<<(ostream&o,const pair&v){return o<Tx dup(Tx x, Ty y){return (x+y-1)/y;} templatell suma(const vector&a){ll res(0);for(auto&&x:a)res+=x;return res;} templatell suma(const V>&a){ll res(0);for(auto&&x:a)res+=suma(x);return res;} templatevoid uni(T& a){sort(all(a));a.erase(unique(all(a)),a.end());} templatevoid prepend(vector&a,const T&x){a.insert(a.begin(),x);} templateT vgcd(T m, T n) {return std::gcd(m, n);} templateT vgcd(T a, Args... args) {return vgcd(a, vgcd(args...));} void print(){ putchar(' '); } void print(bool a){ printf("%d", a); } // void print(int a){ printf("%d", a); } void print(unsigned a){ printf("%u", a); } void print(long a){ printf("%ld", a); } void print(long long a){ printf("%lld", a); } void print(unsigned long long a){ printf("%llu", a); } void print(char a){ printf("%c", a); } void print(char *a){ printf("%s", a); } void print(const char *a){ printf("%s", a); } void print(double a){ printf("%.15f", a); } void print(long double a){ printf("%.15Lf", a); } void print(const string& a){ for(auto&& i : a) print(i); } template void print(const complex& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag()); print('i'); } template void print(const vector&); template void print(const array&); template void print(const pair& p); template void print(const T (&)[size]); template void print(const vector& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const deque& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const array& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const pair& p){ print(p.first); putchar(' '); print(p.second); } template void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } } template void print(const T& a){ cout << a; } int out(){ putchar('\n'); return 0; } template int out(const T& t){ print(t); putchar('\n'); return 0; } template int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; } ll binary_search(function check, ll ok, ll ng) { assert(check(ok)); while (abs(ok - ng) > 1) { auto x = (ng + ok) / 2; if (check(x)) ok = x; else ng = x; } return ok; } #endif