//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-7.4NTT",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "#define LL long long",
            "using namespace std;",
            "const int N=1048576+3,P=998244353,G=3;",
            "int n,m,ans,invG,f[N],g[N],tr[N],S1[N],S2[N],PA[N],nex[N];char A[N],B[N];",
            "inline void in(Re &x){",
            "    int fu=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')fu|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=fu?-x:x;",
            "}",
            "inline void get_next(){",
            "\tfor(Re i=2,j=0;i<=m;++i){",
            "\t\twhile(j&&B[i]!=B[j+1])j=nex[j];",
            "\t\tif(B[i]==B[j+1])++j;nex[i]=j;",
            "\t}",
            "\tfor(Re i=1;i<=m;++i)printf(\"%d \",nex[i]);",
            "}",
            "inline int mi(Re x,Re k){",
            "\tRe s=1;",
            "\twhile(k){",
            "\t\tif(k&1)s=(LL)s*x%P;",
            "\t\tx=(LL)x*x%P,k>>=1;",
            "\t}",
            "\treturn s;",
            "}",
            "inline int inv(Re x){return mi(x,P-2);}",
            "inline void NTT(Re *f,Re n,Re op){",
            "\tfor(Re i=0;i<n;++i)if(i<tr[i])swap(f[i],f[tr[i]]);",
            "\tfor(Re p=2;p<=n;p<<=1){",
            "\t\tRe len=p>>1,w1=mi(op?invG:G,(P-1)/p);",
            "\t\tfor(Re st=0;st<n;st+=p)",
            "\t\t\tfor(Re j=st,base=1;j<=st+len-1;++j){",
            "\t\t\t\tRe tmp=(LL)base*f[j+len]%P;",
            "\t\t\t\tf[j+len]=(f[j]-tmp+P)%P,(f[j]+=tmp)%=P;",
            "\t\t\t\tbase=(LL)base*w1%P;",
            "\t\t\t}",
            "\t}",
            "}",
            "inline void sakura(Re *f,Re n,Re *g,Re m){",
            "\tfor(m=n+1,n=1;n<=m;n<<=1);Re invn=inv(n);",
            "\tfor(Re i=1;i<n;++i)tr[i]=(tr[i>>1]>>1)|((i&1)?n>>1:0);",
            "\tNTT(f,n,0),NTT(g,n,0);",
            "\tfor(Re i=0;i<n;++i)f[i]=(LL)f[i]*g[i]%P;",
            "\tNTT(f,n,1);",
            "\tfor(Re i=0;i<=m;++i)f[i]=(LL)f[i]*invn%P;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tscanf(\"%s%s\",A+1,B+1),invG=inv(G);",
            "\tn=strlen(A+1),m=strlen(B+1);",
            "\tfor(Re i=1;i<=n;++i)f[i]=A[n-i+1]-'A'+1,S1[i]=S1[i-1]+f[i]*f[i];",
            "\tfor(Re i=1;i<=m;++i)g[i]=B[i]-'A'+1,S2[i]=S2[i-1]+g[i]*g[i];",
            "\tsakura(f,n,g,m);",
            "\tfor(Re i=m;i<=n;++i)PA[n-i+1]=((S1[i]-S1[i-m]+S2[m])%P-2*f[i+1]%P+P)%P;",
            "\tfor(Re i=1;i<=n-m+1;++i)if(PA[i]==0)printf(\"%d\\n\",i);",
            "\tget_next();",
            "}",
            ""
        ],
        "description": "插入 字符串匹配"
    }
}