1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <cmath>
5 #include <deque>
6 #include <vector>
7 #include <queue>
8 #include <iostream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define MIT (2147483647)
19 #define INF (1000000001)
20 #define MLL (1000000000000000001LL)
21 #define sz(x) ((int) (x).size())
22 #define clr(x, y) memset(x, y, sizeof(x))
23 #define puf push_front
24 #define pub push_back
25 #define pof pop_front
26 #define pob pop_back
27 #define ft first
28 #define sd second
29 #define mk make_pair
30 inline void SetIO(string Name) {
31 string Input = Name+".in",
32 Output = Name+".out";
33 freopen(Input.c_str(), "r", stdin),
34 freopen(Output.c_str(), "w", stdout);
35 }
36
37 const int N = 50010;
38 int n;
39 LL L;
40 LL C[N], Sum[N], S[N], Dp[N];
41 int Que[N], Head, Tail;
42
43 inline LL Getint() {
44 char Ch = ‘ ‘;
45 LL Ret = 0;
46 while(!(Ch >= ‘0‘ && Ch <= ‘9‘)) Ch = getchar();
47 while(Ch >= ‘0‘ && Ch <= ‘9‘) {
48 Ret = Ret*10LL+Ch-‘0‘;
49 Ch = getchar();
50 }
51 return Ret;
52 }
53
54 inline void Input() {
55 scanf("%d", &n);
56 L = Getint();
57 For(i, 1, n) C[i] = Getint();
58 }
59
60 inline LL Sqr(LL x) {
61 return x*x;
62 }
63
64 inline bool Better(int x, int y, int i) {
65 return Dp[x]+Sqr(S[x])-Dp[y]-Sqr(S[y])
66 <= 2LL*(S[i]-L-1)*(S[x]-S[y]);
67 }
68
69 inline bool Smaller(int x, int y, int z) {
70 LL DX1 = S[y]-S[x], DX2 = S[z]-S[y],
71 DY1 = Dp[y]+Sqr(S[y])-Dp[x]-Sqr(S[x]),
72 DY2 = Dp[z]+Sqr(S[z])-Dp[y]-Sqr(S[y]);
73 return DY1*DX2 <= DY2*DX1;
74 }
75
76 inline void Solve() {
77 For(i, 1, n) Sum[i] = Sum[i-1]+C[i];
78 For(i, 1, n) S[i] = Sum[i]+i;
79
80 Head = Tail = 1, Que[1] = 0;
81 For(i, 1, n) {
82 int x, y;
83 while(Head < Tail) {
84 x = Que[Head], y = Que[Head+1];
85 if(Better(x, y, i)) break;
86 Head++;
87 }
88
89 x = Que[Head];
90 Dp[i] = Dp[x]+Sqr(S[i]-S[x]-1-L);
91
92 while(Head < Tail) {
93 x = Que[Tail-1], y = Que[Tail];
94 if(Smaller(x, y, i)) break;
95 Tail--;
96 }
97 Que[++Tail] = i;
98 }
99
100 cout<<Dp[n]<<endl;
101 }
102
103 int main() {
104 SetIO("1010");
105 Input();
106 Solve();
107 return 0;
108 }