1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <cstring>
5 #define rep(i,l,r) for(int i=l; i<=r; i++)
6 #define clr(x,y) memset(x,y,sizeof(x))
7 #define travel(x) for(Edge *p=last[x]; p; p=p->pre)
8 using namespace std;
9 typedef long long ll;
10 const int maxn = 50010;
11 ll n,L,m,head,tail,q[maxn],f[maxn],s[maxn];
12 inline double slope(int x,int y){
13 return (f[y] - f[x] + s[y] * s[y] - s[x] * s[x]) / (s[y] - s[x]);
14 }
15 inline ll read(){
16 ll ans = 0, f = 1;
17 char c = getchar();
18 while (!isdigit(c)){
19 if (c == ‘-‘) f = -1;
20 c = getchar();
21 }
22 while (isdigit(c)){
23 ans = ans * 10 + c - ‘0‘;
24 c = getchar();
25 }
26 return ans * f;
27 }
28 int main(){
29 n = read(); L = read(); s[0] = 0;
30 rep(i,1,n) s[i] = s[i-1] + read();
31 rep(i,1,n) s[i] += i;
32 f[0] = q[0] = head = tail = 0;
33 rep(i,1,n){
34 m = s[i] - L - 1;
35 while (head < tail && slope(q[head+1],q[head]) <= m<<1) head++;
36 f[i] = f[q[head]] + (m - s[q[head]]) * (m - s[q[head]]);
37 while (head < tail && slope(q[tail],q[tail-1]) >= slope(i,q[tail])) tail--;
38 q[++tail] = i;
39 }
40 printf("%lld\n",f[n]);
41 return 0;
42 }