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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll ncr(ll n, ll r,ll m)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans *= modi(n - i + 1, m);
		ans %= m;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}


bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

void dfs(ll a, vector<ll>adj[100099], bool visited[100001], ll dp[])
{
	visited[a] = true;
	if (adj[a].size() == 0) {
		dp[a] = 0;
	}
	
	for (auto u : adj[a])
	{
		if (!visited[u])
		{
			visited[u] = true;
			dfs(u, adj, visited, dp);
			dp[a] =max(dp[a], dp[u] + 1);
		}
		else {
			dp[a] = max(dp[a], dp[u] + 1);
		}
	}
	
}

ll calhash(string& s) {
	ll i, hash = 0, p = 1, pow = 3;
	for (i = 0; s[i] != '\0'; i++) {
		hash = (hash + p * (s[i] - 'a' + 1)) % MOD;
		p *= pow;
	}
	return hash;
}
ll digit(ll n)
{
	ll count = 0;
	while (n != 0) {
		n = n / 10;
		++count;
	}
	return count;
}
ll* kmp(string& s) {
	ll j, i, prefix[1000];
	prefix[0] = 0;
	for (i = 1; s[i] != '\0'; i++) {

			j = prefix[i - 1];
			while (j > 0 && s[j] != s[i]) {
				j = prefix[j - 1];
			}
			if (s[i] == s[j]) {
				prefix[i] = j + 1;
			}
	}
	return prefix;
}

void bfs(ll start, ll arr[], vector<ll> adj[], ll c) {
	queue<pair<ll,ll>> q;
	pair<ll, ll> temp;
	temp = { start, c };
	q.push(temp);
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		for (auto u : adj[temp.first]) {
			    arr[u] = arr[u] - temp.second;
				q.push({ u , -temp.second});
			}
			
		
	}
}
int main() {
	fast;
	ll n, c, h[1000], i, j;
	cin >> n >> c;
	for (i = 1; i <= n; i++) {
		cin >> h[i];
	}
	ll dp[1000];
	
	dp[1] = 0;
	dp[2] = (h[2] - h[1]) * (h[2] - h[1]) + c;
	for (i = 3; i <= n; i++) {
		dp[i] = 9999999999999;
		for (j = 1; j < i; j++) {
			dp[i] = min(dp[i], dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + c);
		}
		//cout << dp[i] << " ";
	}
	cout << dp[n];
	return 0;
}