1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<algorithm>
5 #include<queue>
6 #include<cstring>
7 #define PAU putchar(‘ ‘)
8 #define ENT putchar(‘\n‘)
9 using namespace std;
10 const int maxn=50010;typedef long long LL;
11 int deq[maxn];LL C[maxn],S[maxn],dp[maxn];
12 double slope(int i,int j){return (dp[i]+S[i]*S[i]-dp[j]-S[j]*S[j])/(double)(S[i]-S[j]);}
13 inline int read(){
14 int x=0,sig=1;char ch=getchar();
15 while(!isdigit(ch)){if(ch==‘-‘)sig=-1;ch=getchar();}
16 while(isdigit(ch))x=10*x+ch-‘0‘,ch=getchar();
17 return x*sig;
18 }
19 inline LL readl(){
20 LL x=0,sig=1;char ch=getchar();
21 while(!isdigit(ch)){if(ch==‘-‘)sig=-1;ch=getchar();}
22 while(isdigit(ch))x=10*x+ch-‘0‘,ch=getchar();
23 return x*sig;
24 }
25 inline void write(LL x){
26 if(x==0){putchar(‘0‘);return;}if(x<0)putchar(‘-‘),x=-x;
27 int len=0;LL buf[15];while(x)buf[len++]=x%10,x/=10;
28 for(int i=len-1;i>=0;i--)putchar(buf[i]+‘0‘);return;
29 }
30 int n,L;
31 void init(){
32 n=read();L=read();C[0]=S[0]=0;
33 for(int i=1;i<=n;i++){C[i]=readl();C[i]+=C[i-1];S[i]=i+C[i];}
34 return;
35 }
36 void work(){
37 int s=0,e=0;dp[0]=deq[s]=0;
38 for(int i=1;i<=n;i++){
39 LL m=S[i]-L-1;
40 while(s<e&&slope(deq[s+1],deq[s])<=(m<<1))++s;
41 int j=deq[s];dp[i]=dp[j]+(m-S[j])*(m-S[j]);
42 while(s<e&&slope(deq[e],deq[~-e])>=slope(i,deq[e]))--e;
43 deq[++e]=i;
44 }
45 return;
46 }
47 void print(){
48 write(dp[n]);
49 return;
50 }
51 int main(){init();work();print();return 0;}