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

{
    "std": {
        "prefix": "acm-1.4sakura",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#include<set>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=5e5+3;",
            "const LL inf=4e18+5;",
            "int n,opt,A[N],B[N];",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "struct QAQ0{",
            "\tint x,g[N];LL tmp,S[N],dp[N];",
            "\tinline void sakura(){",
            "\t\tfor(Re i=1;i<=n;++i)in(x),S[i]=S[i-1]+x,dp[i]=inf;",
            "\t\tdp[0]=0,g[0]=0;",
            "\t\tfor(Re i=1,p=0;i<=n;/*printf(\"i=%d, p=%d\\n\",i,p),*/++i)",
            "\t\t\tfor(Re j=0;j<i;++j)",
            "\t\t\t\tif(S[i]-S[j]>=S[j]-S[g[j]]&&dp[i]>=(tmp=dp[j]+(S[i]-S[j])*(S[i]-S[j])))",
            "\t\t\t\t\tdp[i]=tmp,g[i]=j,p=j;",
            "//\t\tfor(Re i=0;i<=n;++i)printf(\"dp[%d]=%lld\\n\",i,dp[i]);",
            "\t\tprintf(\"%lld\\n\",dp[n]);",
            "\t}",
            "}T0;",
            "int main(){",
            "//\tfreopen(\"456.txt\",\"r\",stdin);",
            "\tin(n),in(opt);",
            "\tif(n<=5000)T0.sakura();",
            "\tfclose(stdin);",
            "\tfclose(stdout);",
            "\treturn 0;",
            "}",
            ""
        ],
        "description": "插入 std"
    }
}