#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <stdlib.h>
#define rep( i, l, r ) for (int i = l; i <= r; i++)
#define down( i, l, r ) for (int i = l; i >= r; i--)
#define MAX 50009
using namespace std;
int num[MAX], dl[MAX], s, t, n, l, a;
long long sum[MAX], m, dp[MAX];
double g(int a, int b)
{
return((dp[a] + sum[a]*sum[a] - dp[b] - sum[b]*sum[b]) / (sum[a] - sum [b]));
}
int main()
{
scanf("%d%d", &n, &l);
rep(i, 1, n) scanf("%d", &num[i]);
sum[0] = 0; rep(i, 1, n) sum[i] = sum[i-1] + num[i] + 1;
s = 1; t = 1; dl[1] = 0; dp[0] = 0;
rep(i, 1, n)
{
m = sum[i] - l - 1;
while (true)
{
if (t == s) break;
if (2 * m <= g(dl[s], dl[s+1])) break;
s++;
}
a = dl[s];
dp[i] = dp[a] + (m - sum[a]) * (m - sum[a]);
while (true)
{
if (t == s) break;
if (g(dl[t-1], dl[t]) <= g(dl[t], i)) break;
t--;
}
t++; dl[t] = i;
}
printf("%lld", dp[n]);
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKI2RlZmluZSByZXAoIGksIGwsIHIgKSBmb3IgKGludCBpID0gbDsgaSA8PSByOyBpKyspCiNkZWZpbmUgZG93biggaSwgbCwgciApIGZvciAoaW50IGkgPSBsOyBpID49IHI7IGktLSkKI2RlZmluZSBNQVggNTAwMDkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbnVtW01BWF0sIGRsW01BWF0sIHMsIHQsIG4sIGwsIGE7CmxvbmcgbG9uZyBzdW1bTUFYXSwgbSwgZHBbTUFYXTsKCmRvdWJsZSBnKGlud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