// #include "../template.cpp"

#ifndef INCLUDE_TEMPLATE
#define INCLUDE_TEMPLATE

// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
// using ll = int64_t;
using ll = __int128;
istream& operator >>(istream &is, ll &a) {
    int64_t i;
    is >> i;
    a = i;
    return is;
}
ostream& operator <<(ostream &os, ll a) {
    int64_t i = (int64_t)a;
    os << i;
    return os;
}
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

#endif

struct LiChaoTree {
    using Line = PLL;
    
    struct Node {
        Line line;
        ll lx, rx;
        Node *l, *r;
        Node(Line line, ll lx, ll rx) : lx(lx), rx(rx), line(line) {}
    };
    
    function<ll(ll, ll)> comp; // maybe min or max
    function<bool(ll, ll)> comp_b;
    ll inf, max_x, id_ele;
    Line init;
    Node *root;

    LiChaoTree(function<ll(ll, ll)> comp, ll inf, ll arg_max_x, ll id_ele, Line init)
        : comp(comp), init(init), inf(inf), id_ele(id_ele)
    {
        max_x = 1;
        while(max_x < arg_max_x) max_x *= 2;
        comp_b = [&](ll a, ll b) { return this->comp(a, b) == a; };
        root = new Node(init, 0, max_x);

    }

    ll calc_y(Line line, ll x) {
        ll a, b;
        tie(a, b) = line;
        return a * x + b; 
    }
    ll calc_y(Node *node, ll x) { return calc_y(node->line, x); }
    
    Node* add_line(Line line, Node *node, ll lx, ll rx) {
        if(node == nullptr) return new Node(line, lx, rx);

        ll mx = (lx + rx) / 2;

        bool lcmp = comp_b(calc_y(line, lx), calc_y(node, lx));
        bool mcmp = comp_b(calc_y(line, mx), calc_y(node, mx));
        bool rcmp = comp_b(calc_y(line, rx), calc_y(node, rx));

        if(lcmp && rcmp) {
            node->line = line;
            return node;
        }
        if(!lcmp && !rcmp) return node;
        if(mcmp) {
            swap(line, node->line);
            lcmp = !lcmp;
            rcmp = !rcmp;
        }
        if(lcmp) {
            auto l = node->l;
            node->l = add_line(line, l, lx, mx);
        } else {
            auto r = node->r;
            node->r = add_line(line, r, mx, rx);
        }
        return node;
    }

    Node* add_line(Line line) { return add_line(line, root, 0, max_x); }

    Node* add_line_seg(Line line, Node *cur, ll lx, ll rx) {
        if(rx <= cur->lx || cur->rx <= lx) return cur;
        if(lx <= cur->lx && cur->rx <= rx) return add_line(line, cur, lx, rx);
        if(cur == nullptr) cur = new Node(init, lx, rx);
        cur->l = add_line_seg(line, cur->l, lx, rx);
        cur->r = add_line_seg(line, cur->r, lx, rx);
        return cur;
    }

    ll query(ll qx) {
        ll lx = 0, rx = max_x;
        Node *cur = root;
        ll ret = id_ele;
        while(cur != nullptr) {
            ll tmp = calc_y(cur, qx);
            ret = comp(ret, tmp);
            if(rx - lx == 1) break;
            ll mx = (lx + rx) / 2;
            if(lx <= qx && qx < mx) {
                rx = mx;
                cur = cur->l;
            } else {
                lx = mx;
                cur = cur->r;
            }
        }
        return ret;
    }
};

const ll inf = 5e18;
LiChaoTree lct([](ll a, ll b) { return min(a, b); }, inf, inf, inf, PLL(inf, inf));

int main() {
    ll N, C;
    cin >> N >> C;
    V<ll> H(N);
    for(auto &&ele : H) cin >> ele;
    V<ll> dp(N + 1);
    dp[1] = 0;
    lct.add_line(PLL(-2 * H[0],  H[0] * H[0] + C));
    for(ll i = 2; i <= N; i++) {
        ll h = H[i - 1];
        dp[i] = lct.query(h) + h * h;
        lct.add_line(PLL(-2 * h, h * h + C + dp[i]));
    }

    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 25344