1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cstdlib>
5 #include<cmath>
6 #include<algorithm>
7 #define inf 1000000000
8 #define ll long long
9 using namespace std;
10 ll n,L,l,r;
11 ll c[50005],q[50005];
12 ll s[50005],f[50005],C;
13 ll up(int j,int k){return f[k]-f[j]+(s[k]+C)*(s[k]+C)-(s[j]+C)*(s[j]+C);}
14 ll down(int j,int k){return 2*(s[k]-s[j]);}
15 int main()
16 {
17 scanf("%lld%lld",&n,&L);
18 C=L+1;
19 for(int i=1;i<=n;i++)scanf("%lld",&c[i]);
20 for(int i=1;i<=n;i++)s[i]=s[i-1]+c[i];
21 for(int i=1;i<=n;i++)s[i]+=i;
22 l=1;r=0;q[++r]=0;
23 for(int i=1;i<=n;i++)
24 {
25 while(l<r&&up(q[l],q[l+1])<=s[i]*down(q[l],q[l+1]))l++;
26 int t=q[l];
27 f[i]=f[t]+(s[i]-s[t]-C)*(s[i]-s[t]-C);
28 while(l<r&&up(q[r],i)*down(q[r-1],q[r])<up(q[r-1],q[r])*down(q[r],i))r--;
29 q[++r]=i;
30 }
31 printf("%lld\n",f[n]);
32 return 0;
33 }