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

{
    "myprogram": {
        "prefix": "acm-1.4sakura",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#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;LL g[N],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]=S[0];",
            "\t\tfor(Re i=1,p=0;i<=n;++i){",
            "\t\t\twhile(p+1<i&&2*S[p+1]-g[p+1]<=S[i])++p;",
            "\t\t\tdp[i]=dp[p]+(S[i]-S[p])*(S[i]-S[p]),g[i]=S[p];",
            "//\t\t\tprintf(\"i=%d, p=%d\\n\",i,p);",
            "//\t\t\tfor(Re j=0;j<=p;++j)",
            "//\t\t\t\tif(dp[i]>=(tmp=dp[j]+(S[i]-S[j])*(S[i]-S[j])))",
            "//\t\t\t\t\tdp[i]=tmp,g[i]=S[j];",
            "\t\t}",
            "//\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": "插入 myprogram"
    }
}