#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
const long long inf = 1e9 * 1e9;
int a[N], sum[N];
long long f[N];
deque<int> Q;
int n, m;
int x(int i) {
return sum[i];
}
long long y(int i) {
return f[i] + 1LL * sum[i] * sum[i];
}
int main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
cin >> a[i];
sum[i] = sum[i-1] + a[i];
}
Q.push_back(0);
for (int i=1; i<=n; i++) {
while (Q.size() >= 2 && y(Q[1]) - y(Q[0]) <= 2LL * sum[i] * (x(Q[1]) - x(Q[0]))) Q.pop_front();
int j = Q.front(), tail;
f[i] = f[j] + 1LL * (sum[i] - sum[j]) * (sum[i] - sum[j]) + m;
while ((tail = Q.size()) >= 2 &&
(y(i) - y(Q[tail-1])) * (x(Q[tail-1]) - x(Q[tail-2])) <= (y(Q[tail-1]) - y(Q[tail-2])) * (x(i) - x(Q[tail-1])))
Q.pop_back();
Q.push_back(i);
}
cout << f[n] << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxMDAwMDAwICsgMTA7CmNvbnN0IGxvbmcgbG9uZyBpbmYgPSAxZTkgKiAxZTk7CgppbnQgYVtOXSwgc3VtW05dOwpsb25nIGxvbmcgZltOXTsKZGVxdWU8aW50PiBROwppbnQgbiwgbTsKCmludCB4KGludCBpKSB7CglyZXR1cm4gc3VtW2ldOwp9Cgpsb25nIGxvbmcgeShpbnQgaSkgewoJcmV0dXJuIGZbaV0gKyAxTEwgKiBzdW1baV0gKiBzdW1baV07Cn0KCmludCBtYWluKCkgewoJY2luID4+IG4gPj4gbTsKCWZvciAoaW50IGk9MTsgaTw9bjsgaSsrKSB7CgkJY2luID4+IGFbaV07CgkJc3VtW2ldID0gc3VtW2ktMV0gKyBhW2ldOwoJfQoJUS5wdXNoX2JhY2soMCk7Cglmb3IgKGludCBpPTE7IGk8PW47IGkrKykgewoJCXdoaW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