//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "回文串": {
        "prefix": "acm-6.6Manacher+SAM+倍增",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=6e5+5,logN=19;",
            "char s[N>>1];",
            "inline void in(Re &x){",
            "    Re f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "struct Suffix_Automaton{",
            "\tint O,last,pos[N],siz[N],link[N],maxlen[N],trans[N][26];LL ans;",
            "\tSuffix_Automaton(){last=O=1;}",
            "\tinline void insert(Re ch){",
            "\t\tRe z=++O,p=last;siz[z]=1,maxlen[z]=maxlen[last]+1;",
            "\t\twhile(p&&!trans[p][ch])trans[p][ch]=z,p=link[p];",
            "\t\tif(!p)link[z]=1;",
            "\t\telse{",
            "\t\t\tRe x=trans[p][ch];",
            "\t\t\tif(maxlen[p]+1==maxlen[x])link[z]=x;",
            "\t\t\telse{",
            "\t\t\t\tRe y=++O;maxlen[y]=maxlen[p]+1;",
            "\t\t\t\tfor(Re i=0;i<26;++i)trans[y][i]=trans[x][i];",
            "\t\t\t\twhile(p&&trans[p][ch]==x)trans[p][ch]=y,p=link[p];",
            "\t\t\t\tlink[y]=link[x],link[x]=link[z]=y;",
            "\t\t\t}",
            "\t\t}",
            "\t\tlast=z;",
            "\t}",
            "\tint o,deep[N],head[N],ant[N][20];",
            "\tstruct QAQ{int to,next;}a[N];",
            "\tinline void add(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}",
            "\tinline void dfs(Re x,Re fa){",
            "\t\tdeep[x]=deep[ant[x][0]=fa]+1;",
            "\t\tfor(Re j=1;(1<<j)<=deep[x];++j)ant[x][j]=ant[ant[x][j-1]][j-1];",
            "\t\tfor(Re i=head[x];i;i=a[i].next)dfs(a[i].to,x),siz[x]+=siz[a[i].to];",
            "\t}",
            "\tinline void build(){",
            "\t\tfor(Re i=1;s[i];++i)insert(s[i]-'a'),pos[i]=last;",
            "\t\tfor(Re i=2;i<=O;++i)add(link[i],i);",
            "\t\tdfs(1,0);",
            "\t}",
            "\tinline void check(Re x,Re len){",
            "\t\tRe p=pos[x+len-1];",
            "\t\tfor(Re i=logN;i>=0;--i)",
            "\t\t\tif(maxlen[ant[p][i]]>=len)p=ant[p][i];",
            "\t\tans=max(ans,(LL)len*siz[p]);",
            "\t}",
            "\tint m,r[N];char b[N];",
            "\tinline void sakura(){",
            "\t\tbuild();",
            "\t\tb[m=0]='$',b[++m]='|';",
            "\t\tfor(Re i=1;s[i];++i)b[++m]=s[i],b[++m]='|';",
            "\t\tfor(Re i=1,R=0,mid=0;i<=m;++i){",
            "\t\t\tr[i]=i<=R?min(r[(mid<<1)-i],R-i+1):1;",
            "\t\t\twhile(b[i-r[i]]==b[i+r[i]]){",
            "\t\t\t\t++r[i];",
            "\t\t\t\tif(i+r[i]-1>R)check(i-r[i]+1+1>>1,r[i]-!(i+r[i]&1));",
            "\t\t\t}",
            "\t\t\tif(i+r[i]-1>R)mid=i,R=i+r[i]-1;",
            "\t\t}",
            "\t\tprintf(\"%lld\\n\",ans);",
            "\t}",
            "}SAM;",
            "int main(){",
            "\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tscanf(\"%s\",s+1),SAM.sakura();",
            "}",
            ""
        ],
        "description": "插入 回文串"
    }
}