1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5 const int maxn=50010;
6 long long s[maxn],f[maxn];
7 int st,ed,q[maxn];
8 int main()
9 {
10 int n,L;
11 scanf("%d%d",&n,&L);
12 for(int i=1;i<=n;i++)
13 scanf("%d",&s[i]);
14
15 for(int i=1;i<=n;i++)
16 s[i]+=s[i-1];
17
18 for(int i=1;i<=n;i++)
19 s[i]+=i;
20
21 q[st=1]=0;ed=2;
22 for(int i=1;i<=n;i++){
23 long long m=s[i]-L-1;
24 while(st<ed-1&&f[q[st+1]]-f[q[st]]+s[q[st+1]]*s[q[st+1]]-s[q[st]]*s[q[st]]<=2*m*(s[q[st+1]]-s[q[st]]))st++;
25 f[i]=f[q[st]]+(m-s[q[st]])*(m-s[q[st]]);
26 while(st<ed-1&&(f[i]-f[q[ed-1]]+s[i]*s[i]-s[q[ed-1]]*s[q[ed-1]])*(s[q[ed-1]]-s[q[ed-2]])<=(f[q[ed-1]]-f[q[ed-2]]+s[q[ed-1]]*s[q[ed-1]]-s[q[ed-2]]*s[q[ed-2]])*(s[i]-s[q[ed-1]]))ed--;
27 q[ed++]=i;
28 }
29 printf("%lld\n",f[n]);
30 }