/*
Li-Chao Tree
Given a set of lines, answer queries of the form add a new line (k, c) = kx + c, and find the minimum across all lines
evaluated at x, both in logarithmic time. A segment tree is created over all points that can be queried.
Construction : O(max(x))
Query : O(log(max(x)))
Reference : https://cp-algorithms.com/geometry/convex_hull_trick.html
*/

#include <bits/stdc++.h>
using namespace std;

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

using point = complex<int>;
#define x real
#define y imag

const int MAXN = 1E6 + 100, INF = 5E15 + 5, LAR_INF = 	5E18; // points evaluated over [1 : MAXN]
point line[4 * MAXN];

int dot(point a, point b) {
	return (conj(a) * b).x();
}

int f(point a, int x) {
	return dot(a, {x, 1});
}

void build_tree(int v = 1, int l = 0, int r = MAXN) {
	line[v] = {0, LAR_INF};
	if(r - l == 1)
		return;
	int m = (l + r)/2;
	build_tree(2*v, l, m);
	build_tree(2*v + 1, m, r);
}

void add_line(point nw, int v = 1, int l = 0, int r = MAXN) {
	point old = line[v];
	int m = (l + r)/2;
	bool left = f(nw, l) < f(old, l);
	bool mid = f(nw, m) < f(old, m);
	if(left && mid) {
		//nw is the smaller function in [l, m)
		line[v] = nw;
		if(r - l == 1)
			return;
		add_line(old, 2*v + 1, m, r);
	}
	else if(!left && mid) {
		//nw is the smaller function in [m, r)
		line[v] = nw;
		if(r - l == 1)
			return;
		add_line(old, 2*v, l, m);
	}

	else if(left && !mid) {
		//old is the smaller function in [m, r)
		if(r - l == 1)
			return;
		add_line(nw, 2*v, l, m);
	}
	else if(!left && !mid) {
		//old is the smaller function in [l, m)
		if(r - l == 1)
			return;
		add_line(nw, 2*v + 1, m, r);
	}
}

int get(int x, int v = 1, int l = 0, int r = MAXN) {
	int val = f(line[v], x);
	if(r - l == 1)
		return val;
	int m = (l + r)/2;
	if(x < m)
		val = min(val, get(x, 2*v, l, m));
	else
		val = min(val, get(x, 2*v + 1, m, r));
	return val;
}

void mini(int &x, int y) {
	x = min(x, y);
}

int32_t main() {
	fast();
	build_tree();
	int n, c;
	cin >> n >> c;
	vi h(n);
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vi dp(n);
	dp[0] = 0;
	add_line({-2*h[0], h[0] * h[0] + c + dp[0] + INF});
	for(int i = 1; i < n; i++) {
		dp[i] = h[i] * h[i] + get(h[i]) - INF;
		add_line({-2 * h[i], h[i] * h[i] + dp[i] + c + INF});
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 38144