//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-3.5EK",
        "body": [
            "#pragma GCC optimize(3,\"Ofast\",\"inline\")",
            "#pragma GCC optimize(2)",
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<vector>",
            "#include<cmath>",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e5+5,inf=2e9;",
            "int h,t,n,p,o=1,st,ed,cnt,maxflow,Q[N],zhu[N],ans[N],pan[N],pre[N],cyf[N],head[N];",
            "struct QAQ{int to,flow,next;}a[N<<1];vector<int>Ans[N];",
            "inline void add(Re x,Re y,Re flow){a[++o].flow=flow,a[o].to=y,a[o].next=head[x],head[x]=o;}",
            "inline void add_(Re x,Re y,Re flow){add(x,y,flow),add(y,x,0);}",
            "inline int bfs(Re st,Re ed){",
            "\tfor(Re i=1;i<=ed;++i)pan[i]=0;",
            "\th=1,t=0,pan[st]=1,Q[++t]=st,cyf[st]=inf;",
            "\twhile(h<=t){",
            "\t\tRe x=Q[h++];",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif(a[i].flow&&!pan[to=a[i].to]){",
            "\t\t\t\tcyf[to]=min(cyf[x],a[i].flow);",
            "\t\t\t\tpan[Q[++t]=to]=1,pre[to]=i;",
            "\t\t\t\tif(to==ed)return 1;",
            "\t\t\t}",
            "\t}",
            "\treturn 0;",
            "}",
            "inline void EK(Re st,Re ed){",
            "\tRe x,flow=0;maxflow=0;",
            "\twhile(bfs(st,ed)){",
            "\t\tx=ed,maxflow+=cyf[ed];",
            "\t\twhile(x!=st){",
            "\t\t\tRe i=pre[x];",
            "\t\t\ta[i].flow-=cyf[ed];",
            "\t\t\ta[i^1].flow+=cyf[ed];",
            "\t\t\tx=a[i^1].to;",
            "\t\t}",
            "\t}",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tscanf(\"%d\",&n),st=1e5+1,ed=st+1;",
            "\twhile(ans[0]<=n){",
            "\t\t++p;",
            "\t\tadd_(st,p<<1,1),add_(p<<1|1,ed,1);",
            "\t\tfor(Re j=sqrt(p)+1;j*j-p<=p-1;++j)add_((j*j-p)<<1,(p<<1)|1,1);",
            "\t\tEK(st,ed);",
            "\t\tif(!maxflow)ans[++ans[0]]=p,Ans[zhu[p]=ans[0]].push_back(p);",
            "\t\telse{",
            "\t\t\tRe x=p<<1|1;",
            "\t\t\twhile(!zhu[x-1>>1])x=a[pre[x]^1].to+1;",
            "\t\t\tAns[zhu[x-1>>1]].push_back(p);",
            "\t\t}",
            "\t}",
            "\tprintf(\"%d\\n\",p-1);",
            "\tfor(Re i=1;i<=n;puts(\"\"),++i)",
            "\t\tfor(Re j=0;j<Ans[i].size();++j)",
            "\t\t\tprintf(\"%d \",Ans[i][j]);",
            "}",
            ""
        ],
        "description": "插入 魔术球问题"
    }
}