#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
// Convex-Hull Trick on monotonicity assumption (与えられる座標および直線の傾きの単調性を仮定)
template <class T>
struct CHT {
    struct Line {
        T a, b;
        Line(T a_, T b_) : a(a_), b(b_) {}

        // xからy座標を返す
        T yp(T x) { return a * x + b; }
    };

    bool x_isAscend, a_isAscend, q_isMin;
    // 傾きa1 <= a2 <= ... <= akでpop/push
    deque<Line> deq;
    function<void()>      pop_in_add, pop_in_query;
    function<void(Line&)> push_in_add;
    function<bool(Line&)> check_in_add;
    function<bool(T&)>    check_in_query;

    // 座標は昇順、傾きは昇順、クエリはminで与えられるか
    CHT(bool xAscend = true, bool aAscend = false, bool qMin = true) 
        : x_isAscend(xAscend), a_isAscend(aAscend), q_isMin(qMin){
        // dequeのpop/push操作
        function<void()>
            popf = [this]() { deq.pop_front(); },
            popb = [this]() { deq.pop_back(); };
        function<void(Line&)>
            pushf = [this](Line&f) { deq.push_front(f); },
            pushb = [this](Line&f) { deq.push_back(f); };

        // addのdeque操作
        tie(pop_in_add, push_in_add) = a_isAscend ? tie(popb, pushb)
                                                  : tie(popf, pushf);
        // queryのdeque操作
        pop_in_query =  (q_isMin ^ x_isAscend) ? popf 
                                               : popb;
        
        // addの直線追加におけるcheck
        function<bool(Line&)>
            fadd1 = [this](Line&f3) {
                Line f1 = deq[deq.size() - 2], f2 = deq[deq.size() - 1];
                bool comp = (f1.b - f2.b) * (f2.a - f3.a) >= (f2.b - f3.b) * (f1.a - f2.a);
                return (q_isMin ? comp : !comp);
            },
            fadd2 = [this](Line&f1) {
                Line f2 = deq[0], f3 = deq[1];
                bool comp = (f1.b - f2.b) * (f2.a - f3.a) >= (f2.b - f3.b) * (f1.a - f2.a);
                return (q_isMin ? comp : !comp);
            };

        check_in_add = a_isAscend ? fadd1 : fadd2;

        // queryのmin(max)取得におけるcheck
        function<bool(T&)>
            fquery1 = [this](const T&x) {
                Line f1 = deq[deq.size() - 2], f2 = deq[deq.size() - 1];
                return f1.yp(x) <= f2.yp(x);
            },
            fquery2 = [this](const T&x) {
                Line f1 = deq[0], f2 = deq[1];
                return f1.yp(x) <= f2.yp(x);
            };

        check_in_query = q_isMin ? fquery1 : fquery2;
    }

    // 直線追加
    void add(T a, T b) {
        Line f = Line(a, b);
        while (deq.size() >= 2 and check_in_add(f)) {
            pop_in_add();
        }
        push_in_add(f);
    }

    T query(T x) {
        while (deq.size() >= 2 and check_in_query(x)) {
            pop_in_query();
        }
        return (q_isMin ? deq[deq.size() - 1].yp(x)
                        : deq[0].yp(x));
    }
};

int main() {
    init();
    ll N, C;
    cin >> N >> C;
    CHT<ll> cht;
    ll h;
    cin >> h;
    cht.add(-2 * h, h * h);

    ll y = 0;
    rep(i, N - 1) {
        cin >> h;
        y = h * h + C + cht.query(h);
        cht.add(-2 * h, y + h * h);
    }

    cout << y << endl;
}

Measured memory_bytes: 5824