#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=5e4+5;
typedef long long ll;
inline int read(){
char c=getchar();int x=0,f=1;
while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();}
while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();}
return x*f;
}
int n,L;
ll s[N],f[N];
ll F(int i){return f[i]+(s[i]+1+L)*(s[i]+1+L);}
double slope(int a,int b){return (F(b)-F(a))/(s[b]-s[a]);}
int head,tail,q[N];
void dp(){
head=tail=1;
q[head]=0;
for(int i=1;i<=n;i++){
while(head<tail&&slope(q[head],q[head+1])<=2*s[i]) head++;
int j=q[head];
f[i]=f[j]+(s[i]-s[j]-1-L)*(s[i]-s[j]-1-L);
while(head<tail&&slope(q[tail],i)<=slope(q[tail-1],q[tail])) tail--;
q[++tail]=i;
}
}
int main(){
n=read();L=read();
for(int i=1;i<=n;i++) s[i]=s[i-1]+read();
for(int i=1;i<=n;i++) s[i]+=i;
dp();
printf("%lld",f[n]);
}