// dp[i]=min(dp[j]+(sum[i]-sum[j])^2+m)(0<j<i)
// j>k&&j优于k dp[j]+(sum[i]-sum[j])^2<dp[j]+(sum[k]-sum[i])^2
// f(x)=sum(x)^2+dp[x]
//==>f(j)-f(k)/(sum[j]-sum[k])<2*sum[i]
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long
int que[650000];
int a[650000];
int sum[650000];
int dp[650000];
int n,m;
int A(int j,int k)
{
return (dp[j]+sum[j]*sum[j])-(dp[k]+sum[k]*sum[k]);
}
int B(int j,int k)
{
return 2*(sum[j]-sum[k]);
}
int Val(int i,int j)
{
return dp[j]+(sum[i]-sum[j])*(sum[i]-sum[j])+m;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
sum[0]=0;
memset(dp,0,sizeof(dp));
memset(que,0,sizeof(que));
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
int head=0,tot=0;
que[tot++]=0;
for(int i=1;i<=n;i++)
{
while(head+1<tot&&A(que[head+1],que[head])<=sum[i]*B(que[head+1],que[head]))head++;
dp[i]=Val(i,que[head]);
while(head+1<tot&&A(i,que[tot-1])*B(que[tot-1],que[tot-2])<=A(que[tot-1],que[tot-2])*B(i,que[tot-1]))tot--;
que[tot++]=i;
}
printf("%d\n",dp[n]);
}
}