<commit_before><commit_msg>BZOJ 1911<commit_after>#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>
typedef long long ll;


typedef unsigned long long ull;
using namespace std;
const int MAXN=1E6+10;
#define X(i) (s[i])
#define Y(i) (a*s[i]*s[i]-b*s[i]+f[i])
#define slope(i,j) ((1.0*Y(j)-Y(i))/(1.0*X(j)-X(i)))
ll s[MAXN],f[MAXN],a,b,c;
deque<int> q;
int n;
int main()
{
    scanf("%d",&n);
    scanf("%lld%lld%lld",&a,&b,&c);
    for(int i=1,t;i<=n;i++) scanf("%d",&t),s[i]=s[i-1]+t;
    f[0]=0;
    q.push_back(0);
    for(int i=1;i<=n;i++)
    {
        while(q.size()>1&&slope(*(q.begin()),*(q.begin()+1))>2.0*a*s[i]) q.pop_front();
        f[i]=-2*a*X(q.front())*s[i]+Y(q.front())+a*s[i]*s[i]+b*s[i]+c;
        while(q.size()>1&&slope(*(q.end()-2),*(q.end()-1))<=slope(*(q.end()-2),i)) q.pop_back();
        q.push_back(i);
    }
    printf("%lld\n",f[n]);
    #ifdef LOCAL
        system("pause");
    #endif
}
{'fraction_non_alphanumeric': 0.2888684452621895, 'fraction_numerical': 0.02483900643974241, 'mean_word_length': 4.978021978021978, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4495376', 'n_tokens_mistral': 550, 'n_tokens_neox': 533, 'n_words': 66}