//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.4x从0到n不连续",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=2003+3,P=998244353;",
            "inline void in(Re &x){",
            "\tint f=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=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);}",
            "int ff[N],gg[N];",
            "inline void mul(Re *f,Re n,Re a0,Re *g){",
            "\tfor(Re i=0;i<=n;++i)ff[i]=f[i];",
            "\tg[0]=(LL)a0*ff[0]%P;for(Re i=1;i<=n+1;++i)g[i]=((LL)a0*ff[i]%P+ff[i-1])%P;",
            "}",
            "inline void div(Re *g,Re n,Re a0,Re *f){",
            "\tfor(Re i=0;i<=n;++i)gg[i]=g[i];",
            "\tf[n-1]=gg[n];for(Re i=n-2;i>=0;--i)f[i]=(gg[i+1]-(LL)a0*f[i+1]%P+P)%P;",
            "}",
            "int fi[N],fmul[N];",
            "inline void Lagrange(Re *x,Re *y,Re n,Re *F){",
            "\tfmul[0]=P-x[0],fmul[1]=1;",
            "\tfor(Re i=1;i<=n;++i)mul(fmul,i,P-x[i],fmul);",
            "\tfor(Re i=0;i<=n-1;++i)F[i]=0;",
            "\tfor(Re i=0;i<=n;++i){",
            "\t\tRe tmp=1;",
            "\t\tfor(Re j=0;j<=n;++j)if(i!=j)tmp=(LL)tmp*(x[i]-x[j]+P)%P;",
            "\t\ttmp=(LL)y[i]*Inv(tmp)%P;",
            "\t\tdiv(fmul,n+1,P-x[i],fi);",
            "\t\tfor(Re i=0;i<=n;++i)(F[i]+=(LL)tmp*fi[i]%P)%=P;",
            "\t}",
            "}",
            "int n,X,ans,x[N],y[N],F[N];",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(X),--n;",
            "\tfor(Re i=0;i<=n;++i)in(x[i]),in(y[i]);",
            "\tLagrange(x,y,n,F);",
            "\tfor(Re i=0,tmp=1;i<=n;++i)(ans+=(LL)F[i]*tmp%P)%=P,tmp=(LL)tmp*X%P;",
            "\tprintf(\"%d\\n\",ans);",
            "}",
            ""
        ],
        "description": "插入 拉格朗日插值"
    }
}