Problem:
Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.
Here, h_1 < h_2 < \cdots < h_N holds.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, N. Here, a cost of (h_j - h_i)^2 + C is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq C \leq 10^{12}

1 \leq h_1 < h_2 < \cdots < h_N \leq 10^6

Input

Input is given from Standard Input in the following format:

N C
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

5 6
1 2 3 4 5

Sample Output 1

20

If we follow the path 1 → 3 → 5, the total cost incurred would be ((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20.

Sample Input 2

2 1000000000000
500000 1000000

Sample Output 2

1250000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

8 5
1 3 4 5 10 11 12 13

Sample Output 3

62

If we follow the path 1 → 2 → 4 → 5 → 8, the total cost incurred would be ((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62.

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,zx,xc,i,j,ii,jj,C,f[200009],dp[200009],za,K,B,x;
bool bo[2200009];
pair <long long, long long> seg[2200009];
void upd(long long q, long long w, long long rr){
	if(bo[rr]==0){
		seg[rr].first=K;seg[rr].second=B;
		bo[rr]=1;
		return;
	}
	if(q==w){
		if(seg[rr].first*q+seg[rr].second>K*q+B){
			seg[rr].first=K;seg[rr].second=B;
		}
		return;
	}
	long long mid=(q+w)/2;
	if(seg[rr].first*q+seg[rr].second>=K*q+B&&seg[rr].first*mid+seg[rr].second>=K*mid+B){
		
	}else{
		if(seg[rr].first*q+seg[rr].second<=K*q+B&&seg[rr].first*mid+seg[rr].second<=K*mid+B){
			seg[rr].first=K;seg[rr].second=B;
		}else{
			upd(q,mid,rr*2);
		}
	}
	mid++;
	if(seg[rr].first*w+seg[rr].second>=K*w+B&&seg[rr].first*mid+seg[rr].second>=K*mid+B){
		
	}else{
		if(seg[rr].first*w+seg[rr].second<=K*w+B&&seg[rr].first*mid+seg[rr].second<=K*mid+B){
			seg[rr].first=K;seg[rr].second=B;
		}else{
			upd(mid,w,rr*2+1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>C;
	for(i=1; i<=a; i++) cin>>f[i];
	za=1;
	while(za<2000000) za*=2;
	dp[1]=0;
	K=-f[1]*2;
	B=f[1]*f[1]+dp[1];
	upd(1,za,1);
	for(i=2; i<=a; i++){
		dp[i]=999999999999999999LL;
		x=f[i];
		zx=za+x-1;
		while(zx!=0){
			if(bo[zx]!=0&&dp[i]>seg[zx].first*x+seg[zx].second) dp[i]=seg[zx].first*x+seg[zx].second;
			zx/=2;
		}
		dp[i]+=C+f[i]*f[i];
		K=-f[i]*2;
		B=f[i]*f[i]+dp[i];
		upd(1,za,1);
	}
	cout<<dp[a];
	return 0;
}