#include<bits/stdc++.h>#defineintlonglongusingnamespace std;constint N =2e6+10;int n, p;int s[N], h, t, q[N], f[N];intX(int x){return s[x];}intY(int x){return f[x]+X(x)*X(x);}intK(int x){return2*(X(x)- p);}doubleslope(int x,int y){returndouble(Y(y)-Y(x))/double(X(y)-X(x));}signedmain(){
cin >> n >> p;
p ++;for(int i =1; i <= n; i ++){int x;
cin >> x;
s[i]= s[i -1]+ x +1;}
h =1, t =0;
q[++ t]=0;for(int i =1; i <= n; i ++){int k =K(i);while(h < t &&Y(q[h])- k *X(q[h])>=Y(q[h +1])- k *X(q[h +1]))
h ++;
f[i]= f[q[h]]+(s[i]- s[q[h]]- p)*(s[i]- s[q[h]]- p);while(h < t &&slope(q[t], q[t -1])>=slope(q[t], i))
t --;
q[++ t]= i;}
cout << f[n]<<'\n';return0;}