//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "Snowflake Snow Snowflakes": {
        "prefix": "acm-6.5最小表示法+Hash",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<map>",
            "#define R register int",
            "#define uLL long long",
            "int n,t,p=13333331,re,A[13];",
            "std::map<uLL,int>pan;",
            "inline int sakura(int a[]){",
            "    R i=1,j=2,k;",
            "    while(i<=6&&j<=6){",
            "        k=0;",
            "        while(k<6&&a[i+k]==a[j+k])++k;",
            "        if(k==6)break;",
            "        if(a[i+k]>a[j+k]){i+=k+1;if(i==j)++i;}",
            "        else{j+=k+1;if(i==j)++j;}",
            "    }",
            "    return i<j?i:j;",
            "}",
            "inline uLL Hash(int a[],int st){",
            "    R i=0;uLL x=0;",
            "    for(;i<6;++i)x=x*p+(uLL)a[st+i];",
            "    return x;",
            "}",
            "inline uLL find(int a[]){",
            "    R x,y,i=1,k=0,b[13];",
            "    for(;i<=6;i++)b[i]=a[7-i];",
            "    for(i=1;i<=6;i++)a[i+6]=a[i],b[i+6]=b[i];",
            "\tx=sakura(a),y=sakura(b);",
            "    for(i=0;i<6;i++)",
            "\t\tif(a[x+i]<b[y+i])return Hash(a,x);",
            "\t\telse if(a[x+i]>b[y+i])return Hash(b,y);",
            "    return Hash(a,x);",
            "}",
            "int main(){",
            "    scanf(\"%d\",&n);R i,j;",
            "    for(i=1;i<=n;i++){",
            "        for(j=1;j<=6;j++)scanf(\"%d\",&A[j]);",
            "        uLL re=find(A);",
            "        if(pan[re]){printf(\"Twin snowflakes found.\");return 0;}",
            "    \tpan[re]=1;",
            "\t}",
            "    printf(\"No two snowflakes are alike.\");",
            "}",
            ""
        ],
        "description": "插入 Snowflake Snow Snowflakes"
    }
}