#include <bits/stdc++.h> using namespace std; const int maxn = 50000 + 20; int q[maxn]; long long f[maxn], dp[maxn], S[maxn], sum[maxn], c[maxn]; double xielv(int k, int j){ return (f[k] - f[j]) * 1.0 / (S[k] - S[j]); } bool dot(int j, int k, int i){ return 2*S[i]*(S[k] - s[j]) >= f[k] - f[j]; } int main(){ int n; long long l; int h = 1, t = 1; scanf("%d%lld",&n,&l); l+=1; q[1] = 0; for(int i = 1; i <= n; i++){ scanf("%lld", &c[i]); sum[i] = sum[i -1] + c[i]; S[i] = sum[i] + i; while(h < t && dot(h, h+1, i))h++; h++; int m = q[h]; dp[i] = dp[m] + (S[i] - S[j] - l) * (S[i] - S[j] - l); while(h < t && dot(t-1, t, i))t--; q[++t] = i; } printf("%lld\n",dp[n]); }