n2+ 特判过了?!
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define rll register ll
#define cll const ll
#define N 1000005
#define P 131
using namespace std;
inline ll read()
{
rll x=0;bool f=1;register char c=getchar();
while(c<48||c>57){if(c=='-') f=0;c=getchar();}
while(c>=48&&c<=57){x=x*10+(c^48);c=getchar();}
return f?x:-x;
}
inline void write(ll x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+48);
}
cll n=read();
ll ans,idt,last,len[N],mps[N],t[N][26];
char s[N];
bool check=1;
ull h[N],p[N];
map<ll,bool> flag;
inline ull hs(ll l,ll r){return h[r]-h[l-1]*p[r-l+1];}
inline ll get(ll pos,ll p)
{
while(s[pos-1-len[p]]!=s[pos])
p=mps[p];
return p;
}
inline void insert(ll pos,ll x)
{
cll p=get(pos,last);
if(!t[p][x])
{
mps[++idt]=t[get(pos,mps[p])][x];
t[p][x]=idt;
len[idt]=len[p]+2;
}
last=t[p][x];
rll q=last;
while(q>1)
{
if((len[q]&1)&&flag[hs(pos-len[q]+1,pos)])
ans=max(ans,(len[q]+1)/2);
flag[hs(pos-len[q]+1,pos)]=1;
q=mps[q];
}
}
int main()
{
scanf("%s",s+1);
for(rll i=2;i<=n;i++)
if(s[i]!=s[i-1])
check=0;
if(check)
{
write(n/2);
return 0;
}
idt=1,len[1]=-1,mps[0]=1;
p[0]=1;
for(rll i=1;i<=n;i++)
{
p[i]=p[i-1]*P;
h[i]=h[i-1]*P+s[i];
insert(i,s[i]-'a');
}
write(ans);
return 0;
}