1 #include<bits/stdc++.h>
2 #define N 50005
3 #define ll long long
4 using namespace std;
5 int n,head,tail;
6 ll L;
7 int a[N];
8 ll s[N],f[N],dp[N],q[N];
9 double calc(int k,int j){
10 return (double)(dp[j]-dp[k]+(f[j]+1+L)*(f[j]+1+L)-(f[k]+1+L)*(f[k]+1+L))/(2*(f[j]-f[k]));
11 }
12 int main(){
13 scanf("%d%lld",&n,&L);
14 for (int i=1;i<=n;i++)
15 scanf("%lld",&a[i]),f[i]=f[i-1]+1+a[i];
16 head=1; tail=1;
17 for (int i=1;i<=n;i++){
18 while (head<tail&&calc(q[head],q[head+1])<=f[i]) head++;
19 int k=q[head];
20 dp[i]=dp[k]+(f[i]-f[k]-1-L)*(f[i]-f[k]-1-L);
21 while (head<tail&&calc(q[tail],i)<calc(q[tail-1],q[tail])) tail--;
22 q[++tail]=i;
23 }
24 printf("%lld\n",dp[n]);
25 return 0;
26 }