#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
typedef long long ll;
const int N=50010;
int w[N];
double sum[N];
double dp[N];
int q[N];
int n,l;
double a(int i)
{
return sum[i]+i;
}
double b(int i)
{
return a(i)+l+1;
}
double X(int i)
{
return b(i);
}
double Y(int i)
{
return dp[i]+b(i)*b(i);
}
double slope(int i,int j)
{
return (Y(i)-Y(j))/(X(i)-X(j));
}
signed main()
{
cin >> n >> l;
for(int i = 1; i <= n; i ++)
{
cin >> sum[i];
sum[i] += sum[i-1];
}
int hh = 1,tt = 1;
for(int i = 1; i <= n; i ++)
{
while(hh < tt && slope(q[hh],q[hh+1])<2*a(i))
hh ++ ;
dp[i] = dp[q[hh]] + (sum[i] + i - sum[q[hh]] - q[hh] - l - 1) * (sum[i] + i - sum[q[hh]] - q[hh] - l - 1);
while(hh < tt && slope(i,q[tt-1])<slope(q[tt-1],q[tt]))
tt -- ;
q[++tt]=i;
}
printf("%lld
",(ll)dp[n]);
return 0;
}