//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.2nlogn 优化倍增 NTT",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LD double",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=262144+3,P=167772161,G=3;",
            "int n,m,invn,invG,f[N],g[N],h[N],p[N],tr[N],jc[N],invjc[N];",
            "inline void in(Re &x){",
            "    int 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;",
            "}",
            "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\tfor(Re st=0,len=p>>1,w1=mi(op?invG:G,(P-1)/p);st<n;st+=p)",
            "\t\t\tfor(Re i=st,base=1;i<=st+len-1;++i){",
            "\t\t\t\tRe tmp=(LL)base*f[i+len]%P;",
            "\t\t\t\tf[i+len]=(f[i]-tmp+P)%P,f[i]=(f[i]+tmp)%P,base=(LL)base*w1%P;",
            "\t\t\t}",
            "}",
            "inline void times(Re *f,Re n,Re *g,Re m){",
            "\tRe n_=n,m_=m;",
            "\tfor(m+=n,n=1;n<=m;n<<=1);",
            "\tfor(Re i=n_+1;i<=n;++i)f[i]=0;",
            "\tfor(Re i=m_+1;i<=n;++i)g[i]=0;",
            "\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,invn=inv(n);i<=m;++i)f[i]=(LL)f[i]*invn%P;",
            "}",
            "inline void xplus(Re *f,Re *F,Re n,Re c){",
            "\tfor(Re i=0;i<=n;++i)h[i]=(LL)F[i]*jc[i]%P;",
            "\tfor(Re i=0,Mi=1;i<=n;++i)p[n-i]=(LL)Mi*invjc[i]%P,Mi=(LL)Mi*c%P;",
            "\ttimes(h,n,p,n);",
            "\tfor(Re i=0;i<=n;++i)f[i]=(LL)h[n+i]*invjc[i]%P;",
            "}",
            "inline void sakura(Re *f,Re n){",
            "\tif(n==1){f[0]=0,f[1]=1;return;}//(x+0)",
            "\tif(n&1){",
            "\t\tsakura(f,n-1);",
            "\t\tfor(Re i=n;i;--i)f[i]=((LL)f[i]*(n-1)%P+f[i-1])%P;",
            "\t\tf[0]=(LL)f[0]*(n-1)%P;",
            "\t}",
            "\telse sakura(f,n>>1),xplus(g,f,n>>1,n>>1),times(f,n>>1,g,n>>1);",
            "}",
            "int s[N];",
            "inline void get_Stirling(Re n){",
            "\tinvjc[1]=invjc[0]=jc[0]=1,invG=inv(G);",
            "\tif(n==0){s[0]=1;return;}",
            "\tfor(Re i=1;i<=n;++i)jc[i]=(LL)jc[i-1]*i%P;",
            "\tfor(Re i=2;i<=n;++i)invjc[i]=(LL)invjc[P%i]*(P-P/i)%P;",
            "\tfor(Re i=2;i<=n;++i)invjc[i]=(LL)invjc[i]*invjc[i-1]%P;",
            "\tsakura(s,n);",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),get_Stirling(n);",
            "\tfor(Re i=0;i<=n;++i)printf(\"%d \",s[i]);",
            "}",
            ""
        ],
        "description": "插入 第一类斯特林数·行"
    }
}