#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int op(int a,int b){ return min(a,b); } int e(){ return Inf32; } int X = 0; bool f(int x){ return x >= X; } struct rolling_hash{ long long t_hash; static inline vector power; static const long long MOD = (1LL<<61)-1; static const long long b = 123456; int sz; rolling_hash(){ sz = 0; t_hash = 0; } rolling_hash(char c){ sz = 1; t_hash = b*c; } long long mul(__int128 x,__int128 y){ __int128 t = x*y; t = (t>>61) + (t&MOD); if(t>=MOD)t -= MOD; return t; } long long get_pow(int sz){ if(power.size()>sz)return power[sz]; while(power.size()<=sz){ if(power.size()==0)power.push_back(1); else power.push_back(mul(power.back(),b)); } return power.back(); } rolling_hash &operator+=(const rolling_hash &another){ (*this).t_hash = mul((*this).t_hash,get_pow(another.sz)); (*this).t_hash += another.t_hash; if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz += another.sz; return (*this); } rolling_hash operator+(const rolling_hash &another)const{ return (rolling_hash(*this)+=another); } rolling_hash &operator-=(const rolling_hash &another){ (*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz)); if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz -= another.sz; return (*this); } rolling_hash operator-(const rolling_hash &another)const{ return (rolling_hash(*this)-=another); } bool operator<(const rolling_hash &another)const{ if((*this).t_hash!=another.t_hash)return (*this).t_hash>s; int n = s.size(); vector R(n+1),rR(n+1); rep(i,n){ R[i+1] = R[i] + rolling_hash(s[i]); } reverse(s.begin(),s.end()); rep(i,n){ rR[i+1] = rR[i] + rolling_hash(s[i]); } reverse(s.begin(),s.end()); set ss; vector> p; rep(i,n){ int ok = 0,ng = n; while(ng-ok>1){ int mid = (ok+ng)/2; int l = i-mid,r = i+1+mid; if(l<0||r>n){ ng = mid; continue; } if((R[r]-R[l]) == (rR[n-l] - rR[n-r]))ok = mid; else ng = mid; } int l = i-ok,r = i+1+ok; while(l1){ int mid = (ok+ng)/2; int l = i-mid,r = i+2+mid; if(l<0||r>n){ ng = mid; continue; } if((R[r]-R[l]) == (rR[n-l] - rR[n-r]))ok = mid; else ng = mid; } int l = i-ok,r = i+2+ok; while(l seg(la); vector imos(n+1); rep(i,sa.size()){ int d = distance(p.begin(),lower_bound(p.begin(),p.end(),make_pair(sa[i],-1))); for(int j=d;j(i); int rr = seg.max_right(i); rr++; long long t = rr-ll; t *= len; imos[ll] += t; imos[rr] -= t; } } rep(i,n)imos[i+1] += imos[i]; cout<<(*max_element(imos.begin(),imos.end()))<